Costa's minimal surface is one of those amazing mathematical objects that look good when rendered with PovRay. While it is not too hard to find triangulations of Costa's surface suitable for the PovRay triangle
element, triangulations with surface normals are not that easy to come by. But these are needed for the smooth_triangle
element which makes Phong shading possible.
In the service of humanity, and especially my students who wanted to render the surface, I provide here the code to triangulate and compute the normals to Costa's minimal surface. The code is written in Mathematica, which is not freely accessible. Therefore, for convenience the repository also contains certain files generated by Mathematica:
-
a CSV file
costa.csv
with ready-made triangulations and surface normals, with a Python scriptcvs-to-mesh2.py
for converting the CSV file to a partial PovRay
mesh2
element, -
a PDF file
Costa.pdf
, the PDF export ofCosta.nb
, so you can see how I did it.
To generate a picture using PovRay, proceed as follows:
-
Run
Costa.nb
with Mathematica and use theCostaCSV
function to generate a CSV file which contains the triangulation and normals, saycosta.csv
. -
Use
csv-to-mesh2.py
to convert the CSV file to a partial PovRaymesh2
object. -
Include the partial
mesh2
object into your PovRay file, as demonstrated incosta.pov
. -
Generate
costa.png
with something likepovray costa.pov +A +J +W1024 +H1024
The Mathematica function CostaCSV
outputs a CSV file in a format that is suitable for
generating a PovRay mesh2
object:
-
The first line lists the parameters that were used with in the call to
CostaCSV
:r1,r2,k,l,m,n
Their meaning is as follows:
* `r1` and `r2` are the radii which determine the upper and middle radius of the surface
* `k`, `l`, `m`, `n` specify the number of vertices used in the triangulation, specifically:
`k` for the inner points, `l` for the edges, `m` for one rim and `n` for the other rim.
In general, larger numbers mean a finer mesh.
-
The triangulation points, where
N
is the number of points, followed by one point per line:N x1,y1,z1 x2,y2,z2 ... xN,yN,zN
-
The normalized normals to the surface at respective triangulation points, where
N
is the number of points (and equal to theN
above):N u1,v1,w1 u2,v2,w2 ... uN,vN,wN
-
The triangles that form the surface triangulation, where
M
is their numbers and the indices refer to the points above.M i1,j1,k1 i2,j2,k2 ... iM,jM,kM
The file costa.pov
generates the following picture: