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 or 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:

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

Seed 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 code:

As you did with the sphere, check that your points look like a cross section of a capsule. Return just the seed points as a flat array with this return statement:

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

Render these as points.

Vertex Positions

Once you’ve confirmed that the seed points are in good order, generate the full positions array just as you did with the sphere. Restore your return statement, but continue to render the capsule as points. Do you see a capsule shape? If not, let’s talk!

Triangles

The triangles of a capsule are generated the same way as a sphere’s triangles. Render your capsule as a mesh. Does it look like a capsule? If not, let’s talk!