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?
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:
Here's how it works:
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top