teaching machines

Sphere

May 25, 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.

Consider the sphere. How are spheres made in nature? There are several ways. The sphere we live on was formed by gravity pulling masses together into a ball. Rocks smooth to spheres when forces erode them on all sides equally. Nature’s sphere-making processes take eons. We humans don’t have that kind of time, so we use math to speed things. In this exercise, we’ll make a sphere as surface of revolution.

Draw

On your paper, draw a semi-circle that forms the right side of a sphere, starting at the south pole and ending at the north. Label the south pole as -90 degrees. What is that in radians? Label the north pole as 90 degrees. What is that in radians?

Draw five or more points between the poles of the semi-circle, distributed evenly. Do not include the poles for reasons we’ll discuss later. The points you did draw represent a set of seed points, which are the starting points along the first line of longitude. To generate the other lines of longitude, you will rotate this first line around the y-axis.

Function

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

Create an empty positions and triangle arrays and return them in an object.

Seed Positions

Before generating the big list of vertex of positions all across the sphere, write code to generate just the single line of longitude that you drew earlier. Follow these steps:

Test that your seed points appear along a semicircle on the right side of the sphere by rendering as points and changing your return statement to this:

return {positions: seeds.flatMap(seed => seed.toArray()), triangles};

If that worked, great! If not, let’s talk.

Vertex Positions

The next task is to rotate the line of seed points all around the sphere to form the lines of longitude. Follow these steps to produce the full array of vertex positions:

When you restore the return statement and render as points, you should see the entire sphere covered.

Triangles

Stitching together the vertices of the sphere is just like stitching together the vertices of the cylinder, though the winding order may need to be adjusted. The poles are treated like the caps of the cylinder.