As part of a ray tracer implementation, I need to compute the barycentric coordinates in a triangle in 3D in order to decide if a ray hits the triangle or not. In theory this could be done by simply solving a few linear equations. But due to the fact that the vertices of a triangle could have the same x, y or z coordinates, some of the coefficients in the equations would be 0, and this caused numerical error in my initial implementations. So, is there a systematic approach to find the barycentric coordinates in a more efficient way? Or I have no choice but to brutally check each possibility one by one?
1 Answer
You might find that adding a little random noise to troublesome coordinates can be helpful.
-
This answer is better than most people might think! At least for fast approximation -- some perturbance might actually be preferable to what it takes for ray/tri intersection to be watertight.– user204677Commented Dec 12, 2017 at 22:06