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.
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.
Write a function named
generateTorus. Have it accept these parameters:
- An integer
nlatitudesthat specifies the number of points that appear on the circular cross section of the torus.
- An integer
nlongitudesthat specifies the number of circular cross sections that will appear revolved around the torus.
majorRadiusof the torus, which is the distance between the center of the inner void and the center of the tube.
minorRadiusof the torus, which is the radius of the circular cross section.
Copy your code from
generateSphere into this function. Much of it will be the same.
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:
- Range-map the latitude index so that it generates the seed points around the entire circle, whose interval is $[0, 2\pi]$.
- Tweak the xy-coordinates so that they are on a circle with the given minor radius.
- Tweak the x-coordinate calculation so that the seed points are pushed rightward by the major radius.
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.
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.