intersectstriangle46

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analytical Geometry
Introduced first in SolidGeometry 1.0, Creation date: 2012-07-13, Last change: 2025-09-14

fundamental fnct for the intersection between a ray and a triangle

Description

References see: http://www.lighthouse3d.com/tutorials/maths
MAJOR CHANGE IN SG-LIB 4.7 because of a clear missing intersection


See Also: crossingfacets2VLFL , cross2F , intersectstriangle , crosspointVLFL , VLprojection

Example Illustration

 missing image of intersectstriangle46(p,d,v0,v1,v2)

Syntax

[b,t]=intersectstriangle46(p,d,v0,v1,v2)

Input Parameter

p: Point of line
d: Direction of line
v0: Vertex 0
v1: Vertex 1
v2: Vertex 2

Output Parameter

b: if t>0 and intersecting point exists
t: intersecting point is p+t*d

Examples


[a,b]=intersectstriangle([5 5 -10],[0 0 1],[0 0 0],[10 0 0],[10 10 0])




Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, intersectstriangle46, determines if a ray intersects with a triangle in 3D space. It is a fundamental function for intersection calculations between a ray and a triangle.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize a threshold thr to 1e-7 for numerical precision.
  2. Set t to infinity, indicating no intersection initially.
  3. Calculate edge vectors of the triangle: e1 = p2 - p1 and e2 = p3 - p1.
  4. Compute the cross product h = cross(d, e2).
  5. Calculate a = e1 * h' (dot product).
  6. Check if a is near zero (within thr), indicating the ray is parallel to the triangle's plane. If so, set b = false and return.
  7. Compute f = 1/a.
  8. Calculate vector s = p0 - p1.
  9. Determine u = f * (s * h'). If u is outside the range [0, 1], set b = false and return.
  10. Compute q = cross(s, e1).
  11. Calculate v = f * (d * q'). If v is less than 0 or u + v > 1, set b = false and return.
  12. Determine t = f * (e2 * q').
  13. If t > thr, set b = true and return, indicating a valid intersection point exists.
  14. If none of the above conditions are met, set b = false.
Algorithm explaination created using ChatGPT on 2025-08-19 07:13. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21