warp.intersect_tri_tri#

warp.intersect_tri_tri(
v0: vec3f,
v1: vec3f,
v2: vec3f,
u0: vec3f,
u1: vec3f,
u2: vec3f,
) → int#
  • Kernel: true
  • Python: false
  • Differentiable: false

Test whether two triangles (v0, v1, v2) and (u0, u1, u2) intersect, using Möller’s method.

All six vertices must be in the same coordinate space. Coplanar triangles are handled (an overlap within their common plane counts as an intersection). This single-precision overload may return incorrect results in near-degenerate cases; use the wp.intersect_tri_tri(v0, v1, v2, u0, u1, u2) overload with vec3d vertices for greater robustness.

Returns:

1 if the triangles intersect, 0 otherwise.

Example

@wp.kernel
def tri_tri(out: wp.array[wp.int32]):
    a0, a1, a2 = wp.vec3(0.0, 0.0, 0.0), wp.vec3(2.0, 0.0, 0.0), wp.vec3(0.0, 2.0, 0.0)
    b0, b1, b2 = wp.vec3(1.0, 1.0, -1.0), wp.vec3(1.0, 1.0, 1.0), wp.vec3(1.0, -1.0, 0.0)
    out[0] = wp.intersect_tri_tri(a0, a1, a2, b0, b1, b2)

out = wp.zeros(1, dtype=wp.int32)
wp.launch(tri_tri, dim=1, inputs=[out])
print("intersect:", out.numpy()[0])
intersect: 1
warp.intersect_tri_tri(
v0: vec3d,
v1: vec3d,
v2: vec3d,
u0: vec3d,
u1: vec3d,
u2: vec3d,
) → int
  • Kernel: true
  • Python: false
  • Differentiable: false

Test whether two triangles (v0, v1, v2) and (u0, u1, u2) intersect, using Möller’s method.

All six vertices must be in the same coordinate space. Coplanar triangles are handled (an overlap within their common plane counts as an intersection). This double-precision overload is more accurate than the wp.intersect_tri_tri(v0, v1, v2, u0, u1, u2) overload with vec3 vertices.

Returns:

1 if the triangles intersect, 0 otherwise.

Example

@wp.kernel
def tri_tri(out: wp.array[wp.int32]):
    a0, a1, a2 = wp.vec3d(0.0, 0.0, 0.0), wp.vec3d(2.0, 0.0, 0.0), wp.vec3d(0.0, 2.0, 0.0)
    b0, b1, b2 = wp.vec3d(1.0, 1.0, -1.0), wp.vec3d(1.0, 1.0, 1.0), wp.vec3d(1.0, -1.0, 0.0)
    out[0] = wp.intersect_tri_tri(a0, a1, a2, b0, b1, b2)

out = wp.zeros(1, dtype=wp.int32)
wp.launch(tri_tri, dim=1, inputs=[out])
print("intersect:", out.numpy()[0])
intersect: 1