1
$\begingroup$

So, I'm following the Pixar tutorials on KhanAcademy, and thanks to that I'm now trying to make my own renderer. For this, I need to be able to determine whether a point I is inside, or outside a triangle in 3D space. I will be on the same plane as the triangle.

The way Pixar suggests using here, is weighted averages, which uses the formula: I = aA + bB + cC

With the three coordinates (Ix, Iy, Iz), it is possible to determine a, b and c, by solving the system of linear equations. When one or more of a, b, c is negative, I is outside of the triangle.

What I'm trying to do, is determining whether I is inside a triangle of which A, B and C have a Z-value of zero. Using the system of linear equations is not possible here.

How can I determine whether I is inside a triangle or not when all values of one axis are zero? I can just 'cut the axis off', but I was hoping there was a more easy way. I've taken a look at Check whether a point is within a 3D Triangle, but I didn't quite understand the answers given.

Thank you very much for trying to help me out! :)

$\endgroup$
3
  • $\begingroup$ A t is missing in weigh(t)ed at your title. Please correct it. $\endgroup$ – callculus Jul 8 '16 at 16:08
  • $\begingroup$ Err thanks :) And done. :) $\endgroup$ – theysconator Jul 8 '16 at 16:19
  • $\begingroup$ I derped there. Now it should be fixed. $\endgroup$ – theysconator Jul 8 '16 at 21:13
0
$\begingroup$

There is an easier way for 2D triangles. Write a function LeftOf($x,y,z$), which returns True if $z$ is left of the directed line through $xy$, False otherwise. Then $I$ in strictly inside $\triangle ABC$ if

LeftOf($A,B,I$) and LeftOf($B,C,I$) and LeftOf($C,A,I$)

If you want to consider $I$ inside when on the boundary, adjust the definition of LeftOf() to LeftOfOn() accordingly.

LeftOf() computes the signed area of the triangle, and uses the sign to return True or False. You can find code for this all over the web, e.g., here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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