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

Current time:0:00Total duration:4:11

now that we can retrace in 2d we can finally go back to the problem we really want to solve retracing in 3d in particular we'll need to retrace flat plains houses and ultimately characters a character like Carl is a complex shape but as we discuss in the character modeling lesson he can be broken down into lots of small four-sided quadrilaterals that is four-sided polygons and each quadrilateral can be converted into two triangles by adding an edge that connects diagonal points that leads to the question how do you intersect array with a triangle it turns out that that's one of the most fundamental calculations that a ray tracer performs here's the scene consisting of just one triangle our real scenes contain millions of triangles but once we know how to intersect a single triangle our ray tracer just keeps doing that over and over again now I don't know about you but I don't want to do the same thing over and over again so it's a good thing we have computers to help us out and that they don't get tired as in 2d we start by setting up a coordinate system but this time there are three directions x y and z as we explained earlier we pick a camera position call it C and a viewing direction and we construct an image plane perpendicular to the viewing direction this is where our image will be formed let's pick a pixel P on the image plane and construct the parametric representation of the Ray CP as R of T equals 1 minus T times C plus T times P this is the same equation we saw in 2d but now it represents three separate equations one for x coordinates one for y coordinates and one for z coordinates remember that in the previous video we saw that in two dimensions every line can be written in an implicit form as ax plus B Y plus C equals 0 very similar to this is the equation for a plane and every triangle lies in a plane the equation for a plane can be written in implicit form as ax plus B y plus cz Plus D equals zero the intersection point I we're looking for is in the plane of the triangle meaning that a times I sub X plus B times I sub y plus C times I sub Z plus D equals 0 where I sub X I sub y and I sub Z are the coordinates of I I is also on the Ray meaning that there's a value of T again let's call it T star such that I equals R of T star which equals 1 minus T star times C plus T star times P which is really the three equations shown here one for X 1 for Y and one for Z now we have four equations and four unknowns to solve the system of equations we can follow the recipe from 2d and substitute the last three equations into the first one this gives us one equation with only one unknown T star but it turns out when you put all these substitutions in it looks pretty scary but remember it's not that bad we're just plugging one value from one equation into another solve this for T star then substitute back into the Ray equations to get I sub X I sub y and I sub Z now I know we've gone kind of fast but the next exercise will let you practice computing intersection points for yourself