teaching machines

Star

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

Let’s regress back to two dimensions momentarily. Your next several shapes will start off flat. Later we will extend or extrude these flat shapes into the third dimension.

Your first challenge is to produce a five-pointed star.

Draw

On your paper, draw a star. Draw only the outer perimeter; do not let any lines cross its inner area. Consider the origin to be at the star’s center. Label the vertices in a counter-clockwise fashion, starting from 0.

Plot a circle that touches only the outer points of the star. What is its radius? Plot a circle that touches only the inner points of the star. What is its radius?

What is the angle between the x-axis and a line to the vertex whose index is 0? Between the x-axis and a line to the vertex whose index is 1? Label all the angles.

Function

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

Create your empty positions and triangles arrays. Return them in an object.

Positions

Generate the vertex positions by visiting all possible vertex indices with a loop. Range map each index to $[0, 2\pi]$ to produce an angle. Choose between the major and minor radius by asking whether the index is odd or even. Convert the radius and the angle to Cartesian coordinates, and append the resulting position to your array of positions, setting the z-coordinate to 0.

Render your scene using points. You should see the alternating pattern of the star’s vertices.

Triangles

Modify your drawing by adding lines between vertices so that the star is broken up into triangles. How many lines do you need? How many triangles are there?

Enumerate the triangles’ indices in your array of triangles.

Render your scene as a solid mesh. You should see a filled star.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *