warp.closest_point_edge_edge#
- warp.closest_point_edge_edge( ) vec3f#
Kernel
Differentiable
Find the closest points between two edges (line segments)
[p1, q1]and[p2, q2].All four endpoints must be in the same coordinate space.
- Parameters:
p1 – Start point of the first edge
q1 – End point of the first edge
p2 – Start point of the second edge
q2 – End point of the second edge
epsilon – An edge whose squared length is
<= epsilonis treated as a single point (degenerate); its barycentric weight is then returned as 0.
- Returns:
sin [0, 1] is the barycentric weight of the closest point on the first edge (the point isp1 + s * (q1 - p1)),tin [0, 1] is the barycentric weight on the second edge (p2 + t * (q2 - p2)), anddis the distance between those two closest points.- Return type:
A
vec3(s, t, d)
Example
@wp.kernel def edge_edge(out: wp.array[wp.vec3]): p1, q1 = wp.vec3(0.0, 0.0, 0.0), wp.vec3(1.0, 0.0, 0.0) p2, q2 = wp.vec3(0.5, 1.0, 1.0), wp.vec3(0.5, 1.0, -1.0) out[0] = wp.closest_point_edge_edge(p1, q1, p2, q2, 1.0e-6) out = wp.zeros(1, dtype=wp.vec3) wp.launch(edge_edge, dim=1, inputs=[out]) s, t, d = out.numpy()[0] print(f"s={s:.1f} t={t:.1f} d={d:.1f}")
s=0.5 t=0.5 d=1.0