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:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
This isn't the right stackexchange for this question, but it's been answered already here.… – ThinkingMedia Apr 21 '13 at 17:23
@Mathew Foscarini This is the second time I got told to have posted the question to the wrong stackexchange. Frankly speaking I have no idea which one to post, but your link turns out to be very useful and solved my problem. Thanks anyway. – God_of_Thunder Apr 22 '13 at 14:59
It's not so much that it's the wrong place, but that the users of this stackexchange won't give you the best answer simply because this is outside their scope of interest. You'll find people over at gamedev far more friendly cause they share the same interest in 3D graphics and 3D math. – ThinkingMedia Apr 22 '13 at 16:32
@Mathew Foscarini I thought this place convers a wide range of computer science related topics, not just programming. Maybe I am wrong. – God_of_Thunder May 13 '13 at 22:57
Well, programmers stack exchange is not computer science stack exchange. But actually, you got a link to an answer here, so your question was not totally misplaced here ;-) – Doc Brown Jun 20 '13 at 20:32

You might find that adding a little random noise to troublesome coordinates can be helpful.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.