e15190.utilities.ray_triangle_intersection.moller_trumbore¶
- e15190.utilities.ray_triangle_intersection.moller_trumbore(ray_origin, ray_vectors, triangles, mode='einsum', tol=1e-09)¶
Implementation of Moller-Trumbore ray-triangle intersection algorithm To read more about the mathematical derivation, visit https://www.scratchapixel.comhttps://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection.
- Parameters
ray_origin – array of shape (3, ) This implementation only allows all rays to have one common origin.
ray_vectors – array of shape (n_rays, 3) The ray vectors are only used to tell the directions. No normalization is needed.
triangles – array of shape (n_triangles, 3, 3) An array of 3 x 3 arrays. Each 3 x 3 array consists of three vertices that specify the triangle. For example, the y-coordinate of the first vertex in the fifth triangle would be triangles[4][0][1].
mode – str, default ‘einsum’ To select different implementations of the algorithm. In ‘einsum’ mode, the numpy.einsum() function is heavily used to optimize the calculations. Otherwise, we will use the implementation without ‘einsum’. Our simple test suggests, for 1 million rays and 12 triangles, ‘einsum’ mode performs at least two times faster than the mode without ‘einsum’.
tol – float, default 1e-9 Tolerance for checking the determinant in the algorithm. If the determinant is smaller than the tolerance, then the ray would be assumed parallel to the plane of the triangle, hence no attempt would be made to determine the intersection point.
- Returns
A numpy.ndarray of intersections with shape (n_triangles, n_rays, 3).