0
$\begingroup$

I have been watching this series on khancademy and in it they try to explain how to find out if a ray intersects a triangle. They do a good job explaining how to find the point of intersection of the plane of the triangle but they do an incomplete job of explaining how after that checking if the point is in the triangle is done.

They explain that you can use weighted averages to calculate this by first calculating them and then checking if it's negative or not but in the explanation in the exercises they only pick points of triangles that can exactly be added or subtracted from each other to cancel out. thus being useless for any other situation (which i need because i'm trying to make a ray tracer).

So i want to know how can you calculate the weights of the points that together make up the weighted average

For instance you have 3 points A, B and C each with their xyz value and you have an intersection point I. What do the weights of A,B and C have to be to get point I.

video https://www.khanacademy.org/partner-content/pixar/rendering/rendering-2/v/rendering-10

exercises https://www.khanacademy.org/partner-content/pixar/rendering/rendering-2/e/triangle-intersection-3d (notice how in these exercises they pick points that are always able to cancel each other out which makes their method in the exercises useless when trying to make a ray tracer)

$\endgroup$
1
0
$\begingroup$

I think your question has already been answered here.

But, if not, the basic idea is that the "weights" (also known as "barycentric coordinates") are areas of certain triangles. When you say they "cancel out", maybe you mean that they add up to $1$. This will always be the case -- if you take any point in the plane of the triangle, the sum of its barycentric coordinates will be equal to $1$. This is a mathematical fact; it's not because the Kahn folks chose some special unrealistic examples.

There are ways to do ray-triangle intersection directly, without computing and checking ray-plane intersections. See this page, which includes the necessary code, and this page, which describes the whole process in great detail.

$\endgroup$
2
  • $\begingroup$ these barycentric coordinates indeed seem to be what i'm looking for altough i dont quite yet know how to get the weights yet from that other question. i'l look into those barycentric coordinates and hope that i can use that to see if a point is in a triangle $\endgroup$
    – Paul Boon
    Dec 30 '15 at 15:06
  • $\begingroup$ Barycentric coords and formulae for calculating them are given here: en.wikipedia.org/wiki/Barycentric_coordinate_system. Section 2.4 shows how their values can be used to determine whether or not a point lies in a triangle. $\endgroup$
    – bubba
    Dec 31 '15 at 2:08

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.