hello guys,

in my program, i need to check if an arbitrary 3D line segment intersects with any edge of a 3D triangle (but they are actually in the same plane).

my approach is to solve the equations that are consisted of the line function of the line segment and the line functions of the triangle edges.

once i have a result, i then check if the intersection point is actually on the line segment and one of the triangle edges.


however, i got float point rounding error problems, because the equation solving part involves some subtractions, especially when the triangle and the line segment are very small.

the actual problem happens at where i need to check if a denominator is 0. sometimes, the denominator should be 0, but because of the rounding error, it is not but a very small value.



i thought about using barycentric coordinates method, instead of directly solving the equations, but in my program, i need not only checking if they intersect with each other but also finding out the intersection point. with barycentric coordinates, it is easy to tell if a line segment intersects a triangle edge by checking if one of it's endpoint is outside the triangle, but i don't know how to get the intersection point.




i have two ideas to solve this problem, either transforming the line segment and the triangle into a 2D coordinate system, as there are a lot of intersection solutions in 2D. but why don't those 2D intersection methods have the float point rounding error problem?

or maybe i can use a small value instead of 0 in my equation solving function to check the denominator. is this reasonable? because i did see someone's code doing this trick.

thank you.





or is there any better way to solve linear equations? say using matrix?