10.7 Surfaces
Wireframe models do not constitute surfaces. In fact, as lines are very thin and there is nothing between them, it is not possible to associate a wireframe model to a real surface.
If what we want is, in fact, to draw surfaces, then it is preferable to exploit the capabilities of Khepri for the creation of surfaces, which are implemented through the concept of polygonal meshes.
A polygon mesh is a set of polygonal surfaces, usually triangles and quadrilaterals, which define the shape of an object. In comparison to wireframe models, polygon meshes have the advantage of providing a more realistic visualization, for example, with the removal of invisible surfaces and the inclusion of shading. However, each polygonal surface of these polygonal meshes has zero thickness, therefore they are not true solids but only abstract representations of surfaces. Nevertheless, they can be subsequently transformed for creating solids, for example, using the Khepri’s function thicken that gives the surface a uniform thickness.
Khepri provides an operation for creating these polygonal meshes named surface_grid. This figure shows a surface representation of the Möbius strip generated from the following expression:
surface_grid(mobius_strip(0, 4*pi, 80, 0, 0.3, 10))
The Möbius strip represented by a surface.
We can now experiment variations of the Möbius strip, for example, by varying the strip’s width, as depicted in this figure.
Möbius strips with different widths. From left to right, the variation interval in \(v\) is \([0,\frac{1}{2}]\), \([0,1]\), \([0,2]\), and \([0,4]\).
10.7.1 Hyperbolic Paraboloid
To visualize another example, let us consider the hyperbolic paraboloid used by Félix Candela in the Chapel Lomas de Cuernavaca (illustrated in this figure). This surface can be described by its implicit equation
\[x^2-y^2-z=0\]
or, likewise, through its parametric representation:
\[\left\{ \begin{aligned} x(u,v)& = u\\ y(u,v)& = v\\ z(u,v)& = u^2 - v^2 \end{aligned}\right.\]
The translation to Julia is the following:
thicken(surface_grid(map_division((x, y) -> xyz(x, y, x*x-y*y),
-0.5,
1.3,
40,
-2,
2,
80)),
0.03)
In the previous expression, we adjusted the limits to approximate the surface to the Chapel Lomas de Cuernavaca, and we gave thickness to the surface through the function thicken. This figure shows the result of evaluating the above expression, where we eliminated the part that is underground.
An approximation of the Chapel Lomas de Cuernavaca.
10.7.2 Exercises 52
10.7.2.1 Question 190
Define a function that, with appropriate arguments, generates the surface shown in the following figure.
10.7.2.2 Question 191
Consider the following image:
Assume that the figure is centered at the origin and represented using an axonometric projection. Notice that the surface intersections with any plane parallel to the \(XZ\) plane or to the \(YZ\) plane produces a perfect sinusoid (though the produced sinusoids have different frequencies depending on the distance from the intersection plane to the origin). From these tips, try to figure out the parametric equations that originated the surface.
10.7.3 Helicoid
In section Space Curves we discussed the drawing of the helix. We will now discuss the surface that generalizes this curve: the helicoid.
The helicoid was first described in 1776 by Jean Baptiste Meusnier. An interesting feature of this surface is that for each point of the helicoid there is a helix that passes through it and is contained in the helicoid. Its parametric equations (in cylindrical coordinates) are:
\[\left\{ \begin{aligned} \rho(u,v)& =u\\ \phi(u,v)& =\alpha v\\ z(u,v)& =v \end{aligned}\right.\]
This figure shows two helicoids with different parameters, generated from the following fragment of program:
helicoid(p, a, u0, u1, n, v0, v1, m) =
map_division((u, v) -> p+vcyl(u, a*v, v), u0, u1, n, v0, v1, m)
surface_grid(helicoid(xyz(0, 0, 0), 1, 0, 1, 10, 0, 2*pi, 100))
surface_grid(helicoid(xyz(7, 0, 0), 3, 0, 5, 50, 0, 2*pi, 200))
Two helicoids with variation intervals in \(v\) of \([0,2\pi]\). The left helicoid has \(\alpha=1\) and variation interval in \(u\) of \([0,1]\), while the right one has \(\alpha=3\) and \(u \in [0,5]\).
10.7.4 Spring
A spring is another geometric figure that has affinities with a helix. Mathematically, the spring is the surface generated by a circle that sweeps along a helix. In simpler terms, a spring is a helix with thickness, i.e., a tube that wraps around an axis. If \(r_0\) is the radius of the tube, \(r_1\) the distance from the tube axis to the helix axis, \(\alpha\) the initial rotation angle of the spring and \(v_z\) the speed of the movement along the \(Z\) axis, the parametric equations of the spring, in cylindrical coordinates, are:
\[\left\{ \begin{aligned} \rho(u,v)& =r_1+r_0\cos u\\ \phi(u,v)& =\alpha+v\\ z(u,v)& = \frac{v_z v}{\pi} + r_0\sin u \end{aligned}\right.\]
The translation of the above definition into Julia is:
spring(p, a, r0, r1, vz, u0, u1, n, v0, v1, m) =
map_division((u, v) -> p+vcyl(r1+r0*cos(u), a+v, (vz*v)/pi+r0*sin(u)),
u0,
u1,
n,
v0,
v1,
m)
In this figure we can visualize a spring in its extension process. The springs have the same dimensions except the speed of the movement along the \(Z\) axis.
surface_grid(spring(xyz(0, 0, 0), 0, 1, 5, 1, 0, 2*pi, 50, 0, 3*2*pi, 150))
surface_grid(spring(xyz(20, 0, 0), 0, 1, 5, 2, 0, 2*pi, 50, 0, 3*2*pi, 150))
surface_grid(spring(xyz(40, 0, 0), 0, 1, 5, 4, 0, 2*pi, 50, 0, 3*2*pi, 150))
Three springs created with the parameters \(r_0=1\), \(r_1=5\), \(u \in [0, 2\pi]\) and \(v \in [0, 6\pi]\). From left to right, we have the speed \(vz \in \{1,2,4\}\).
10.7.5 Exercises 53
10.7.5.1 Question 192
The spring is the simplest shape that can be generated with the function spring. More elaborate shapes can be obtained either by parametrization or by composition. For example, by composing springs we can generate ropes. In this case, we can treat springs as strands that, wrapped around each other, constitute a rope.
Thus, a rope can be seen as a set of intertwined springs, with all the springs developing along the same axis but with an initial rotation angle and movement speed which allows them to be close to each other. The following figure contains two schemes that show the position of the springs in the case of a rope with four strands (on the left) and two strands (on the right). The rope can be generalized to any number of strands, until the lower limit of two strands.
Define the function rope that, when receiving the appropriate parameters, creates ropes. For example, consider the following expressions, whose evaluation produces the three ropes shown below, composed of two, three, and six strands:
rope(xyz(0, 0, 0), 2, 1, 3)
rope(xyz(10, 0, 0), 3, 1, 2)
rope(xyz(20, 0, 0), 6, 1, 1)
10.7.5.2 Question 193
A breather is a mathematical surface that characterizes a particular type of wave. This surface is illustrated in the figure below, and its parametric equations are the following:
\[\left\{ \begin{aligned} x(u,v)& = -u+\frac{2\left(1-a^2\right)\cosh(au)\sinh(au)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)} \\ y(u,v)& = \frac{2\sqrt{1-a^2}\cosh(au)\left(-\sqrt{1-a^2}\cos(v)\cos\left(\sqrt{1-a^2}v\right)-\sin(v)\sin\left(\sqrt{1-a^2}v\right)\right)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)} \\ z(u,v)& = \frac{2\sqrt{1-a^2}\cosh(au)\left(-\sqrt{1-a^2}\sin(v)\cos\left(\sqrt{1-a^2}v\right)+\cos(v)\sin\left(\sqrt{1-a^2}v\right)\right)}{a\left(\left(1-a^2\right)\cosh^2(au)+a^2\,\sin^2\left(\sqrt{1-a^2}v\right)\right)} \end{aligned}\right.\]
Note that, due to the periodicity of the trigonometric functions, we have that \(-2\pi\leq u \leq 2\pi\) and \(-12\pi\leq v \leq 12\pi\). The parameter \(a\) characterizes different surfaces and may vary between \(0\) and \(1\).
Define the function breather that draws the surface in question from a point \(P\), the parameter \(b\), and the variation limits and the number of points to consider along that variation for the parameters \(u\) and \(v\). For example, the previous figure was produced by evaluating the following expression:
surface_grid(breather(xyz(0, 0, 0), 0.4, -13.2, 13.2, 200, -37.4, 37.4, 200))
10.7.6 Seashells
Several authors argue that nature is a mathematical manifestation and justify that belief by the striking resemblance that some mathematical surfaces exhibit with natural shapes.
The Dini’s surface is one of such cases. The parametric equations that define it are:
\[\left\{ \begin{aligned} x(u,v)& =\cos(u)\sin(v)\\ y(u,v)& =\sin(u)\sin(v)\\ z(u,v)& =\cos(v)+\log(\tan(\frac{v}{2}))+a*u \end{aligned}\right.\]
where \(0\leq u\leq 2\pi\) and \(0\leq v\leq\pi\).
The translation of these equations into Julia is the following:
dini(p, a, u0, u1, n, v0, v1, m) =
map_division((u, v) -> p+vxyz(cos(u)*sin(v), sin(u)*sin(v), cos(v)+log(tan(v/2.0))+a*u),
u0,
u1,
n,
v0,
v1,
m)
The following invocations of this function show that it is possible, in fact, to simulate the natural shapes of certain types of seashells. The result is presented in this figure.
surface_grid(dini(xyz(0, 0, 0), 0.2, 0, 6*pi, 100, 0.1, pi*0.5, 100))
surface_grid(dini(xyz(3, 0, 0), 0.2, 0, 6*pi, 100, 0.1, pi*0.7, 100))
surface_grid(dini(xyz(6, 0, 0), 0.2, 0, 6*pi, 100, 0.1, pi*0.9, 100))
The Dini’s surface as a mathematical approximation of the shape of certain types of seashells.
Another example is the seashell surface mathematically defined in Julia as:
seashell(p, a, b, u0, u1, n, v0, v1, m) =
map_division((u, v) -> let e=exp(u/6.0/pi), c=cos(v/2.0)^2; p+vxyz(a*(1-e)*cos(u)*c, b*(e-1)*sin(u)*c, 1-exp(u/3.0/pi)-sin(v)+e*sin(v)) end,
u0,
u1,
n,
v0,
v1,
m)
From the previous function, we can experiment variations like the ones presented below, which generate the surfaces presented in this figure.
surface_grid(seashell(xyz(0, 0, 0), 1, 1, 0, 7*pi, 100, 0, 2*pi, 100))
surface_grid(seashell(xyz(7, 0, 0), 2, 2, 0, 7*pi, 100, 0, 2*pi, 100))
surface_grid(seashell(xyz(18, 0, 0), 3, 1, 0, 7*pi, 100, 0, 2*pi, 100))
A mathematical approximation of the shape of seashells.
10.7.7 Cylinders, Cones, and Spheres
Although we have illustrated the previous sections with relatively complex surfaces, in this section we will analyse surfaces that are comparatively much simpler. They will allow us to realize that the parametric construction of surfaces is relatively easy as long as we understand the impact of the variation of the independent parameters \(u\) and \(v\).
For example, the surface of a cylinder of radius \(r\) is characterized by the set of points that are at a fixed distance \(r\) of an axis and between a minimum height \(h_0\) and a maximum height \(h_1\) relative to that axis.
We will assume, for simplicity, that the cylinder axis is the \(Z\) axis, which will allow us to employ cylindrical coordinates \((\rho, \phi,z)\) to define the cylinder surface by fixing \(\rho=r\) and letting \(\phi\) vary between \(0\) and \(2\pi\) and \(z\) vary between \(h_0\) and \(h_1\). With \(\rho\) being fixed and the variables \(\phi\) and \(z\) being independent, we can define a parametric surface by using the parameters \(u\) and \(v\) to make the variation of \(\phi\) and \(z\).
More specifically, let us make \(\rho(u,v)=r\) and let \(\phi(u,v)=u\) and \(z(u,v)=v\) vary independently, respectively between \(u\in [0,2\pi]\) and \(v\in [h_0,h_1]\). Since \(\phi\) depends directly and exclusively on \(u\) and \(z\) depends directly and exclusively on \(v\), we can use these parameters directly in the function. This way, we are able to write a function that produces cylindrical coordinates from the value of the radius \(r\) and from the independent parameters \(\phi\) and \(z\).
The surface on the left of this figure shows a cylinder of radius \(1\) and with \(h_0=-1\) and \(h_1=1\), produced by the evaluation of following expression:
surface_grid(map_division((phi, z) -> cyl(1, phi, z), 0, 2*pi, 60, -1, 1, 20))
If, instead of fixing the radius \(\rho(phi,z)=r\), we vary it in function of the height \(z\), then the radius of the "cylinder" will be zero at the origin and will increase (in absolute value) as it moves away from the origin. The only difference to the previous case will thus be on the expression that creates the cylindrical coordinates, which will now be cyl(z, phi, z), reflecting the linear increase of the radius with \(z\). The resulting figure will not be a cylinder but a cone, which is presented in the surface on the center of this figure.
Finally, let us consider the description of a sphere of radius \(r\) in spherical coordinates \((\rho, \phi, \psi)\), which comes down to \(\rho=r\), with \(\phi\) varying between \(0\) and \(2\pi\) and \(\psi\) varying between \(0\) and \(\pi\). Once again, we need two independent variations, for which we can arbitrarily assign \(u\) to one and \(v\) to the another. Thus, let us make \(\rho(u,v)=r\), \(\phi(u,v)=u\) and \(\psi(u,v)=v\) with \(u\in [0,2\pi]\) and \(v\in [0,\pi]\). As it was done in the two previous examples, this association between \(\phi\) and \(\psi\) and, respectively, \(u\) and \(v\), allows us to write the function directly in terms of \(\phi\) and \(\psi\). Exemplifying with \(r=1\), we have:
surface_grid(map_division((phi, psi) -> sph(1, phi, psi),
0,
2*pi,
60,
0,
pi,
30))
The result is the surface on the right of this figure.
A cylinder, a cone and a sphere generated as parametric surfaces.
To see the impact that small changes in parameters can have on the shape of generated surfaces, we will make three variations on the shape of the sphere. The first variation is to add to the sphere’s radius a sinusoid with high frequency and low amplitude, in terms of the latitude \(\psi\), for example, by making \(\rho=1+\frac{\sin(20\psi)}{20}\). The result will be a formation of waves from pole to pole, as is visible in the surface on the left of this figure. If, on the other hand, we decide to make the sphere’s radius dependent on an identical sinusoid but in terms of \(\phi\), then the waves travel along the longitude, for example, from east to west. This effect is illustrated in the surface on the center of this figure. Finally, we can get a combined effect by making the radius simultaneously dependent on a sinusoid in terms of latitude and other sinusoid in terms of longitude, i.e., \(\rho=1+\frac{\sin(20\phi)}{20}+\frac{\sin(20\psi)}{20}\). The result is shown in the surface on the right of this figure.
Spheres whose radius, from left to right, is a function of the latitude, longitude, and both.
10.7.8 Exercises 54
10.7.8.1 Question 194
Consider the following ellipsoid:
An ellipsoid is characterized by the dimensions of its three orthogonal radii \(a\), \(b\) and \(c\). The parametric equations that define it are:
\[\left\{ \begin{aligned} x&=a\sin \psi \cos \phi\\ y&=b\sin \psi \sin \phi\\ z&=c\cos \psi \end{aligned}\right.\]
We have that \(-\frac{\pi}{2}\leq\phi\leq+\frac{\pi}{2}\) and \(-\pi\leq\psi\leq+\pi\).
Define the ellipsoid function that produces an ellipsoid from the three radii \(a\), \(b\), and \(c\), and from the number \(n\) of values to use along \(\phi\) and \(\psi\).