https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
we present a clean algorithm for determining whether a ray intersects a triangle. the algorithm translates the origin of the ray and then changes the base of that vector which yields a vector
where t is the distacen to the plane in which the triangle lies and (u,v) represents the coordinates inside the triangle.
one advantage of this method is that the plane equation need not be computed on the fly nor be stored, which can amount to significant memory savings for triangle meshes. as we found our method to be comparable in speed to previous methods, we believe it is the fastest ray/triangle intersection routine for triangles which do not have precomputed plane equations.
keywords: ray tracing, intersection, ray/triangle-intersection, base transformation.
1 introduction
a ray R(t) with origin O and normalized direction D is defined as
and a triangle is defined by three vertices Vo, V1, and V2. In the ray/triangle intersection problem we want to determine if the ray intersects the triangle. Previous algorithms have solved this by first computing the intersection between the ray and the plane in which the triangle lies and then testing if the intersection
point is inside the edges.
our algorithm uses minimal storage (i.e only the vertices of the triangle need to be stored) and does not need any preprocessing. For triangle meshes, the memory savings are significant ranging from about 25% to 50% depending on the amount of vertex sharing.
in our algorithm, a transformation is constructed and applied to the origin of the ray. the transfomation yields a vector containing the distance, t, to the intersection and the coordinates, (u,v), of the intersection.
2 intersection algorithm
a point, T(u,v), on a triangle is given by
where (u,v) are the barycentric coordinates, which must fulfill u>=0, v>=0 and u+v<=1.
note that (u,v) can be used for texture mapping, normal interpolation, color interpolation etc. computing the intersection between the ray, R(t), and the triangle, T(u,v), is equivalent to R(t) = T(u,v), which yields:
这个交点,既在平面上,又在射线上。所以满足上面的方程。
rearranging the terms gives:
D是单位化之后的射线的方向
O是射线的起点(原点)
V0/V1/V2是三角形的三个顶点
this means the barycentric coordinates (u,v) and the distance, t, from the ray origin to the intersection point can be found by solving the linear system of equations above.
the above can be thought of geometrically as translating the triangle to the origin, and translating it to t a unit triangle in y&z with the ray direction aligned with x, as illustrated in figure 1 (where M=[-D, V1-V0, V2-V0] is the matrix in equation 4).
figure 1: translation and change of base of the ray origin
Arenberg describes a similar algorithm to the one above. he also constructs a 3x3 matrix but uses the normal of the triangle instead of the ray direction D. this method requires storing the normal for each triangle or computing them on the fly.
这个方向需要存储三角形的法线,或者是在运行时计算。
denoting E1=V1-V0, E2=V2-V0 and T=O-V0, the solution to equation (4) is obtained by using Cramer’s rule: