Sphere demo

Draw a sphere in wireframe. Its longitude and latitude lines are to be visible on the front half of the sphere.

For the math we use a unit sphere centered on the origin. For now we use an orthographic projection \(\left<x,y,z\right> \mapsto \left<x,y\right>\). Additionally we give the transformation to pixel coordinates as \(\left<x,y\right> \mapsto \left<150x+200,-150y+200\right>\). Then \(x\) and \(y\) correspond to the natural directions of right and up, and \(z\) points out of the page.

The longitude lines are circles centered on the center of the sphere. The image of these circles under the orthographic projection is always an ellipse centered on the origin of the screen space. For each ellipse we only draw the half in front of the \(xy\)-plane. It remains to calculate the width and the angle of each elliptical image. To determine this we compute the position of each longitudinal circle.

We compute a sequence of points on the equator and use those as the normal vectors for the longitudinal circles. Recall that points on a circle can be parameterized by \((\cos(\theta), \sin(\theta))\). Similarly, points on the equator can be computed as \(\cos(\theta)\vec{v_1} + \sin(\theta)\vec{v_2}\) for some perpendicular \(\vec{v_1}\) and \(\vec{v_2}\) on the equator. (what two vectors?) (how to turn that into an ellipse?)

The latitude lines are circles on the surface of the sphere centered on points on the axis. We only draw the parts in front of the \(xy\)-plane. Rather than computing the intersections of each latitude circle with the \(xy\) plane, we start by considering each point on the \(xy\)-plane and finding the latitude circle it intersects. Note that the latitude circles lie in planes perpendicular to the axis. Then the latitude circle containing a given point is centered on the projection of that point onto the axis.