Main content

## Mathematics of rendering

# 6. 3D ray tracing part 2

## Video transcript

- In the previous video, we saw how to compute an intersection point, I, that lies in the plane of a triangle. But how can we tell if the point is like this one, that's inside the triangle; or like this one, that's outside the triangle? The method our ray tracer actually uses makes use of vector algebra. But a method that is essentially the same is easy to explain if you understand weighted averages. (bell) Notice that as I change the weights in the average, the intersection point, I, moves. And if all the weights are positive, I is inside the triangle. But look what happens when one or more weights is negative: I escapes from the triangle. Bingo! If we can determine the weights needed to produce I, we can simply check their signs. If one or two of them is negative, I is outside the triangle, and otherwise, I is inside. But how can we determine the weights? Let's leave them as unknowns for the moment, and we'll call them little a, little b, and little c. Every point I in the plane of big A, big B, and big C can be written as a weighted average of big A, big B, and big C. If I pick little a, little b, and little c, so that they add to one, then I can forget about the denominator. The resulting equation, I equals little a times big A plus little b times big B plus little c times big C represents the following three equations: one for the x-coordinate, one for the y-coordinate, and one for the z. We know I, big A, big B, and big C, so the only unknowns are little a, little b, and little c. So this is three equations and three unknowns that can be solved for the values of little a, little b, and little c. Once you know little a, little b, and little c, check their signs to determine if I is inside the triangle. In this final exercise, you'll be asked to compute intersection points I, and determine if they lie inside or outside the triangle. Now, after all that, go forth and write your own ray tracer.