teaching machines

Torus

May 27, 2021 by . Filed under public, slai-2021.

This post is part of a course on geometric modeling at the Summer Liberal Arts Institute for Computer Science held at Carleton College in 2021.

Rings are a big deal. We coat them in sugar and eat them for a snack. We commit to a partner with one. We drive on two or four or eighteen of them. To mathematicians, a ring is a torus. In this exercise, you’ll craft you’re very own torus using by revolving a circle.

Draw

On your paper, draw the y-axis. To its right, draw a circle with a few points spread around the perimeter. This circle holds the set of seed points of your torus. You will revolve this circle around the y-axis to form your torus.

Draw a similar circle to the left of the y-axis. Connect the two circles to each other to form a half donut.

Function

Write a function named generateTorus. Have it accept these parameters:

Copy your code from generateSphere into this function. Much of it will be the same.

Positions

The seed positions of the torus are very similar to the seed positions of the sphere, but instead of generating just those on a semicircle, you must generate points across the entire circle, and that circle must be pushed rightward of the y-axis. Follow these steps to adapt your sphere code:

Revolve the seed points to produce your positions array, just as you did with the sphere. When you render the positions as points, you should see a donut-like shape.

Triangles

The triangles of the torus are formed much as you formed the triangles of the sphere. But the torus doesn’t have poles. Remove the cap generation logic from the code you copied. Render your capsule as a solid mesh.

You may see a gap in your torus. That’s because a sphere and torus have a different topology. In both, the right edge of the grid wraps back around to the left edge. But only in the torus does the top edge of the grid wrap back around to the bottom. To fix the topology, ensure that you visit every possible latitude index, and use wrapped addition to connect each row to the next one “above” it.