# teaching machines

## Parametric Puzzle

March 8, 2019 by . Filed under madeup, public.

Check out these these parametric equations:

$$\begin{array}{rll}x &=& \cos v \cdot \cos u \\y &=& \sin v \\z &=& \cos v \cdot \sin u\end{array}$$

Do you know what they do? They are most assuredly not magic. Here, let’s rename the variables, and you can try again:

$$\begin{array}{rll}x &=& \cos \textit{latitude} \cdot \cos \textit{longitude} \\y &=& \sin \textit{latitude} \\z &=& \cos \textit{latitude} \cdot \cos \textit{longitude}\end{array}$$

These equations generate coordinates across the surface of a sphere. It’s hard to tell, but they compactly apply polar coordinate conversions twice. Let’s derive them one step at a time.

First, let’s say the south pole has a latitude of -90 degrees, and the north pole has a latitude of +90 degrees. Let’s traverse this span of latitudes in 10-degree ticks:



scale 0.05, 0.1, 0.1

for latitude in -90..90 by 10
moveto 0, latitude
end

var mupDiv = jQuery('#mup_latitudes');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_latitudes').submit();

scale 0.05, 0.1, 0.1

for latitude in -90..90 by 10
moveto 0, latitude
end



I’ll be playing with the scale a bit in each step to ensure that we can see the structure of our generated shapes. Eventually we will remove the scaling.

At each latitude, we want to trace out a circle that goes around the sphere. A circle goes from 0 degrees to 360 degrees. Let’s unroll the circles until they are flat and traverse their flattened perimeters in 30-degree ticks:



scale 0.05, 0.1, 0.1

for latitude in -90..90 by 10
for longitude in 0..360 by 30
moveto longitude, latitude
end
dowel
end

var mupDiv = jQuery('#mup_longitudes');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_longitudes').submit();

scale 0.05, 0.1, 0.1

for latitude in -90..90 by 10
for longitude in 0..360 by 30
moveto longitude, latitude
end
dowel
end



Now let’s roll the circles back up—turning our plane into a cylinder. We use sine and cosine to turn the longitude angle into the x- and z-coordinates of each latitude ring:



scale 4, 0.05, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = cos longitude
z = sin longitude
moveto x, latitude, z
end
dowel
end

var mupDiv = jQuery('#mup_circles');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_circles').submit();

scale 4, 0.05, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = cos longitude
z = sin longitude
moveto x, latitude, z
end
dowel
end



For a cylinder to become a sphere, we must taper the ends. The rings at the north and south poles should have very small radii, and the radius of the equator should be large. What function is small at -90, large at 0, and small at 90? Cosine is! We use it directly to compute each ring’s radius:



scale 4, 0.05, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, latitude, z
end
dowel
end

var mupDiv = jQuery('#mup_tapered');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_tapered').submit();

scale 4, 0.05, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, latitude, z
end
dowel
end



That’s not exactly spherical. One issue is the nonuniform scaling. We are shrinking along the y-axis but growing along the x- and z-axes. Let’s making the scaling uniform:



scale 4, 4, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, latitude, z
end
dowel
end

var mupDiv = jQuery('#mup_nonuniform');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_nonuniform').submit();

scale 4, 4, 4

for latitude in -90..90 by 10
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, latitude, z
end
dowel
end



Oh, but that’s terrible. The other issue is that the y-coordinate of each ring is not correct. We are feeding in a number of degrees when a Cartesian coordinate is expected. The sine function converts our latitude to a y-coordinate on our latitude circle:



scale 4, 4, 4

for latitude in -90..90 by 10
y = sin latitude
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, y, z
end
end

var mupDiv = jQuery('#mup_wiresphere');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_wiresphere').submit();

scale 4, 4, 4

for latitude in -90..90 by 10
y = sin latitude
for longitude in 0..360 by 30
x = radius * cos longitude
z = radius * sin longitude
moveto x, y, z
end
end



The surface now looks spherical. And we effectively have the parametric equations that we saw above. We converted the longitudes to Cartesian coordinates to generate a ring for each latitude, and we converted the latitude to size and position each ring.

Let’s fill the sphere in with the surface solidifier:



for latitude in -90..90 by 10
y = sin latitude
for longitude in 0..360 by 15
x = radius * cos longitude
z = radius * sin longitude
moveto x, y, z
end
end

surface 25, 19

var mupDiv = jQuery('#mup_solidsphere');
mupDiv.closest('pre').replaceWith(mupDiv);
document.getElementById('mup_form_solidsphere').submit();

for latitude in -90..90 by 10