teaching machines

Capsule

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

Suppose you grabbed the North Pole, somehow, and I grabbed the South Pole. And then we pulled on the poles. What shape would we get? Earth would look like a pill. Maybe Saturn would swallow it to calm its storms. A more professional term for a pill is capsule. In this exercise, you will make a capsule.

Draw

On your paper, draw an arc that forms the bottom-right quarter-arc of a circle, starting at the south pole and moving counter-clockwise to the east pole. Draw a straight line upward. Then draw another quarter-arc, this time stopping at the pole. You should see the radial cross section of a capsule.

Draw five or more points along the arcs only. Do not include the poles.

As with the sphere, the points you have drawn represent a set of seed 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 generateCapsule. Have it accept these parameters:

• An integer nlatitudesPerHemisphere that specifies the number of lines of latitude that each hemisphere of the capsule has. The higher the number, the more spherical they will be.
• An integer nlongitudes that specifies the number of lines of longitude that the capsule has. The higher the number, the more spherical it will be.
• The radius of the capsule.
• The height of the capsule’s cylindrical body.

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

Positions

The seed positions of the capsule are very similar to the seed positions of the sphere, but the first half of them are pushed down and the second half are pushed up. That’s it. You’ll accomplish this by breaking the loop into two, one for each half. Follow these steps to adapt your sphere code:

• Note how the first parameter has a different meaning that it did with the sphere. You still need to know the total number of lines of latitude for your later code. Compute the total number of lines of latitude and store it in nlatitudes.
• All told, each quarter-arc is $\frac{\pi}{2}$ radians, and you want to break each into nlatitudesPerHemisphere slices. Compute the number of radians per slice and store it in radiansPerSlice.
• Adapt the loop to visit each latitude index in just one hemisphere.
• Range-map the latitude index so that it generates the seed points in just the southern hemisphere, whose interval is $[-\frac{\pi}{2} + \mathrm{radiansPerSlice}, 0]$.
• Tweak the y-coordinate calculation so that the seed points are pushed downward by half the cylinder’s height.
• Duplicate the loop.
• Modify the range-mapping of the second loop so that it generates the seed points in the northern hemisphere.
• Tweak the y-coordinate calculation so that the seed points are pushed upward by half the cylinder’s height.

When you render your capsule after making these changes, you should see a capsule-like shape. However, the poles are probably not be right. Adjust the pole positions just as you adjust the seed positions.