4.5 | 2 ratings Rate this file 38 Downloads (last 30 days) File Size: 167 KB File ID: #33073
image thumbnail

Triangle/Ray Intersection



29 Sep 2011 (Updated )

Fast vectorized triangle/ray intersection algorithm

| Watch this File

File Information

Ray/triangle intersection using the algorithm proposed by Möller and
Trumbore (1997), implemented as highly vectorized MATLAB code.

 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
   options: aditional customization options
     options.epsilon (default = 1e-5)
     options.triangle - 'one sided' or 'two sided' (default) - how to treat
       triangles. In 'one sided' version only intersections in single
       direction are counted and intersections with back facing
          tringles are ignored
     options.ray - 'ray' (default) or 'segment' - how to treat ray as an
     infinite line (ray) or as line segment defined by a vector

   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


Ray/Triangle Intersection inspired this file.

This file inspired Ray Shape Article Fex.Zip.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
24 Mar 2014 Nick

Very useful but when considering many rays and many triangles is there a way to find which ray has intersected which triangle?

24 Mar 2014 Nick  
28 Aug 2013 Amilcar Torres

Excellent.. Really helpful!!!

12 Apr 2013 Ben

Looks great. Downloaded and will try it later.

06 Oct 2012 Jaroslaw Tuszynski

Re to Anton Semechko: This is a low level function which can be called with one ray and many faces, many faces and one ray or many faces and rays. It is quite simple to apply repmat function to the inputs.

28 Feb 2012 Anton Semechko

why does the number of rays have to equal the number of faces? that's so inconvenient

07 Oct 2011

Improvements to border handling

21 Mar 2013

correct treatment of 3x3 arrays as suggested by Andreas Weber

07 Jun 2013

documentation improvements and typo correction

Contact us