warp.sample_triangle#

warp.sample_triangle(state: uint32) vec2f#
  • Kernel

  • Python

Uniformly sample a point in a triangle, returned as barycentric coordinates.

In a kernel, advances state in place; called from the Python scope, it does not modify state, so repeated calls with the same state return the same point (see rand_init()). The third coordinate is w = 1 - u - v; recover a point on a triangle with vertices a, b, c as u*a + v*b + w*c:

@wp.kernel
def points_in_triangle(
    seed: int, a: wp.vec3, b: wp.vec3, c: wp.vec3, out: wp.array[wp.vec3]
):
    i = wp.tid()
    rng = wp.rand_init(seed, i)
    bary = wp.sample_triangle(rng)
    w = 1.0 - bary[0] - bary[1]
    out[i] = bary[0] * a + bary[1] * b + w * c
Returns:

The barycentric coordinates (u, v) of the sampled point.