# teaching machines

## Swirl Ball

A few months back, I saw a 2D illustration in Mathographics that was begging to be expanded into 3D.

A spiral from Robert Dixon’s Mathographics. It wanted to be 3D.

Here’s my “spin” on that expansion. First, I started with a simple circle.

Only two shapes matter: triangles and circles.

interDelta = 5

for azimuth through 360 by interDelta
x = radius * cos azimuth
y = radius * sin azimuth
moveto x, y, 0
end


I anticipated doing a lot of plotting of polar coordinates, so I factored out a helper function.

interDelta = 5

to polarto radius degrees
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, 0
end

for azimuth through 360 by interDelta
end

Next up was shaping the circle into a lobed, flowery shape. I fed the angle into the sine function to get an undulating radius as I traversed the circle’s perimeter.

The circle bloomed into a flower. It was a sine.

interDelta = 5
nlobes = 7

to polarto radius degrees
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, 0
end

for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
end


Next I wanted a stack of flowers. However, I like abstraction a lot, so I made a flower function first.

interDelta = 5
nlobes = 7

to polarto radius degrees
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, 0
end

to flower
for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
end
end

flower

I wanted the stack of flowers eventually to shape themselves into a ball, so it made sense to me to walk the altitudes from -90 to 90. At the extremes -90 and 90, I wanted more flowers because the radius changes faster at the ends and I needed to capture the detail. So, I fed the azimuth angle into another sine function to calculate a flower slice’s z-coordinate.

A stack of flowers, with more detail at the ends.

interDelta = 15
nlobes = 7

to polarto radius degrees z
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, z
end

to flower altitude
for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
z = maxRadius * sin altitude
polarto azimuthRadius, azimuth, z
end
end

for altitude in -90..90 by interDelta
flower altitude
end

Now I shrunk the flowers according to the altitude. At the extremes -90 and 90, I wanted the flowers to be small. At 0, I wanted the flower to be its full size. Cosine to the rescue!

The flower stack, with its slices shrunk according to their altitude.

interDelta = 15
nlobes = 7

to polarto radius degrees z
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, z
end

to flower altitude
for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
altitudeRadius = cos altitude
z = maxRadius * sin altitude
end
end

for altitude in -90..90 by interDelta
flower altitude
end

Then it was time make a solid. I added a surface solidifier. I stopped interDelta + 1 times going through the azimuth angles and intraDelta + 1 times going through the altitudinal angles.

The flower stack made into a solid.

interDelta = 5
nlobes = 7

to polarto radius degrees z
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, z
end

to flower altitude
for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
altitudeRadius = cos altitude
z = maxRadius * sin altitude
end
end

for altitude in -90..90 by interDelta
flower altitude
end

surface 360 / interDelta + 1, 180 / intraDelta + 1

Finally, I added a little twist between flower slices.

A twisted flower stack. Dream accomplished.

interDelta = 5
nlobes = 7

to polarto radius degrees z
x = radius * cos degrees
y = radius * sin degrees
moveto x, y, z
end

to flower altitude
for azimuth through 360 by interDelta
azimuthRadius = minRadius + sin (azimuth * nlobes)
altitudeRadius = cos altitude
z = maxRadius * sin altitude
end
end

for altitude in -90..90 by interDelta
flower altitude
rotate 0, 0, 1, 3
end

surface 360 / interDelta + 1, 180 / intraDelta + 1

Missing from this process are the steps where I made a bunch of mistakes.

I think cornflower blue is pretty.