Algorithmcore
Triangle-triangle intersection test
Also called Moller triangle intersection test.
Tests whether two triangles in 3D meet. It finds the side of each plane on which the vertices of the other triangle lie, then compares two intervals on the common line.
- Time
- Θ(1) worst
- Space
- Θ(1) extra
- Where
- n = none, the input is two triangles
- Model
- Real RAM
- Properties
- deterministicexactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Tomas Möller, 1997
The triangle-triangle intersection test decides whether two closed triangles in 3D have a common point. It is the test of Möller (1997). First it computes on which side of the plane of each triangle the three vertices of the other triangle lie, with the orientation test ORIENT3D. If all three vertices are on one side, the triangles do not meet. If not, each triangle cuts the plane of the other in a segment, both segments lie on the line where the two planes meet, and the triangles meet if and only if the two segments overlap. Two triangles in one plane go to a separate test in 2D. The test takes a constant number of operations. It is the inner test of a mesh self-intersection check and of mesh Boolean operations.
In plain words
Take two flat triangles in space. Each one lies in a flat sheet that goes on forever. If all three corners of the second triangle are above the sheet of the first, or all are below, the two triangles cannot touch. The same is true the other way round.
If the corners are on both sides, the first triangle cuts the sheet of the second along a short piece of a line. The second triangle cuts the sheet of the first along a piece of the same line, because both sheets meet on that line. The triangles touch exactly when these two pieces overlap. To compare them, measure where each piece starts and ends along the line.
If the two triangles lie in the same sheet, the test looks at them as flat shapes: they touch if two edges cross, or if one triangle holds a corner of the other.
The problem
The input is two triangles and in . Each triangle has three vertices that are not collinear. The output is true if the closed triangles (the convex hulls of the vertices, with the boundary) have a common point, and false if not. A shared vertex, a shared edge and a touch at one point all count as a meeting. A mesh check must then decide which of these meetings are allowed, see mesh self-intersection.
The algorithm
ORIENT3D is the determinant of the three edge vectors from . It is positive when is on the side of the normal of , negative on the other side, and zero when the four points are in one plane. The normal of a triangle is , with the cross product.
TRI-TRI(P, Q)- 1
dq_i ← ORIENT3D(p0, p1, p2, q_i) for i = 0, 1, 2 ▷ sides of Q's vertices - 2
if all dq_i > 0 or all dq_i < 0 then return false - 3
dp_i ← ORIENT3D(q0, q1, q2, p_i) for i = 0, 1, 2 ▷ sides of P's vertices - 4
if all dp_i > 0 or all dp_i < 0 then return false - 5
if dq = (0, 0, 0) then return COPLANAR-TRI-TRI(P, Q) - 6
D ← n_P × n_Q ▷ direction of the common line - 7
[a, b] ← SPAN(P, dp, D); [c, e] ← SPAN(Q, dq, D) - 8
return max(a, c) ≤ min(b, e) SPAN(T, s, D) ▷ projections on D of T ∩ (other plane)- 9
X ← { D · t_i : s_i = 0 } - 10
for each edge (t_i, t_j) of T with s_i · s_j < 0 do - 11
X ← X ∪ { D · t_i + (D · t_j − D · t_i) · s_i / (s_i − s_j) } - 12
return [min X, max X] COPLANAR-TRI-TRI(P, Q)- 13
drop the coordinate k where |n_P[k]| is largest - 14
if a closed edge of P' meets a closed edge of Q' then return true - 15
return p0' ∈ Q' or q0' ∈ P'
Line L11 is the point where the edge from to crosses the other plane, measured along . The fraction is between 0 and 1, because and have opposite signs. Line L13 projects both triangles onto the axis plane where they have the largest area. The projection is one to one on their common plane, so it does not change whether they meet. Line L14 uses orientation tests in 2D for each of the 9 pairs of edges, and line L15 tests one vertex of each triangle against the other with three 2D orientation tests.
Degenerate cases. A vertex of one triangle can lie in the plane of the other, the triangles can share an edge or a vertex, and they can lie in one plane. These cases are common in meshes, because neighbouring faces share vertices. The test does not assume general position. A zero goes to line L9, all zeros go to line L5, and the comparison of line L8 counts a touch at one point. With integer or rational coordinates, every sign is exact, so each of these cases gets the correct answer.
Example
Let in the plane , and in the plane .
| step | value |
|---|---|
| L1 | : is below the plane of , and are above |
| L3 | : is in the plane of , and are on opposite sides |
| L6 | , , |
| L9 for | has , so |
| L11 for | edge : , so and |
| L11 for | edge gives , edge gives , so |
| L8 | , so true |
The common line is , , and the point has . So the overlap is the segment from to , which is the part of that lies in .
Move to . The signs do not change, but now , which ends before . So the triangles do not meet: cuts the plane of outside the hypotenuse. For , , the interval of is the one point , and . The test returns true, because touches the hypotenuse of at the point .
When the arithmetic is floating point. The signs of line L1 decide everything, and in floating point they can be wrong. Let , , and with , that is . The point is very near the line through and . ORIENT3D is about in exact arithmetic, but the same formula in IEEE double gives about , with the wrong sign. The products are large and almost equal, so their difference loses all correct digits. This is catastrophic cancellation. A wrong sign at line L2 can reject two triangles that touch, or send a pair to the wrong branch, and a mesh check then reports a crossing that is not there or misses one that is. The fix is exact signs: integer or rational coordinates as in the code of this page, adaptive filtered predicates as in Shewchuk's expansion arithmetic, or the exact geometric computation model in general.
Correctness
If all three vertices of are strictly on one side of the plane of , then the whole of is on that side, because the signed distance is an affine function and is the convex hull of its vertices. So lines L2 and L4 reject correctly. In the general case the planes are different and not parallel, so they meet in a line with direction . The part of each triangle in the other plane is the convex hull of its vertices with sign zero and of the edge crossings, and this is what SPAN collects. Both parts lie on , and is their intersection. The map is one to one and keeps the order on , so the parts meet if and only if their intervals overlap. In the coplanar case the projection is one to one on the plane, and two plane triangles meet if and only if two edges meet or one triangle holds a vertex of the other. The full proof is below.
Proof: The plane-side and interval test decides exactly whether two closed triangles meetfull
Claim. Let and be triangles in , each with three vertices that are not collinear, and let the coordinates be exact numbers (integers or rationals). Then TRI-TRI returns true if and only if the closed triangles and (the convex hulls of their vertices) have a common point. It stops after a fixed number of arithmetic operations.
Setup. Write and . Both are non-zero because the triangles are not degenerate. Let and be the planes of and . By the definition of ORIENT3D, and . So the sign of tells on which side of the point lies, and means . All these values are exact, so each test of the pseudocode has the true answer.
Step 1 (early rejection, lines L2 and L4). If all , the affine function is positive at each vertex of , so it is positive on their convex hull . But on . So , and false is correct. The cases "all " and the two cases of line L4 are the same with signs or roles exchanged.
Step 2 (the coplanar case, line L5). If , then , and since is not degenerate, . Line L13 picks a coordinate with largest, so . Dropping coordinate is then a one-to-one affine map from onto the coordinate plane: a point of is fixed by its other two coordinates, because the equation of the plane can be solved for coordinate . An affine bijection keeps segments, triangles and their intersections. So it is enough to decide whether the plane triangles and meet.
Lemma A. Two closed, non-degenerate triangles and in the plane meet if and only if an edge of meets an edge of , or , or .
Proof. The "if" part holds because edges and vertices are subsets of the triangles. For "only if", let and assume that no edge of meets an edge of , so . The boundary is connected and does not meet , so it lies entirely in the interior of or entirely outside . In the first case . In the second case , and in the same way lies in the interior of (then ) or outside . If both boundaries lie outside the other triangle, then is connected and does not meet , so lies in the interior of or in its exterior. It contains , and , so lies in the interior of , and then , a contradiction.
Lines L14 and L15 test exactly the conditions of Lemma A. The closed segment test is exact: two segments meet if they cross properly (strict opposite signs on both sides) or if an endpoint of one lies on the other, which the collinear branch checks with coordinate ranges. The point test accepts a point when the three orientation signs are all or all , which is the closed triangle. So the coplanar branch is correct.
Step 3 (the general case). Now , and the signs of are not all strictly equal, and the same holds for . Then . The planes are not parallel: if they were parallel and different, would be a non-zero constant on , so all would be equal and non-zero, which line L2 has excluded. So is a line, with direction .
Lemma B. Let be one of the two triangles, let be the values of the affine function of the other plane at ( for , for ), and assume that the are not all strictly of one sign and not all zero. Let be the set of vertices with together with the points for the pairs with . Then is not empty, and is the convex hull of .
Proof. If no is zero, two of them have opposite signs, so is not empty. Each point of is in (the factor lies in when ) and has , because . The set is convex, so it contains the hull of . Conversely, let with , and . Let , and be the indices with , and , and let . If , then for all , so is a convex combination of the vertices of . If , set for and . A direct computation gives
and in the same way . So is a convex combination of points of . Every pair , is an edge of a triangle, so line L10 meets each such pair.
By Lemma B, is the convex hull of the points that lines L9 to L11 collect for , and is the same for . Both lie on , because and . Each point of is for one real , and is strictly increasing in . So maps one to one and in order onto , the segment onto and onto , the values that line L12 returns. Line L11 computes as , which is the same number by linearity.
Finally , because a point of lies in both planes, and a point of lies in both triangles. Two segments of meet if and only if their images meet, that is, if and only if . This is the test of line L8.
Termination. There are no loops except the loops over the 3 vertices and the 3 edges of each triangle, and over the 9 pairs of edges in the coplanar case. So the test stops after a fixed number of exact operations.
Complexity
The test does a fixed number of operations: 6 ORIENT3D calls, two cross products, at most 6 interval points, and in the coplanar case 9 segment tests and 2 point tests. So it takes time and extra space in the real RAM model.
The cost of exact arithmetic depends on the size of the numbers. With integer coordinates of bits, ORIENT3D is a polynomial of degree 3 and needs about bits. The values have degree 5, and the interval ends of line L11 are fractions of degree about 8 over degree 3. These values are constructions, not only signs, so the interval part is the most expensive part of an exact version. The variant of Guigue and Devillers below avoids it.
Properties
- Exact. With integer or rational coordinates, each branch takes the true answer, also on all degenerate inputs.
- Symmetric. The result does not depend on the order of the two triangles or on the order of the vertices of each one.
- Closed sets. A shared vertex, a shared edge or a touch at one point counts as a meeting.
- Early exit. Most pairs of far-apart triangles stop at line L2 after 3 orientation tests.
- Construction, not only predicates. Lines L6 to L11 compute new numbers. A version with only signs needs a different method.
Variants and improvements
- Möller's float version. The original code uses floating point and sets each signed distance with a small absolute value to zero, to treat nearly coplanar cases as coplanar. The threshold is a heuristic. It removes some wrong answers and causes others, and no value is correct for all inputs.
- Guigue and Devillers (2003). After the same rejection by signs, it permutes the vertices so that one vertex of each triangle is alone on its side, and it decides the overlap of the two intervals with two more ORIENT3D signs. It uses no constructions, so it is exact with filtered predicates such as Shewchuk's, and it is fast in floating point.
- Separating axes. Two triangles are disjoint if and only if their projections are disjoint on one of a finite list of axes: the two normals, the 9 cross products of an edge of one with an edge of the other, and, for flat triangles in one plane, the 6 edge normals in that plane. See the separating axis theorem. This test is simple, but it does many more dot products.
- Edge against triangle. Two closed triangles meet if and only if an edge of one meets the other triangle. So six segment-triangle tests also decide the question. The ray form of such a test is Möller-Trumbore, which is a ray-triangle test.
- The segment of intersection. Mesh Boolean operations need the segment itself, not only a yes or no. The overlap interval of line L8 gives its two ends on the common line.
When to use it
Use it as the exact pair test after a broad phase, such as a bounding volume hierarchy or a uniform grid, has found the pairs of triangles whose boxes overlap. This is the setting of a mesh self-intersection check, of collision detection between triangle meshes, and of mesh Boolean operations. If only a yes or no is needed and robust floating point predicates are available, the Guigue-Devillers form is a better choice. If you test a ray, not a triangle, use a ray-triangle test.
Pitfalls
- Neighbours always meet. Two faces of a mesh that share a vertex or an edge meet by this test. A self-intersection check must ignore the shared part and look for any other common point.
- Epsilon tests. A threshold on the signed distances is not a fix. It changes which inputs fail, and it makes the test depend on the scale of the model.
- The wrong coplanar projection. Drop the coordinate where the normal is largest. If you drop a coordinate where the normal is zero, the projected triangles are segments, and the 2D test is wrong.
- Degenerate triangles. A triangle with collinear vertices has a zero normal, and the test does not apply. Remove such faces first, or test them as segments.
- Mixed precision. Signs from exact arithmetic and interval ends from floating point can disagree. Compute the whole test in one exact model.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/triangle-triangle-intersection/. The authors are listed in prov/QR3KY9.jsonl.
"""Exact test whether two closed triangles in 3D intersect.
The method is the plane-side and interval method of Moller (1997). Every
sign is computed exactly: coordinates are int or fractions.Fraction, and the
interval ends on the common line are Fractions. Triangles must not be
degenerate (their three vertices must not be collinear).
"""
from fractions import Fraction
from typing import Sequence, Union
Num = Union[int, Fraction]
Point = Sequence[Num]
Triangle = Sequence[Point]
def sub(a: Point, b: Point) -> tuple[Num, Num, Num]:
return (a[0] - b[0], a[1] - b[1], a[2] - b[2])
def cross(a: Point, b: Point) -> tuple[Num, Num, Num]:
return (a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0])
def dot(a: Point, b: Point) -> Num:
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
def normal(t: Triangle) -> tuple[Num, Num, Num]:
return cross(sub(t[1], t[0]), sub(t[2], t[0]))
def orient3d(a: Point, b: Point, c: Point, d: Point) -> Num:
"""det[b - a, c - a, d - a]: positive when d is on the side of the normal of (a, b, c)."""
return dot(cross(sub(b, a), sub(c, a)), sub(d, a))
def sign(x: Num) -> int:
return (x > 0) - (x < 0)
def orient2d(a: Sequence[Num], b: Sequence[Num], c: Sequence[Num]) -> int:
return sign((b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]))
def on_segment(a: Sequence[Num], b: Sequence[Num], c: Sequence[Num]) -> bool:
"""For collinear a, b, c: is c on the closed segment ab?"""
return min(a[0], b[0]) <= c[0] <= max(a[0], b[0]) and min(a[1], b[1]) <= c[1] <= max(a[1], b[1])
def segments_meet_2d(a, b, c, d) -> bool:
"""Do the closed segments ab and cd of the plane meet?"""
o1, o2, o3, o4 = orient2d(a, b, c), orient2d(a, b, d), orient2d(c, d, a), orient2d(c, d, b)
if o1 * o2 < 0 and o3 * o4 < 0:
return True
return ((o1 == 0 and on_segment(a, b, c)) or (o2 == 0 and on_segment(a, b, d))
or (o3 == 0 and on_segment(c, d, a)) or (o4 == 0 and on_segment(c, d, b)))
def in_triangle_2d(p, t) -> bool:
"""Is p in the closed, non-degenerate triangle t of the plane?"""
s = [orient2d(t[i], t[(i + 1) % 3], p) for i in range(3)]
return min(s) >= 0 or max(s) <= 0
def coplanar_tri_tri(p: Triangle, q: Triangle) -> bool:
"""Two triangles in one plane: project to the axis plane where the normal is largest."""
n = normal(p)
k = max(range(3), key=lambda i: abs(n[i])) # @line L13
keep = [i for i in range(3) if i != k]
p2 = [(v[keep[0]], v[keep[1]]) for v in p]
q2 = [(v[keep[0]], v[keep[1]]) for v in q]
for i in range(3): # @line L14
for j in range(3):
if segments_meet_2d(p2[i], p2[(i + 1) % 3], q2[j], q2[(j + 1) % 3]):
return True
return in_triangle_2d(p2[0], q2) or in_triangle_2d(q2[0], p2) # @line L15
def span(t: Triangle, s: Sequence[Num], d: Point) -> tuple[Fraction, Fraction]:
"""The projections on d of the part of t that lies in the plane of the other triangle.
s[i] is the signed side of vertex i of t. The signs are not all equal and non-zero.
"""
x = [Fraction(dot(d, t[i])) for i in range(3) if s[i] == 0] # @line L9
for i in range(3): # @line L10
j = (i + 1) % 3
if s[i] * s[j] < 0:
di, dj = dot(d, t[i]), dot(d, t[j])
x.append(Fraction(di) + Fraction(dj - di) * Fraction(s[i], 1) / (s[i] - s[j])) # @line L11
return min(x), max(x) # @line L12
def tri_tri(p: Triangle, q: Triangle) -> bool:
"""Return True when the closed triangles p and q share at least one point.
Precondition: neither triangle is degenerate. Coordinates are int or
Fraction. Time O(1); every decision is an exact sign.
"""
dq = [orient3d(p[0], p[1], p[2], q[i]) for i in range(3)] # @line L1
if min(dq) > 0 or max(dq) < 0: # @line L2
return False
dp = [orient3d(q[0], q[1], q[2], p[i]) for i in range(3)] # @line L3
if min(dp) > 0 or max(dp) < 0: # @line L4
return False
if dq == [0, 0, 0]: # @line L5
return coplanar_tri_tri(p, q)
d = cross(normal(p), normal(q)) # @line L6
a, b = span(p, dp, d) # @line L7
c, e = span(q, dq, d)
return max(a, c) <= min(b, e) # @line L8
def orient3d_float(a: Point, b: Point, c: Point, d: Point) -> float:
"""The same determinant in floating point, to show how its sign can be wrong."""
fa, fb, fc, fd = ([float(x) for x in v] for v in (a, b, c, d))
return orient3d(fa, fb, fc, fd) # type: ignore[arg-type]
test_triangle_triangle_intersection.py 165 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/triangle-triangle-intersection/. The authors are listed in prov/QR3KY9.jsonl.
import random
from fractions import Fraction
from triangle_triangle_intersection import cross, dot, normal, orient3d, orient3d_float, sub, tri_tri
# ---- independent oracles (no orientation predicates) ----
def det3(a, b, c):
return dot(a, cross(b, c))
def segment_meets_triangle(a, b, t):
"""Closed segment ab against closed triangle t, by a one-variable linear program.
Write a + s (b - a) - t0 = u e1 + v e2 + w n with the basis e1, e2, n of the
triangle. Then u, v and w are affine in s, and the segment meets t if some
s in [0, 1] has w = 0, u >= 0, v >= 0 and u + v <= 1.
"""
e1, e2 = sub(t[1], t[0]), sub(t[2], t[0])
n = cross(e1, e2)
big = det3(e1, e2, n) # = |n|^2 > 0
y0, y1 = sub(a, t[0]), sub(b, a)
u = (Fraction(det3(y0, e2, n), big), Fraction(det3(y1, e2, n), big))
v = (Fraction(det3(e1, y0, n), big), Fraction(det3(e1, y1, n), big))
w = (Fraction(det3(e1, e2, y0), big), Fraction(det3(e1, e2, y1), big))
lo, hi = Fraction(0), Fraction(1)
# w0 + s w1 = 0
if w[1] == 0:
if w[0] != 0:
return False
else:
s = -w[0] / w[1]
lo, hi = max(lo, s), min(hi, s)
# c0 + s c1 >= 0
for c0, c1 in (u, v, (1 - u[0] - v[0], -u[1] - v[1])):
if c1 == 0:
if c0 < 0:
return False
elif c1 > 0:
lo = max(lo, -c0 / c1)
else:
hi = min(hi, -c0 / c1)
return lo <= hi
def by_segments(p, q):
"""Two closed triangles meet iff an edge of one meets the other triangle."""
for s, t in ((p, q), (q, p)):
for i in range(3):
if segment_meets_triangle(s[i], s[(i + 1) % 3], t):
return True
return False
def by_separating_axes(p, q):
"""Separating axis test: face normals, edge cross products and in-plane edge normals."""
ep = [sub(p[(i + 1) % 3], p[i]) for i in range(3)]
eq = [sub(q[(i + 1) % 3], q[i]) for i in range(3)]
n1, n2 = normal(p), normal(q)
axes = [n1, n2] + [cross(a, b) for a in ep for b in eq]
axes += [cross(n1, a) for a in ep] + [cross(n2, b) for b in eq]
for ax in axes:
if ax == (0, 0, 0):
continue
sp = [dot(ax, v) for v in p]
sq = [dot(ax, v) for v in q]
if max(sp) < min(sq) or max(sq) < min(sp):
return False
return True
def degenerate(t):
return normal(t) == (0, 0, 0)
def rand_tri(rng, r, flat=False):
while True:
t = [tuple(rng.randint(-r, r) if (k < 2 or not flat) else 0 for k in range(3)) for _ in range(3)]
if not degenerate(t):
return t
# ---- tests ----
def test_page_example():
p = [(0, 0, 0), (4, 0, 0), (0, 4, 0)]
q = [(1, 1, -1), (1, 1, 3), (3, 3, 1)]
assert tri_tri(p, q)
q_far = [(5, 5, -1), (5, 5, 3), (7, 7, 1)]
assert not tri_tri(p, q_far)
q_touch = [(2, 2, 0), (2, 2, 3), (5, 5, 3)] # touches the hypotenuse at (2, 2, 0)
assert tri_tri(p, q_touch)
def test_coplanar_cases():
p = [(0, 0, 0), (4, 0, 0), (0, 4, 0)]
assert tri_tri(p, [(1, 1, 0), (2, 1, 0), (1, 2, 0)]) # inside
assert tri_tri([(1, 1, 0), (2, 1, 0), (1, 2, 0)], p) # contains
assert tri_tri(p, [(4, 0, 0), (6, 0, 0), (5, 2, 0)]) # shared vertex only
assert not tri_tri(p, [(3, 3, 0), (6, 3, 0), (3, 6, 0)]) # beyond the hypotenuse
assert tri_tri(p, [(2, 2, 0), (6, 2, 0), (2, 6, 0)]) # touches the hypotenuse at (2, 2)
def test_shared_edge_and_vertex():
p = [(0, 0, 0), (2, 0, 0), (0, 2, 0)]
assert tri_tri(p, [(0, 0, 0), (2, 0, 0), (1, 0, 5)]) # shared edge, other plane
assert tri_tri(p, [(0, 0, 0), (-1, -1, 3), (-2, 1, 3)]) # shared vertex
def test_parallel_planes():
p = [(0, 0, 0), (2, 0, 0), (0, 2, 0)]
assert not tri_tri(p, [(0, 0, 1), (2, 0, 1), (0, 2, 1)])
def test_float_orientation_can_be_wrong():
# The example of the page: a is almost on the line through b and c.
u = 2.0**-53
a = (0.5 + 41 * u, 0.5 + 48 * u, 0.0)
b, c, d = (12.0, 12.0, 0.0), (24.0, 24.0, 0.0), (0.0, 0.0, 1.0)
exact = orient3d(*[tuple(Fraction(x) for x in v) for v in (a, b, c, d)])
assert exact > 0
assert orient3d_float(a, b, c, d) < 0
def test_against_oracles_random():
rng = random.Random(1997)
hits = 0
for it in range(4000):
flat = it % 4 == 0
p = rand_tri(rng, 3, flat)
q = rand_tri(rng, 3, flat)
got = tri_tri(p, q)
assert got == by_segments(p, q), (p, q)
assert got == by_separating_axes(p, q), (p, q)
assert got == tri_tri(q, p)
assert got == tri_tri([p[1], p[2], p[0]], [q[2], q[1], q[0]])
hits += got
assert 500 < hits < 3500
def test_against_oracles_fractions():
rng = random.Random(2003)
for _ in range(600):
p = [tuple(Fraction(rng.randint(-8, 8), rng.randint(1, 4)) for _ in range(3)) for _ in range(3)]
q = [tuple(Fraction(rng.randint(-8, 8), rng.randint(1, 4)) for _ in range(3)) for _ in range(3)]
if degenerate(p) or degenerate(q):
continue
assert tri_tri(p, q) == by_segments(p, q) == by_separating_axes(p, q)
def test_touching_cases_from_shared_vertices():
rng = random.Random(7)
for _ in range(800):
p = rand_tri(rng, 2)
q = rand_tri(rng, 2)
q = [p[rng.randrange(3)], q[1], q[2]] # force a shared vertex
if degenerate(q):
continue
assert tri_tri(p, q)
assert by_segments(p, q) and by_separating_axes(p, q)
History
Tomas Möller published the test in 1997, in the Journal of Graphics Tools, as a fast test for collision detection and for the intersection of meshes. Philippe Guigue and Olivier Devillers published a version in 2003 that uses only orientation predicates, so that it can be made robust with exact predicates. The exact predicates come from the work of Jonathan Shewchuk in 1997 on adaptive floating point arithmetic.
References
- Tomas Möller, A fast triangle-triangle intersection test, Journal of Graphics Tools 2(2), 1997, 25 to 30, the description of the test (plane rejection, the intervals on the line of intersection and the coplanar case)
- Philippe Guigue and Olivier Devillers, Fast and robust triangle-triangle overlap test using orientation predicates, Journal of Graphics Tools 8(1), 2003, 25 to 32, the overlap test that uses only orientation predicates, and its coplanar case
- Jonathan Richard Shewchuk, Adaptive precision floating-point arithmetic and fast robust geometric predicates, Discrete and Computational Geometry 18(3), 1997, 305 to 363, the sections on the orient3d predicate and its adaptive evaluation
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag QR3KY9 Edit this page History Report an error Markdown