INTERSECTLINETRIANGLE3D Intersection point of a 3D line and a 3D triangle.
POINT = intersectLineTriangle3d(LINE, TRI)
Compute coordinates of the intersection point between the line LINE and
the triangle TRI.
LINE is a 1-by-6 row vector given as: [X0 Y0 Z0 DX DY DZ]
TRI is given either as a row vector [X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3], or as
a 3-by-3 array, each row containing coordinates of one of the triangle
vertices.
The result is a 1-by-3 array containing coordinates of the intesection
point, or [NaN NaN NaN] if the line and the triangle do not intersect.
[POINT POS] = intersectLineTriangle3d(LINE, TRI)
Also returns the position of the intersection point on the line, or NaN
if the line and the supporting plane of the triangle are parallel.
[POINT POS ISINSIDE] = intersectLineTriangle3d(LINE, TRI)
Also returns a boolean value, set to true if the line and the triangle
intersect each other. Can be used for testing validity of result.
Example
line = [1 1 0 0 0 1];
tri = [0 0 5;5 0 0;0 5 0];
intersectLineTriangle3d(line, tri)
ans =
1 1 3
See also
points3d, lines3d, polygons3d, intersectRayPolygon3d,
distancePointTriangle3d
References
Algorithm adapted from SoftSurfer Ray/Segment-Triangle intersection
http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm
Package: matgeom