If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

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.

Want to join the conversation?

  • leaf red style avatar for user Blaze
    How am I supposed to solve those simultaneous three equations?
    (10 votes)
    Default Khan Academy avatar avatar for user
  • duskpin ultimate style avatar for user JadaRodriguez
    When I'm old enough I definitely want to become an animator! Does anyone else want to?
    (8 votes)
    Default Khan Academy avatar avatar for user
  • leafers sapling style avatar for user Maozi Yang
    Why a+b+c=1 in here?
    (3 votes)
    Default Khan Academy avatar avatar for user
    • starky ultimate style avatar for user Ruben D
      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)
  • hopper cool style avatar for user Iron Programming
    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)
    Default Khan Academy avatar avatar for user
  • winston baby style avatar for user Destroyer
    How do you solve for the weights a, b, c
    (2 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Vatsya Aggarwal
    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)
    Default Khan Academy avatar avatar for user
  • piceratops ultimate style avatar for user Khan Gressman
    At , 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)
    Default Khan Academy avatar avatar for user
  • starky ultimate style avatar for user The Teenage Artist
    is this the end?
    (1 vote)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user mddeforge
    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)
    Default Khan Academy avatar avatar for user
  • hopper cool style avatar for user ッ Coder ッ
    how do i finally create an animation pls TELL MEEEEEE!
    (1 vote)
    Default Khan Academy avatar avatar for user

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.