Note: this article is currently a WIP.
Some examples of surface visualisations
Here are a couple of versions of the Desmos save file with different cool pre-loaded plots:
Note: The below was submitted as my essay for the final assignment in the unit MTH3110 - differential geometry, at Monash University, in Semester 1, 2021. I’ve chosen to upload it here for those who may have seen my Desmos surface visualisation, and are interested in how I derived it! However, it assumes familiarity, especially near the end, with differential-geometric quantities such as maps of surfaces and their derivatives, and tangent spaces.
The explanation and geometry of the Desmos visualisation
Here is an interactive visualisation of surfaces on Desmos (a graphing website), made by me. It takes a (continuous) function , for some , and plots a projection of the graph of onto as a “wire-frame”; it can also take a parametrisation and plot a projection of its image in the plane. We discuss the algebra and geometry used in its construction, and some geometric properties of the projection map. Henceforth, let us assume that is open, is a smooth function, and that is a regular surface patch.
Projecting down to a plane
There are many ways to project , onto . However, a way to choose a sensible, well-behaved projection is to choose a plane through the origin (a linear subspace of ), and perform an orthogonal projection . Such a plane can be uniquely determined by using spherical coordinates. Consider an “observer” at , the unit sphere, and a standard map given by
here, respectively measure latitude and longitude. The unit vectors in (denoting possible directions from the origin) are precisely points on . Thus, we may take as the orthogonal complement of the span of .
A fact from differential geometry is that . If , then for any (where ), . In particular, , so . Conversely, a vector satisfies for all , so . This means that , and is normal to this tangent space.
Next, we consider the problem of projecting from into (and then into ). Given an orthonormal basis for that extends to a right-handed orthonormal basis of , where , consider the orthogonal projection . Since and is the identity, it follows that , , and . The map is linear, so its matrix with respect to the bases is
The geometry of this map is as follows: take a point . Then the coset , a line parallel to (thus orthogonal to ) passing through , is collapsed onto a point ; distinct parallel lines are collapsed to distinct points. This is an orthographic projection, where the axes are not foreshortened, that is, no length distortion due to perspective (see Figure~\mathbb Ref{fig:cylinder_perspective}).\footnote{See explanation of perspective and foreshortening in art.} Under this projection, we consider as the quotient , and cannot distinguish between points on the same line parallel to ; the map has rank and nullity .
\begin{figure}[p!] \centering \includegraphics[width=0.75\textwidth]{cylinderperspective.png} \caption{Plot of cylinder , with perspective , using the Desmos visualisation. Observe that there is no distortion due to perspective (i.e. _foreshortening) in the negative -direction.} \label{fig:cylinder_perspective} \end{figure}
Next, we consider the map that transforms points on into points in . Given our basis for , there is a natural sense in which can be thought of as pointing “right”, and as pointing “up”. This is described by , the linear isometry such that and . Letting , is simply the identity in coordinates : , the identity matrix.
Thus, our overall projection in the direction of would be given by , with matrix . However, we wish to express the matrix for with respect to the standard basis for . For this, we recall that the change-of-basis matrix from to is given by
Since is an orthonormal set, it follows that , so . It follows that the matrix for w.r.t. the bases of respectively is
Now, recall that there is a pair corresponding to . For simplicity, we will assume that , so that a suitable restriction of forms a regular chart for . We aim to find an orthonormal basis for by finding an orthonormal basis for . Note that forms a basis for , where
and
It is easy to check that these are orthogonal, so an orthonormal basis for is found by normalising these vectors, yielding
and
(It turns out that this also works when ; these span the tangent planes !) Note that we needed to take and , so that indeed .
In summary, for our perspective given by spherical coordinates (or equivalently ), the projection is given by
Visualising the surface in Desmos
If we wish to plot as the graph of , take . Then it reduces to the problem of plotting the image of , or at least its projection under . It would be useless (given limitations on Desmos) to present a filled-in outline—we would get a single splotch of colour (with jagged edges)! Instead, we use the idea that the domain is an open subset of \footnote{Desmos does not like strict inequalities, so they are often closed subsets instead, but we can ignore the boundary of .} and for fixed , we consider the curves in (for suitable open intervals ), where and , i.e. we fix the or coordinate, and let the other vary.
Consider a set of points , and the families of curves so-defined. Then for each of the curves (generically called ), we plot the image of , a curve in , under the projection , yielding two families (fixing , plotted in red) and (fixing , plotted in blue) of curves in , representing moving along using , with one input fixed. In the visualisation, we assume that is a box,\footnote{Technically , so we have a surface with boundary… but we can ignore this, as mentioned earlier.} and take curves of constant separation in in each direction. This creates the desired projection of the “wire-frame” on , and varying allows us to visualise the plot of from all angles, giving it a 3-dimensional effect.
Differential geometry of the projection: changing perspective
For spherical coordinates , let principal latitude denote such that there is with . We see that is a smooth function of , so the matrix (and projection) smoothly varies with :
and
Fixing a point , we can think of as a function , where the inputs are spherical coordinates ; let us call this map , . Then the directional derivatives of are given by , which is such that
So, if we change perspective from with velocity (i.e. increasing latitude by and longitude by ), the image of in moves with velocity , given explicitly above. Note that
this relates the directional derivatives of to the partial derivatives of .
Let us consider what happens to when we fix longitude and vary latitude . Taking and reveals a directional derivative of
in the direction. In particular, the -coordinate of does not change when only is changed, which makes sense since we view this as tilting the plane up or down. However, the -coordinate changes at a rate precisely equal to (since gives points on ). For nonzero , this is zero precisely when , or equivalently , is orthogonal to , the unit normal vector to the plane of projection . This holds when ; if , then this occurs for every latitude , but otherwise, is a circle on and intersects for precisely one latitude (modulo ). From this, we conclude that for principal latitudes , if , is always fixed when varying latitude (the directional derivative is zero); otherwise, there is precisely one latitude (or two, whence ) for which has velocity zero.
The above observations agree with a direct calculation: the curve in that traces for fixed longitude is
Now, let us consider what happens to when we fix latitude and vary longitude . Taking and gives a directional derivative of
in the direction. A direct calculation gives that the curve in that traces for fixed latitude is
the above directional derivative is simply . By trigonometry, we know that letting ,
this is clearly an ellipse (with period ) with axis lengths and , oriented negatively (clockwise) whenever principal latitude is positive (and positively if principal latitude is negative). Additionally, it has 4 vertices by Example 6.3 of chapter 4 (as long as and both axis lengths are nonzero); these vertices correspond to locations where the or -coordinate of is greatest or smallest. In summary, we see that for fixed latitude , projected points move in an elliptic shape (in a clockwise direction when viewed from with positive principal latitude); this agrees with the intuition that as we increase longitude , in order for the normal to the plane of projection to point “into the screen”, points must rotate clockwise about the projected -axis.
This concludes our analysis of the 2-dimensional visualisation of surfaces in on Desmos. We saw some commentary on the derivation of the projection, using some linear algebra. Then we proceeded to analyse how curves are represented in the plot, as a “wire-frame”, and finally, we analysed the effect of changing latitude and longitude on the positions of points in the plot, rounding off a treatment of the algebraic, analytic, and geometric properties of the visualisation.
Acknowledgements
I would like to acknowledge Dan Mathews for giving useful feedback (especially with respect to interpreting the effect on changing perspective on the position of points) and verifying the procedure used to derive the projection matrix. Errors in my initial formula for the projection were also corrected through discussion and testing with various members of the Maths @ Monash Discord server.