Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

I have a triangle in a 3-dimensional coordinate system that I want to draw to a screen. I'm able to flatten the triangle to 2 dimensions and determine whether an arbitrary point on the screen falls within the flattened object. What I don't know how to do is determine the Z-index of that point.

As an example, let's say the triangle is bounded by the points $(2, 2, 0)$, $(2, 8, 5)$, and $(8, 5, 10)$ (where higher Z values are behind lower ones, in case that's not clear) and mapped to a $10 \times 10$ screen. The flattened points, according to the system I'm using, are $(2, 2)$, $(3, 7)$, and $(6.5, 5)$. The arbitrary point $(5, 3)$ falls within this flattened triangle; how can I determine the Z-index of that point on the original triangle?

share|cite|improve this question
up vote 3 down vote accepted

You can calculate the barycentric coordinates of the point (as described by Wikipedia) and then calculate the $z$ index as the weighted average of the $z$ indices of the vertices, with the barycentric coordinates as weights.

share|cite|improve this answer
This worked perfectly! Thanks a ton for the information. – Fraxtil Jul 22 '12 at 21:32
@Fraxtil: You're welcome! – joriki Jul 22 '12 at 21:33

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.