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
statein place; called from the Python scope, it does not modifystate, so repeated calls with the samestatereturn the same point (seerand_init()). The third coordinate isw = 1 - u - v; recover a point on a triangle with verticesa,b,casu*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.