Main content

## Pixar in a Box

### Unit 15: Lesson 2

Mathematics of rendering- Start here!
- 1. Ray tracing intuition
- 2D rendering intuition
- 2. Parametric form of a ray
- Parametric ray intuition
- 3. Calculate intersection point
- Solve for t
- 4. Using the line equation
- Ray intersection with line
- 5. 3D ray tracing part 1
- Ray intersection with plane
- 6. 3D ray tracing part 2
- Triangle intersection in 3D

© 2023 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# 6. 3D ray tracing part 2

Now we just need to determine whether our intersection point is inside or outside the triangle.

Click here to review weighted averages of three points.

Click here to review weighted averages of three points.

## Want to join the conversation?

- How am I supposed to solve those simultaneous three equations?(10 votes)
- You could put them in a matrix and then put them in reduced echelon form, or just do it directly without using matrices - using simultaneous equations. Keep in mind that they're both the same thing.(3 votes)

- When I'm old enough I definitely want to become an animator! Does anyone else want to?(8 votes)
- Why a+b+c=1 in here?(3 votes)
- They are specified to add up to one to make the equation easier. a, b and c are the weights of a weighted average. You would normally compute a weighted average by computing a * A + b * B + c * C / (a + b + c). However, the result of choosing for instance a=4, b=3, c=1 are always the same as the result of choosing a=8, b=6, c=2. That is to say, you can scale the weights arbitrarily as long as they stay in the same proportion. To make the equation easier, you can define that a, b and c are always scaled in such a way that they add up to 1. You don't need to, but it just makes the equation a bit easier to grasp.(2 votes)

- I already learned linear algebra a while back, so I would like to see an example of using vector algebra - if you could give me an example OR give me a name to a resourceful video topic, that would be very useful!

Thanks for your time! :-)(2 votes)- I found an article/tutorial by scratchpixel to be very helpful. Just search "calculating barycentric coordinates" on google and it should be the top result.(1 vote)

- How do you solve for the weights a, b, c(2 votes)
- I have learnt everything here in pixar thanks for it khan academy.

But is there any program or anything where i can try to produce my short story(2 votes) - At0:19, she said that the method their ray-tracers use make use of vector algebra. What is that method, and how is it different from what she teaches here?(1 vote)
- How are we able to pick a, b, and c such that they add to one? Couldn't the ray strike anywhere on this polygon? Is this just to reduce some of the math for the sake of the lesson, or is the midpoint of ABC frequently used in this situation?(1 vote)
- how do i finally create an animation pls TELL MEEEEEE!(1 vote)

## 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.