Now, how do we draw a donut, AKA torus? Well, a torus is a solid of revolution, so one way to do it is to draw a 2D circle around some point in 3D space, and then rotate it around the central axis of the torus. Churning through the above gets us an point on the surface of our torus, rotated around two axes, centered at the origin. To calculate illumination, we need to know the surface normal - the direction perpendicular to the surface at each point. The derivation of the surface normal direction turns out to be pretty much the same as our derivation of the point in space. The surface normal of the point on the circle is fairly obvious: it's the same as the point on a unit circle centered at the origin. So our surface normal is derived the same as above, except the point we start with is just. If it's < 0, the surface // is pointing away from us, so we won't bother trying to plot it.

Send Feedback | WebAssembly Version (beta)

⬆