Main content

### Course: 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

© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# 2. Parametric form of a ray

This video introduces the parametric form of a ray in 2D. To find the intersection of a two-dimensional ray and a line segment, we use slope intercept form. But this method doesn't work in three dimensions! In 3D, we can represent a ray using a parametric function. This function, R(t), is a weighted average of two points, and it's super handy for naming points on the ray. Click here to review weighted averages of two points. Click here to review slope-intercept form of a line.

## Want to join the conversation?

- At1:29, Susan says that in three dimensions, rays don't have slope-intercept forms. Why is this? Why can't we write "z = ax + by + c", or convert "z − z0 = a(x − x0) + b(y − y0)" to that form instead?(11 votes)
- Both of those equations give you a plane. You can see this by fixing the x-value, such that ax = c1, to get the equation z = c1 + by + c. Then you can combine the two constants, c and c1 into a new constant c2, to get z = by + c2. This is the equation for a line. So for every x-value you pick, you get a line and an infinite number of lines side-by-side gives you a plane.

Essentially you have too many degrees of freedom. You can pick any value for one coordinate, and any value for the second, and only then will the third coordinate be constrained.(21 votes)

- For anyone else that found their parametric form initially confusing, here's how I made sense of it: we want to go from C to P as t goes from 0 to 1. So we start at C, find the distance that t will change our position over, and multiply by t. R(t) = C + (P-C)t. You can multiply this out and simplify to get the same equation they use: R(t) = C + Pt-Ct = (1-t)C + tP.(4 votes)
- Couldn't you use trig for this?(0 votes)
- Why make a problem harder when it isn't necessary?(5 votes)

- At0:27, how you calculated slope-intercept form?(1 vote)
- Making an animation in Unity with ray tracing, what are the specs recommended for my PC to render the animation?(5-10mins long.)(1 vote)
- Why are weighted averages used for the ray?(1 vote)
- can i have something thing fun(1 vote)
- Why are weighted averages used in the parametric function of the array?(1 vote)
- - Recall that to figure out where a two-dimensional ray intersects a line segment, we started by first introducing a coordinate system. Once we have our coordinate system, we can write our line AB in slope intercept form. Since in this example A has coordinates three two, and B has coordinates four negative one, the slope intercept form of AB is y equals negative three x plus 11. Similarly, if I pick P to have coordinates two, one half, then the slope intercept form of the ray CP is y equals one quarter x. The point I we're looking for is on both of these lines. So if I sub x and I sub y represent the coordinates of I, then I sub y equals negative three I sub x plus eleven, because I lies on AB. And I sub y equals one quarter I sub x, because I lies on the ray CP. Solving these two equations for the two unknowns gives us the coordinates I sub x and I sub y. Using the slope intercept form of the ray works in two dimensions, and is fairly simple to understand, but there's a problem when we generalize it to three dimensions. The problem is that in three dimensions, the ray doesn't have a slope intercept form. So we'll have to throw out this representation of our ray in preparation for three dimensional raytracing. To represent our ray CP, we'll use something called a parametric function. What I'm about to write looks a little strange at first, but bear with me, these functions start to become familiar with practice. My ray will be represented by a new function, R of t, that is the weighted average of C and P, where t is the weight. In particular, I'm going to write R of t as one minus t times C, plus t times P. Notice what happens when t equals zero. One minus t is just one. So R of zero is C. And when t equals one, R of one equals P. That's convenient, because I can relabel C as R of zero, and I can relabel P as R of one. R of one half would be exactly halfway between C and P. Values of t greater than one name points on the ray off in the scene beyond P. Before we continue, get some experience using this kind of parametric function in the next exercise.(0 votes)
- - Recall that to figure out where a two-dimensional ray intersects a line segment, we started by first introducing a coordinate system. Once we have our coordinate system, we can write our line AB in slope intercept form. Since in this example A has coordinates three two, and B has coordinates four negative one, the slope intercept form of AB is y equals negative three x plus 11. Similarly, if I pick P to have coordinates two, one half, then the slope intercept form of the ray CP is y equals one quarter x. The point I we're looking for is on both of these lines. So if I sub x and I sub y represent the coordinates of I, then I sub y equals negative three I sub x plus eleven, because I lies on AB. And I sub y equals one quarter I sub x, because I lies on the ray CP. Solving these two equations for the two unknowns gives us the coordinates I sub x and I sub y. Using the slope intercept form of the ray works in two dimensions, and is fairly simple to understand, but there's a problem when we generalize it to three dimensions. The problem is that in three dimensions, the ray doesn't have a slope intercept form. So we'll have to throw out this representation of our ray in preparation for three dimensional raytracing. To represent our ray CP, we'll use something called a parametric function. What I'm about to write looks a little strange at first, but bear with me, these functions start to become familiar with practice. My ray will be represented by a new function, R of t, that is the weighted average of C and P, where t is the weight. In particular, I'm going to write R of t as one minus t times C, plus t times P. Notice what happens when t equals zero. One minus t is just one. So R of zero is C. And when t equals one, R of one equals P. That's convenient, because I can relabel C as R of zero, and I can relabel P as R of one. R of one half would be exactly halfway between C and P. Values of t greater than one name points on the ray off in the scene beyond P. Before we continue, get some experience using this kind of parametric function in the next exercise.(0 votes)

## Video transcript

- Recall that to figure out where a two-dimensional ray intersects a line segment, we started by first introducing a coordinate system. Once we have our coordinate system, we can write our line AB in slope intercept form. Since in this example A has coordinates three two, and B has coordinates four negative one, the slope intercept form of AB is y equals negative three x plus 11. Similarly, if I pick P to have coordinates two, one half, then the slope intercept form of the ray CP is y equals one quarter x. The point I we're looking for is on both of these lines. So if I sub x and I sub y represent the coordinates of I, then I sub y equals negative three I sub x plus eleven, because I lies on AB. And I sub y equals one quarter I sub x, because I lies on the ray CP. Solving these two equations for the two unknowns gives us the coordinates I sub x and I sub y. Using the slope intercept form of the ray works in two dimensions, and is fairly simple to understand, but there's a problem when we generalize it to three dimensions. The problem is that in three dimensions, the ray doesn't have a slope intercept form. So we'll have to throw out this representation of our ray in preparation for three dimensional raytracing. To represent our ray CP, we'll use something called a parametric function. What I'm about to write looks a little strange at first, but bear with me, these functions start to become familiar with practice. My ray will be represented by a new function, R of t, that is the weighted average of C and P, where t is the weight. In particular, I'm going to write R of t as one minus t times C, plus t times P. Notice what happens when t equals zero. One minus t is just one. So R of zero is C. And when t equals one, R of one equals P. That's convenient, because I can relabel C as R of zero, and I can relabel P as R of one. R of one half would be exactly halfway between C and P. Values of t greater than one name points on the ray off in the scene beyond P. Before we continue, get some experience using this kind of parametric function in the next exercise.