Triangle/Ray Intersection (original) (raw)

Fast vectorized triangle/ray intersection algorithm

6.2K Downloads

Updated18 May 2018

View License

Ray/triangle intersection using the algorithm proposed by Möller and
Trumbore (1997), implemented as highly vectorized MATLAB code.
The algorithm can work with one and two sided surfaces, as well as, with
infinite lines, rays (lines bounded on one side) and segments (lines bounded on
both sides).
Input (all arrays in in Nx3, where N is number of vertices or rays):
orig : ray's origin
dir : ray's direction
vert0, vert1, vert2: vertices of the triangle
Output:
Intersect - boolean array of length N
t - distance from the ray origin to the intersection point in |dir|
u,v - barycentric coordinates of the intersection point units
xcoor - carthesian coordinates of the intersection point
In addition PointInsideVolume is 3D equivalent to 2D inpolygon function and can test if
array of points is inside or outside any volume defined by the surface grid.

Cite As

Jaroslaw Tuszynski (2024). Triangle/Ray Intersection (https://www.mathworks.com/matlabcentral/fileexchange/33073-triangle-ray-intersection), MATLAB Central File Exchange. Retrieved December 27, 2024.

MATLAB Release Compatibility

Created with R2017b

Compatible with any release

Platform Compatibility

Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

html/

Version Published Release Notes
1.7 18 May 2018 small corrections to the interface
1.6.0.0 25 Sep 2017 Minimal changes suggested by Igor in Comments and Ratings Download
1.5.0.0 15 Jun 2016 correct description: no symbolic toolbox is neededMajor rewrite of the function with additional options and output variables. Also provided PointInsideVolume function Download
1.4.0.0 7 Jun 2013 documentation improvements and typo correction Download
1.2.0.0 21 Mar 2013 correct treatment of 3x3 arrays as suggested by Andreas Weber Download
1.1.0.0 7 Oct 2011 Improvements to border handling Download
1.0.0.0 29 Sep 2011 Download