Você está na página 1de 69

POV-Ray for Geometry

J.C. Sifre, Institut Mathmatique de Bourgogne


July 2, 2014

Contents
1 Use of POV-Ray
1.1 Editor and messages window . . . . . . . . . . . . . .
1.2 First view : axes . . . . . . . . . . . . . . . . . . . . .
1.3 Camera for a conic perspective view . . . . . . . . . .
1.3.1 Location and look_at . . . . . . . . . . . . . . .
1.3.2 Adjustment of the objective : up, right, direction
1.3.3 Moving the camera : translate et rotate . . . . .
1.4 Camera for an orthographic perspective view . . . . . .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

2 Geometric objects
2.1 Elementary solids . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Curve drawing . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Tori and Hlder norm balls . . . . . . . . . . . . . . . . . . . .
2.4 Constructive Solid Gemometry . . . . . . . . . . . . . . . . . .
2.4.1 Intersection, union, difference . . . . . . . . . . . . . . .
2.4.2 Color or texture in CGS . . . . . . . . . . . . . . . . . .
2.4.3 Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Surfaces based on a curve . . . . . . . . . . . . . . . . . . . . .
2.5.1 Revolution surfaces, cylinders, canal surfaces . . . . . .
2.5.2 Linear and quadratic splines . . . . . . . . . . . . . . . .
2.5.3 Elementary arc for pour cubic, bezier and natural splines
2.5.4 POV-Ray cubic spline . . . . . . . . . . . . . . . . . . .
2.5.5 POV-Ray bezier spline . . . . . . . . . . . . . . . . . . .
2.5.6 POV-Ray cubic spline with variable steps . . . . . . . .
2.5.7 POV-Ray natural spline (with variable steps) . . . . . .
2.5.8 Drawing a lathe . . . . . . . . . . . . . . . . . . . . . . .
2.5.9 Drawing a prism . . . . . . . . . . . . . . . . . . . . . .
2.5.10 Drawing a canal surface . . . . . . . . . . . . . . . . . .
2.5.11 Using a canal surface to draw a curve . . . . . . . . . . .
3

.
.
.
.
.
.
.

11
11
14
15
16
18
21
24

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

27
27
28
29
31
31
33
35
35
36
38
39
40
41
43
43
43
45
47
49

CONTENTS

2.6

2.7

2.8

2.9

2.5.12 Drawing parametrized spline curves


Bezier bicubic surfaces . . . . . . . . . . . .
2.6.1 Bicubic functions . . . . . . . . . . .
2.6.2 POV-Ray bicubic patches . . . . . .
2.6.3 Joining bicubic patches . . . . . . .
Isosurfaces . . . . . . . . . . . . . . . . . .
2.7.1 Volume by isosurface . . . . . . . .
2.7.2 Surface by isosurface . . . . . . . .
Algebraic surfaces . . . . . . . . . . . . . .
2.8.1 Surface with poly and polynomial . .
2.8.2 Singular surface with poly . . . . . .
2.8.3 Complete intersection with poly . . .
Parametric surfaces . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

49
51
51
52
53
55
55
56
58
58
61
63
65

Introduction
We intend to describe the use of POV-Ray (Persistence of Vision), a ray
tracing software, strictly for mathematical (and more precisely 3-dimensional
geometry) illustration on a screen , as for beamer, or for printed publication. This
implies a drastic selection of the topics, since we dont need to give an image of
the garden of our dreams or a cartoon scene of Star Wars.
Mathematical softwares like Maple and Mathematica represent parametrized
curves by a succession of little segments, and parametrized surfaces by juxtaposition and superposition of small triangles. The hidden parts of objects are precisely
determined by painters algorithm, see figure (1).

Figure 1: Hidden parts


We call this representation vector graphics, since the elementary objects are
segments and triangles.
POV-Ray is a ray tracing software. To represent an object, we have to choose
light sources from which start millions of light rays. These light rays bounce from
or go through surfaces, these surface may absorb some wave lengths. We have
to choose a position of the observer (the camera) and of the screen. The light
rays which, after having travelled in the scene, meets the screen, while going in
direction of the camera, gives a coloured point on the screen, like in the classical
5

CONTENTS

corpuscular theory of vision (and photography).


As it is easy to determine the intersection of a line and a surface defined by an
equation, by putting a parametrization of the line in an equation of the surface, we
guess that POV-Ray is more adapted to representation of surface defined by an
equation that that of a parametrized surface. Indeed, in this last case, the software
has essentially to determine, for each little triangle of the triangulation whether
it cuts the light ray or not. For each light ray, thousands of intersections must be
separately tested. POV-Ray can do that, but very slowly.
Moreover, representing a surface defined by an equation f .x; y; z/ D 0 is not
easy for vector graphics. The software begins by approximating the surface by
a triangulated one, essentially by separating the points of a network where the
function f is positive and is negative, after which it has to find a triangulated
surface covering approximately the no-mans land between the two (discrete)
domains. Generally, the singularities of the surface are badly represented, and
even not seen at all.
An interesting example is Hadamards double hyperboloid, of equation
..x

2/2 C z 2

y2

1/..x C 2/2 C z 2

y2

1/

2 D 0;

whose principal connected component is a hyperboloid with two holes. For


a recent version of Maple, the function implicitplot3d needs a very big grid not
to show discontinuities of the surface near the two secondary components while
POV-Ray representation (with convenient light and transparency) shows very
well the shape, and the proximity of the three regular components, see figure (2).
Other more striking examples will appear later.
In this sense, ray-tracing is in some way dual of vector graphics, since it
prefers to use equations than parametrizations of objects. The reason is purely
dimensional. For POV-Ray, everything must be a surface or a volume. The lines
do not exist : generically two lines (the light ray and the line to be represented) do
not cut ! The segments should be represented by fine cylinders, the curves will be
pieces of fines cylinders : for visual continuity, these cylinders should be joined
smoothly by spherical kneecaps.
Photo-realism has a price. There is no image without light. In the environment
of the picture, any zone without a defined color will be black (as sky at night).
The camera (i.e. the observer) must be precisely defined, otherwise there is no
image.
Transparency (up to caustics) is nice in POV-Ray. But there is a trap. When
objects are transparent and reflect light like glass, any object in the scene may
reflect on them, and, for a mathematician who has to read geometric properties

CONTENTS

Figure 2: Hadamard hyperboloid with Maple and with POV-Ray (Hadamardtwo-holes-POV-Ray.pov)


on the objects, this may introduce unpleasant artefacts. So our theatre should not
be baroque ! Prefer Becket to Goldoni !
We will even have sometimes to forget some properties of objects. For
instance, light implies shadows, which are not easy to make as smooth as in real
life. Sometimes the shadows make some details hard to read (if we do not want to
multiply the light sources), and POV-Ray allows to forget the shadows (but keep
intensity of light). Augmented reality will sometimes be synonym of heating with
it.
Finally, a great quality of POV-Ray is that we can control everything, since
everything is coded. The language is a layer over C++. The object-oriented
properties of C++ are widely used by the authors of POV-Ray, to collect common
properties of objects of very different origin and construction. But object-oriented
programming may be essentially ignored by the common user, I mean the author
of these lines, and any mathematician. A C++ programmer will understand
immediately some choices of POV-Ray, but it is not necessary to know C++,
since POV-Rays authors have partly bridled C++ for users comfort (essentially
to avoid type declarations, since the strictly geometric and optical context allows
POV-RAy to guess many types).
For some rather complex objects, it may be useful to prepare POV-Rays work
in another application, for instance Mathematica of Maple, when some computer
algebra is needed. We shall give some important examples.
Of course, all the POV-Ray sources of all the pictures of this document are

CONTENTS

given together with it, and we recommend warmly their reading.


The principal source is the manual included as Help in the software, but
it incomplete and sometimes ambiguous (even in POV-Ray 3.7). Some other
sources may be found on Internet. A good collection of examples of scenes for
advanced user is Oyonale/POV-Ray objects and scripts. At a basic level (but
with pedagogical purpose), there is also the well known site for Lohmuller. Some
others (in french) are outdated. The movie Dimensions is made with POV-Ray,
and free on Internet. You may find many mathematical illustrations in the site of
Konrad Polthier.
The absolute reference is the complete source, provided here in the file
povray-3.7-stable.zip. The details of the *.h and *.CPP files which contain
information on geometry and treatment of light (written in C++) are in the subdirectory source/backend. For instance, the parameters for determining camera
and screen are in source/backend/camera.h. Hard to read, but it is possible to
find there an answer to a local question.
In this preliminary document, we describe POV-Rays principal techniques to
draw basic objets, surfaces and even curves.
In the lectures, we shall first review and comment them.
(The following material is not in these preliminary notes.)
Then, we shall review the most useful directives of C++ bridled by POVRay : it gives tools for programming repetitive actions.
After that, we show how to use Mathematica and Maple for some important
calculations to prepare POVRays rendering in cases where a formal calculus
software is necessary.
Finally, we present the most interesting contribution of POV-Ray to geometry :
the use of transparency to show hidden parts of surfaces or intersection (or even
contact) of surfaces.
Here is a little gallery of some geometric objects enhanced by POV-Ray
transparency, see figures (3) and (4) which were made for [La-Si], [La-Si2],
[La-Si-Dru-Gar-Pa].
1) The segments delimited on the rulings of an hyperboloid by a secant sphere.
2) A DAlembert cyclide, circled by two families of circles, any circle of the
first family being cospherical to any cercle of the second.
3) A parabolic Dupin cyclide tangent along a curve to a cylinder.
4) Three contacts of two generic Dupin cyclides imply a common contact
curve.

CONTENTS

Figure 3: Hyperboloid generatrices cut by a sphere and DAlembert cyclide


(Generatrices-cut-by-Sphere.pov and DAlembert-Cyclide.pov)

Figure 4: Contacts between Dupin cyclides (Parabolic-Tangent-Cyclides.pov


and Tritangent-Dupin-Cyclides.pov)

10

CONTENTS

Chapter 1
Use of POV-Ray
1.1

Editor and messages window

The version of POV-Ray in use is 3.7 (stable, and essentially definitive).


You open POV-Ray editor by clicking on POV-Ray icon, or on a file of type
*.pov in Windows explorer. In the editor, to may work simultaneously on several
images, each in an editor window. To close one of them, you type Ctrl W or
select (in the upper bar) Window/Close window. If your editor is already opened,
and you want to open a new POV file by clicking on it in Windows explorer, you
may find this message (see figure (1.1) :

Figure 1.1: Editor window already opened


The problem is solved by clicking as on the picture.
Editor fonts are very small, and you enlarge them by travelling through the
menus
Options/Editor Window/Editor Preferences (Color, Keystrokes, etc.)
but for a shorter access, type Alt Enter (together). It takes you to a window where
you can choose font size (figure (1.2). Dont forget to quit by OK.
11

CHAPTER 1. USE OF POV-RAY

12

Figure 1.2: Choice of font size


Once the code written, you launch image making by clicking on the Run
button on the upper bar. You can interrupt at any time a too low execution by
clicking on Pause.
While working, POVay writes a work report in a Message Window at the
bottom of the screen. (figure 1.3) : which disappears when the image is drawn.

Figure 1.3: Message window


his window may be opened (and closed) by Alt M even after drawing the image.
It is important for debugging. We can ask, for instance, the display of the value of
a variable A during execution at a specified moment of this execution. It suffices
to write
#warning str(A, L, P)

in the code. Then, at that moment of execution, in the Message Window, will
appear the value of A, with P decimals, written in characters of size at least L.

1.1. EDITOR AND MESSAGES WINDOW

13

Then the value of A will be given, preceded by the warning : Parse warning :
. You can write also some text to identify the variable :
#warning concat("A = ", str(A, L, P))

Then you will see


#Parse warning : A = 1.35

if the value of A is 1:35 at that moment.


You can also enlarge the characters in the Message window by clicking on
Options/Message Window/Text font, in the same way as above.
Sometimes, by mouse lapsus (!), you may loose text-colouring (necessary
for coding confort). You find it by going to Options/Editor Window/Color
Scheme/custom, which opens a window (figure 1.4), where you choose POVRay language.

Figure 1.4: Choice of text colouring


POV-Ray is case sensitive.
Some words are directives of the language (in fact C++) and are preceded
by # , like #declare . The parameters of directives (functionss, procedures,
macros) are generally put between braces.
Comments on a line are preceded by // . Comments on several lines should
be preceded by /* and followed by */ .

CHAPTER 1. USE OF POV-RAY

14
You include a file by
#include "[file name]"

for example the very frequent #include color.inc


The numbers are integers or of type float. The vectors of coordinates a, b, c
are denoted by <a,b,c> . If the name given to the vector is V , its coordinates are
V:x, V:y, V:z. In particular, x, y, z are reserved words for POV-Ray.

1.2

First view : axes

As said in the introduction we need :


 a camera, called camera ,
 one or several light source light_source ,
 a background where this light is reflected, otherwise the background will
be black (which is possible and sometime interesting on a screen, but has to be
avoided in print).
The simplest possible background for a mathematical picture which you want
to convert in an EPS file (for TEXand publication) is :
background {White}

You can also define a sky_sphere , and perhaps you want to place your
object in relation to a sort of floor, with the code plane . It will be easily seen
latter.
A first surprise is the choice of coordinates in POV-Ray. Let < a; b; c > be a
vector. For the coordinates in this order,
 the first, the abscissa, a is horizontal from left to right ;
 the second b is vertical from bottom to top ;
 the third c is horizontal from < 0; 0; 0 > to horizon.
Thus, the usual y-coordinate in mathematics is the z-coordinate in POV-Ray,
and the usal z-coordinate in mathematics is the y coordinate in POV-Ray.
The reason of this choice in POV-Ray is logical : the natural plane of
reference is frontal. However, the plane of the image produced by POV-Ray will
be on a screen orthogonal to direction of vision, and this direction may be any
vector in R3 .

1.3. CAMERA FOR A CONIC PERSPECTIVE VIEW

15

An important point : the letters x, y, z are strictly reserved word of POV-Ray.


They denote respectively the vectors :
x D < 1; 0; 0 >;

y D < 0; 1; 0 >;

z D < 0; 0; 1 >

and nothing else. Then 3  x, is < 3; 0; 0 >.


The basic axes of POV-Ray are represented on figure (1.5), produced by the
joined file POV-unit-vectors.pov). The tiles of the floor have unit size, to give

Figure 1.5: POV-Ray unit vectors (POV-Unit-Vectors.pov)


a precise idea of size of objects. We keep this habit in the sequel, to help vision
of examples, which does not mean that mathematical scenes should have a check
floor !

1.3

Camera for a conic perspective view

In this section, we describe conic perspective, that is with vanishing point


(the Renaissance perspective of Brunelleschi). Latter, we shall consider briefly
orthographic perspective, which is an orthogonal projection. They ave not the
same use, and for photo-realism, the first is more natural.
We have to place two linked up elements, which must form in mind a solid :
the camera and the screen of intersection of the light rays arriving to the camera,
and which contains the final image. Both are determined in POV-Ray under the
same name camera . The principal parameter for its determination ar :

CHAPTER 1. USE OF POV-RAY

16

location, up, right, direction, look_at, rotate, translate

For instance, we may write :


camera{location<5,2,-4> up<0,1,0> right<4/3,0,0>
direction<0,0,1> look_at<0,0,-2>
rotate<30,0,90> translate<0,2,3>}

For our purpose (geometry) it would be better to introduce them in the


preceding order, we shall see why.

1.3.1

Location and look_at

To put the center of the objective of the camera at the point ! D < a; b; c >,
we write
location<a,b,c>

The axis of the camera will join the point ! to the point  D < a0 ; b 0; c 0 > (in
absolute coordinates), keeping horizon parallel to the original one, when we write
look_at<a,b,c>

To understand what happens, let us associate to the camera a moving frame


of origin ! and of basis vectors X , Y , Z. In any move, the direction of the
look (or objective) is in the direction of Z, the vertical of the machine itself is
Y , and the line joining the two hands of the cameraman is X . Then, specifying
look_at<a,b,c> means for the cameraman the following move : from the
original position where X D x, Y D y, Z D z (but ! has already been changed
by location ), and without changing !, he first turns around the Y D y axis so
as to find the point  in the new vertical plane X D 0 ; after which he turns the
objective in this vertical plane (keeping ! fixed) to put the point  at the middle
of the image.
If the angle between the horizontal plane and the new Z is the objective
latitude , and the angle between the initial axis x and the new horizontal X is
the objective longitude ', the move of the camera is in fact a rotation of  around
the initial x axis followed by a rotation of ' around the initial y axis (which is

1.3. CAMERA FOR A CONIC PERSPECTIVE VIEW

17

less natural for a human cameraman..). We must keep in mind that for POV-Ray,
the angles are counted with the left hand rule, that is the sense opposed to the
trigonometric one. It means that if you use your left thumb as axis, when you close
the other fingers, they turn in the positive direction. It gives, in mathematical
notations with vertical vectors and square matrices (but POV-Ray coordinates) :
0
10
1
cos ' 0 sin '
1
0
0

X Y Z D@ 0
1
0 A @0 cos 
sin  A
sin ' 0 cos '
0 sin  cos 

The sign of sin  is due to the fact that the first coordinate in the latitude rotation
is z and not y, and the left hand convention. This calculus has been given to
prevent some errors due to mathematical habits. It gives :
8

< X D < cos '; 0; sin ' >


(1.1)
Y D < sin ' sin ; cos ; cos ' sin  >

:
Z D < sin ' cos ; sin ; cos ' cos  > :

This vector should be u=kuk, where u D < a0 a; b 0 b; c 0 c >. Then ' is


detemined by the first and third coordinates of a0 a, and  is determined by the
respective second coordinates of b 0 b and c 0 c :
(
 D Arcsin.Z2 /
(1.2)
' D Arctg.Z1 =Z3/:
The norm of u is not used here.
An example for camera adjustments will be the following simple objects. On
the floor (with one unit check) put at one unit down :
 a yellow unit cube put on the floor its upper face being at the y zero level) ;
 put on four brown legs (of height one unit) a unit blue cube ;
 in front of then, a green cone with unit height, see figure (1.6).
With the basic code
camera{location<0,0,-4> look_at<0,0,0>
}

we see figure (1.7) on the left. The right picture shows where is the camera
for this result. The following code
camera{location<0,0,-4> look_at<1,-1,0>
}

18

CHAPTER 1. USE OF POV-RAY

Figure 1.6: Two cubes and a cone (Cubes-cone.pov)

Figure 1.7: Cubes and cone viewed from the camera, and together with it
(Cubes-cone1.pov and Camera-Cubes-Cone1.pov)
gives figure (1.8) where the camera looks at the foot of the right leg of the blue
cube.

1.3.2

Adjustment of the objective : up, right, direction

Now, we have to determine the position of the rectangular screen which picks
up the light rays in their last travel in direction of the camera. The light rays in
direction of the observer but not cutting this rectangle are not considered.
This rectangle (the screen) will be centered on the Z axis at a distance which
we (for this document) denote by d of the point !. With respect to the moving
frame .!; X; Y; Z/, the X dimension which we denote by W and the Y dimension

1.3. CAMERA FOR A CONIC PERSPECTIVE VIEW

19

Figure 1.8: When the cameraman looks at a foot of a leg (Cubes-cone2.pov and
Camera-Cubes-Cone2.pov)

which we denote by H . For POV-Ray, this will be specified by the code


up H*y
right W*x
direction d*z

The letters H , L d of our mathematical description should be replaced by the


numerical values chosen by the user. You must be advised that the total height of
the screen is H , its total width is L. Then, in the moving frame, the extremities
of the screen have (POV-Ray) coordinates :
< W=2; H=2; d >; < W=2; H=2; d >;
< W=2; H=2; d >; < W=2; H=2; d > :

In fact, X , Y , Z may be replaced by other vectors, but it will not interest us


for our purpose. We pass to the examples.
The code
camera { location <0,0,-4> look_at <0,0,0>
up 1*y right 4/3*x
direction 1*z

gives figure (1.9). The code

CHAPTER 1. USE OF POV-RAY

20

Figure 1.9: d D 1 (Cubes-cone3.pov and Camera-Cubes-Cone3.pov)


camera { location <0,0,-4> look_at <0,0,0>
up 1*y right 4/3*x
direction 2*z

gives figure (1.10).

Figure 1.10: d D 2 (Cubes-cone4.pov and Camera-Cubes-Cone4.pov)


Even if the code contains the reserved word x, y, z in low case, they make
reference to the moving frame vectors X , Y , Z as can be seen in the following
example. The code
camera { location <0,0,-4> look_at <1,-1,0>
up 1*y right 4/3*x
direction 2*z

gives figure (1.11). As we see a little part of the blue cube and of the horizon,

1.3. CAMERA FOR A CONIC PERSPECTIVE VIEW

21

Figure 1.11: d D 2 and look at < 1; 1; 0 > (Cubes-cone5.pov and CameraCubes-Cone5.pov)


we notice that the scaling of the screen is not related to the distance of ! to  but
only the number d defined above. The distance from
p the camera to the screen is
exactly 2, which is smaller than half the distance 17 from ! to .

1.3.3

Moving the camera : translate et rotate

Suppose now that you want to turn your camera around its view direction with
an angle, say 45 degrees, not for fun but for some geometric reason (for instance
in an animation). POV-Rays coding of rotations does not give immediately the
answer. Of course, it offers a procedure : rotate . But its working is particular.
If, in the declaration
camera { location ... look_at ...
up ... right ...
direction ...

you put a geometric transformation such as rotate<..., ..., ...>


translate<..., ..., ...> , it will be executed after the code
location, look_at, up, right, direction

or

wherever you write the transformation in the camera{...} code. In fact it


transforms the bloc camera-screen just defined as a solid, and the transformations
are executed with respect to the initial frame .O; x; y; z/. In particular, the location
of the camera will not be preserved. Moreover, we must know how the rotation is
carried out.
For POV-Ray, an object (like the camera-screen) is rotated by a code like

CHAPTER 1. USE OF POV-RAY

22

object{... (construction of the geometric object)


rotate <alpha, beta, gamma>
}

where the object is :

 rotated around the x-axis with an angle alpha (left hand convention) ;

 rotated around the y-axis with an angle beta (left hand convention) ;

 rotated around the z-axis with an angle gamma (left hand convention).

To describe concretely what happens, suppose the angles are between 0 and
90 degrees, and you stand up, looking in the z-direction (POV-Rays horizon),
with your object in front of you. The first rotation is natural. You lean the object
with an angle . After that, keeping it at hand, you turn yourself around the y-axis
with an angle (in the right direction, left hand rule). But the last movement is
physically very unnatural : you should turn around the z-axis (from which you
have turned away), with a determined angle . You guess that no cameraman
has in mind these angular parameters when he executes the instructions of his
director, even in a complicated S.F. movie !

So, if you need to turn the camera naturally around its view axis (from a
position where horizon is horizontal) it is better to write the description of the
pair camera-screen in another way. Here is a solution, which we shall explain.

1.3. CAMERA FOR A CONIC PERSPECTIVE VIEW

23

#declare ScreenDirection = 2;
#declare ScreenHeight = 1;
#declare ScreenWidth = 4/3;
#declare
#declare
#declare
#declare
#declare

CameraLocation = <0,0,-4>;
CameraLookAt = <1,-1,0>;
U = CameraLookAt-CameraLocation;
NU = sqrt(pow(U.x,2)+pow(U.y,2)+pow(U.z,2));
Un = U/NU;

#declare rhau = 45;


#declare theta = - asin(Un.y)*180/pi;
#declare phi = atan(Un.x/Un.z)*180/pi;
// Camera and screen
camera {location <0, 0, 0> look_at z
up H*y
right W*x
direction ScreenDirection*z
rotate rhau*z
rotate theta*x
rotate phi*y
translate CameraLocation
}

Let ! be the desired location of the camera,  the look_at point, H the
screen height, W its width, ScreenDirection the camera-screen distance, and 
the angle (in the left hand convention) of rotation you want for your camera.
We first calculate the vision vector u D  !. We let the parameters
location and look_at at their initial value (see the code above). We choose
the up , right , and direction parameters. The normed vision vector is u=kuk.
This defines a latitude  (oriented with left hand convention, i.e. head down),
and a longitude ' (from left to right). Then we execute in this order a rotation
of  (translated in degrees) around the z axis (which leans the camera on the
left), followed by a rotation of  around the x axis (we lean our camera) and a
rotation of ' around the y-axis (from left to right), where the angles  and ' are
determined from u=kuk by the formulas (1.2). All the angles must be in degrees.
Finally, we translate the camera to the desired point !.

CHAPTER 1. USE OF POV-RAY

24

Thus, we dont use the parameters location and look_at , but it is due to
POV-Rays conventions for rotations for which the authors have chosen anything
else than Euler angles... Starting from cameras position of figure (1.11), and

Figure 1.12: d D 2, look at < 1; 1; 0 > and turn of 45 degrees (Cubes-cone6.pov


and Camera-Cubes-Cone6.pov)
turning of an angle of 45 degrees around the vision axis (with left hand convention)
gives figure (1.12).

1.4

Camera for an orthographic perspective view

This is approximately what you obtain with telephotography (and big zooming). The image has no depth of field. Parallel lines in space stay parallel on the
screen. This is Monges descriptive geometry projection. Its interest is to retrieve
real lengths from measurements on the screen. In particular, we shall use it for
plane figures.
The parameters of the camera code are the same as conic perspective, with a
new parameter orthographic :
camera{orthographic
location ... etc.
}

The parameters up and right have the same meaning as in conic perspective,
with a particularity : the screen has actually these dimensions H and W , but the
parameter d of direction has no more importance, and should be deleted.

1.4. CAMERA FOR AN ORTHOGRAPHIC PERSPECTIVE VIEW

25

In fact, only the objects in the half-plane in front of the camera are considered.
If the camera is inside one of them, you cannot be sure whether POV-Ray
represents a part of it or not, so avoid this situation, and use orthographic
perspective only to represent objects in front of you : when you look at a leopard
through telephoto lens, your camera is not in his mouth.

26

CHAPTER 1. USE OF POV-RAY

Chapter 2
Geometric objects
2.1

Elementary solids

The four elementary solids are (see figure (2.1))

Figure 2.1:
solids2.pov)

Elementary solids (Elementary-solids.pov and Elementary-

 The revolution cylinder


object{cylinder{A B r pigment{color ...}}}

where A and B are vectors representing the centers of circular faces, and
r the radius. It should be assigned a color. The simplest way to do it is
pigment{color ...} . This cylinder is full, it is a volume, and not a surface. For
a hollow cylinder (a cylindrical surface), add open just after the radius. Commas
are accepted but not necessary between the parameters.
27

CHAPTER 2. GEOMETRIC OBJECTS

28
 The box

object{box{A B pigment{color ...}}}

which s a rectangle parallelipiped with great diagonal joining the points A and
B. It may not be opened, and is a convex volume. No comma necessary.
 The sphere
object{sphere{A r pigment{color ...}}}

of center A and radius r. No comma necessary between A and r.


 The truncated cone
object{cone{A r B r pigment{color ...}}}

wher A and B are centers of circular faces of respective radii r and r 0 . It is


full but may be hollow with open after the second radius. The two radii are
necessary, even if one of then is null.
They may be translated by translate , rotated by rotate , expanded in
the three directions by scale , which admits a three dimensional parameter
< a; b; c > for expanding of ratio a in x direction, and so on. In figure (2.1)
we have expanded the sphere to obtain an ellipsoid. Then all ellipsoid are basic
shapes in POV-Ray.

2.2

Curve drawing

We have said that POV-Ray does not draw curves. He draws only surfaces and
volumes (in fact only surfaces). A simple strategy to construct a curve consists in
drawing a great number of closed little spheres all along the curve. Figure (2.2)
on the left shows what happens. We choose a very little number of spheres to
show the graphic disadvantage.
Another strategy could be to draw a sequence of cylinders. But curvature
implies an unpleasant discontinuity, see figure (2.2) on the right. With some
patience, a better solution consists in drawing a sequence of cylinders, two
successive cylinders having a circular face center in common, together with the
spheres centered at that points realizing a kind of kneecap to fill the discontinuity.
Now it seems smooth (even if it is not), see figure (2.3).

2.3. TORI AND HLDER NORM BALLS

29

Figure 2.2: Basic curve drawing, with spheres or cylinders (Parabola.pov and
Parabola1.pov)

Figure 2.3: Nice curve drawing, with spheres and cylinders (Parabola2.pov)

2.3

Tori and Hlder norm balls

We present in figure (2.4) two uses of transparency to show the singular tori,
the left one being more abstract. In both cases, the shadows are suppressed. In the
inside view, the tiles are grey and white, which shows that the light source is also
inside the torus.

Figure 2.4: Two view of the three types of tori (Blue-Tori.pov and GlassTori.pov)
A torus of vertical (i.e. y) axis centered at < 0; 0; 0 > is constructed with

CHAPTER 2. GEOMETRIC OBJECTS

30

Figure 2.5: Inside a singular torus (Singular-torus-inside.pov)

object{torus{R r

pigment{color ...}}

where R is the radius of the fixed circle, and r the radius of the turning circles.
When R  r, the torus is singular. and transparency helps to look inside, see
figures (2.4) and (2.5). Another useful object is called by POV-Rays authors

Figure 2.6: Different kinds of superellipsoids (Superellipsoid.pov and Superellipsoid2.pov)


the super-ellipsoid. It is in fact the set of points < a; b; c > (with POV-Ray
conventions) such that

e=n
2=e
2=e
f .a; b; c/ D jaj C jbj
C jcj2=n 1 D 0;

2.4. CONSTRUCTIVE SOLID GEMOMETRY

31

where e and n are arbitrary positive values. POV-Rays code is :


\begin{verbatim}
object{superellipsoid{< e, n> pigment{color ...}}}



For D 2=e and D 2=n, this is the set of points such that k.a; b/k ; c D
1, where k  k denotes Hlder norm of parameter when  1 and  1. As a
super-ellipsoid is defined for all e and n > 0, it may not be convex. In figure (2.6),
the parameters e and n take the values 3, 2, and 1, with e constant for each color.
On the left, the same with the values 3=2, 1, and 1=2, so that they are convex.
These surfaces are defined centered at < 0; 0; 0 > and in a precise position.
They may be transformed by any affine transformation.

2.4

Constructive Solid Gemometry

Commonly named CSG, Constructive Solid Gemometry gives techniques to


code compound geometric objects obtained from simpler ones with set theoretic
operations : union, intersection, difference.

2.4.1

Intersection, union, difference

The code
intersection{box{<-1,-1/2,-1/2> <0,1/2,1/2>
pigment{Red}
}
sphere{<0,0,0> 1
pigment{Blue}
}
no_shadow
}

gives figure (2.7). Colors may be surprising, and we shall describe them later
in this section.
In the above code, we had only to write the word intersection followed
by the direct descriptions of the desired object. Ie we ad assigned to names
such as A, B, ... in a #declare directive (for example to use them for several

CHAPTER 2. GEOMETRIC OBJECTS

32

Figure 2.7: Intersection of a red box and a blue sphere (CSG0.pov)


actions), then the intersection action needs the word object when we want
their intersection, like in the following code.
#declare A = box{<-1,-1/2,-1/2> <0,1/2,1/2>
pigment{Red}
}
#declare B = sphere{<0,0,0> 1
pigment{Blue}
}
intersection{object{A} object{B}
no_shadow
}

A little constraint due to the Object-Oriented nature of the underlying C++


(no more comment).
The operation union is absolutely equivalent to writing the descriptions of
the objects one after the other or the assigned variables A, B, etc. under the form :
object{A}
object{B}

So, why putting them together in a union{...} code ? To work on all of


them simultaneously. Indeed, we may have to translate, rotate, scale, the union
of objects, impose them a common no_shadow , etc. In that case, putting all of
them in a union is necessary.
Figure (2.8) shows the union or two overlapping cubes A and B, and images
of A \ B, A n B, B n A by translations to see all of them on the same picture. The
code is

2.4. CONSTRUCTIVE SOLID GEMOMETRY

33

Figure 2.8: A n B, A \ B, B n A, A [ B. (CSG1.pov)


union{
object{intersection{object{A} object{B}}}
object{difference{object{A} object{B}}
translate<-2,0,0>}
object{difference{object{B} object{A}}
translate<2,0,0>}
object{ union{object{A} object{B}}
translate<0,-3,0>}
no_shadow
}

2.4.2

Color or texture in CGS

Even if we have not yet studied texture, we may just say that a volume has
a texture attached to its boundary, i.e. the surface which bounds it (even when
transparency allows refraction indices and so on). In case of opaque objects, this
texture is strictly attached to the boundary, since we cannot see anything inside.
This is the case we consider here.
Suppose that the boundaries @A and @B have no surface element in common
i.e. have at most curves in common. Then, for opaque objects, color or texture
attribution of the compound object is simple : if some partial surface remains after
the set theoretic operation, it keeps its initial texture/color. For example, in figure

CHAPTER 2. GEOMETRIC OBJECTS

34

(2.8), the concave part of the boundary of B n A comes from A, and A is red, then
it must be red. The same is true for the frontal face of A \ B.
When A and B have a part of face in common, POV-Ray doesnt know which
texture he has to assign to it, and ... does anything which has no geometric
meaning, and probably anything else than what you would expect, see figure (2.9)
for a wooden and a glass cube. In that case, you had rather combine object without

Figure 2.9: Fake texture when A and B have a part of face in common. (CSG2.pov)
color or texture and attribute afterwards a texture to the set theoretic result.
Without entering the details, we give what we think (by pure experimentation)
to be the rule for textures with eventual transparency. The face arising from points

A BB A

B AA B

B A

B A

B A

Figure 2.10: Repartition of textures in a difference, intersection, union.


common to the two interiors of the objects are transformed into a two layer face,
with attribution of texture (or color) like in figure (2.10). It is clear in figure
(2.11). For example in intersection (figure (2.11), the small cube), te top left faces
have texture consisting of two layers. The exterior is blue, as lass like the right

2.5. SURFACES BASED ON A CURVE

35

Figure 2.11: Texture attribution in CSG (CSG3.pov)


big cube B, under which a second layer in wood like the left big cube A, and this
explains the blue wooden faces. When the exterior layer of a common face
is wood, the interior glass layer is invisible. Other tests has been carried out with
two glass objets of different colors, which seem to confirm this description.

2.4.3

Merge

As is said in POV-Ray documentation, the operator union keeps the intersection in the object (at the price of a complicated rule for inside texture). A much
simpler union is merge which forgets the inside parts.
Since in general using merge means trying to construct an homogeneous
object with the two pieces, we shall not play with textures in that case. Indeed,
when the two objects have different textures, the logic of POV-Rays automatic
texturing of a = merge i even less clear. The user is invited to merge only non
textured objects, an graft a texture on the result afterwards.

2.5

Surfaces based on a curve

We describe surfaces constructed in a somewhat mechanic way from a curve :


revolution surfaces, cylindrical surfaces, and canal surfaces. The types of curves
on which they are based is of different possible spline types, which in general
means : interpolated from a finite number of points. POV-Ray offers several
types of interpolation, which we study precisely. Some of these curves may be

36

CHAPTER 2. GEOMETRIC OBJECTS

drawn (as they are actually parametrized), some others not since they are only a
formalization of a directing curve for the surface. Here are the details.

2.5.1

Revolution surfaces, cylinders, canal surfaces

A revolution surface is for POV-Ray a lathe (like a polishing lathe, in french


un tour), with y-axis, and based on a meridian curve drawn in the xOy (vertical)
plane. The code is
lathe{spline_type | [parameters for the spline] [options],
[color, texture, etc.] [sturm]}

where spline_type is the type of spline curve (in the present case, the
meridian curve), to be chosen among the following
linear_spline, quadratic_spline, cubic_spline, natural_spline

The other entries are options, color, and the important reserved word sturm
explained later. For example, the code
lathe{quadratic_spline 5 <4, -2> <2, 0> <1, 3> <2, 4> <0, 5>
texture{T_Wood14
finish{specular 0.35 roughness 0.05 ambient 0.3}
}
sturm
no_shadow
}

gives figure (2.12), in initial position and after rotation-translation. An


orthographic projection (figure (2.13)) shows clearly the three parabola arcs of
the directing curve, as we have chosen the quadratic_spline spline type.
There is another way to draw a revolution surface, the code is sor (like
Surface Of Revolution. It is described precisely in section 3.4.5.1.15 in the Help
of POV-Ray version 3:7. Differences with lathe are given there.
A cylindric surface is for POV-Ray a prism with y direction, based on a
horizontal directing curve in the xOz plane. The code is

2.5. SURFACES BASED ON A CURVE

37

Figure 2.12: A simplified (hollow) chess pawn (Lathe.pov and Lathe0.pov)

Figure 2.13: Orthographic projection of the simplified pawn (Lathe1.pov)

prism{spline_type | [parameters for the spline] [options],


[color, texture, etc.] [sturm]}

with the same kind of parameters, now for the horizontal directing curve.
A canal surface (envelope of a family of spheres) is for POV-Ray a
sphere_sweep with a soul curve, the set of centers of a one parameter family
of spheres, and we have to specify the law of variation of radii of the spheres
enveloped by our surface. The code is
sphere_sweep{spline_type | [parameters for the spline] [options],
[color, texture, etc.] [sturm]}

CHAPTER 2. GEOMETRIC OBJECTS

38

In the three cases, the 3-dimensional object is based on a curve (or polygon)
which must take one of the following forms :
 linear_pline : a polygonal line ;
 quadratic_spline : a juxtaposition of pieces of parabola, not even
1
C but useful for simple curved surfaces of revolution (parther useless for
mathematicians) :
 bezier_pline , cubic_pline and natural_spline : a C 1 juxtaposition of third degree parametrized curves, but with different join techniques
corresponding to different needs.
For a lathe or a prims , the base point parameters of the spline are 2dimensional (respectively in the xoY and the xOz planes), and for a sphere_sweep
they are 3-dimensional.
We shall see later how to use these splines for these surfaces, but we have
now to give a detailed description of all these splines, since POV-Rays use is
not always standard.

2.5.2

Linear and quadratic splines

A linear_spline is simply a polygon, specified by a sequence of points,


with two of three coordinates. Two when it is used for a lathe or prism, three for
a sphere-sweep (since the soul curve may not be plane).
We are given n points p1 , . . . , pn . The code
linear_spline

p_1 ... p_n

defines, for each i from 2 to n, the unique segment joining pi 1 to pi .


The polygon is their union. Notice the number of points just after the word
linear_spline .
For a quadratic_spline , we are given a sequence of n C 1 points p0 , p1,
. . . , pn . A curve will be drawn, passing at the successive points p1 , p2 , . . . , pn
(but not p0 , used only as a control point for the first parabola arc). The code
quadratic_spline

n+1

p_0

p_1 ... p_n

defines, for each i D 2; : : : ; n, the image of the arc i restriction to 0; 1 of


the unique parametrized arc i : 1; 1 ! E D R2 or R3 such that :
 i is a polynomial of degree 2 ;
 i .0/ D pi 1 , i .1/ D pi ;

2.5. SURFACES BASED ON A CURVE

39

pi 2
.
2
This define entirely i (see figure (2.14)) :
 i0 .0/ D

pi

8t 2 0; 1;

i .t / D pi

Ct

pi

pi
2

Ct

p

C pi
2

i 2


pi 1 :

The curve is the union of these arcs. The restriction of i to 1; 0 is never


pi

pi

pi

Figure 2.14: POV-Rays quadratic spline


represented ! The arc i depends only on the three points pi 2 , pi 1 , pi . It implies
that the curve is not even C 1 in general. but it may give nice lathes (chess
pawns, chair legs ...).
Much more interesting are the following splines.

2.5.3

Elementary arc for pour cubic, bezier and natural splines

In the three cases, the spline is a juxtaposition of third degree parametrized


arcs constructed in the same following way (which is in fact generally called a
Bezier curve).
Let us begin by a small algebraic reminder.
Given four real numbers p, q, v, w, there exists a unique function f polynomial
of degree at most 3 such that :
f .0/ D p;

f .1/ D q;

f 0.0/ D v;

f 0 .1/ D w:

These conditions are linear, so it suffices to determine f for :


 .p; q; v; w/ D .1; 0; 0; 0/, which defines f0 ,
 .p; q; v; w/ D .0; 1; 0; 0/, which defines f1 ,
 .p; q; v; w/ D .0; 0; 1; 0/, which defines g0 ,
 .p; q; v; w/ D .0; 0; 0; 1/, which defines g1 .

(2.1)

CHAPTER 2. GEOMETRIC OBJECTS

40
Then (see figure (2.15))
f0.t / D .2t C 1/.t

g0 .t / D t .t

1/2 ;
1/2 ;

f1 .t / D t 2.2t

g1 .t / D t 2.t

3/

(2.2)

1/:

(2.3)

The general f is f D pf0 C qf1 C vg0 C wg1.

Figure 2.15: Functions f0 , f1, g0 and g1


This may be naturally extended to vector functions 0; 1 ! E D R2 or R3.

2.5.4

POV-Ray cubic spline

We are given n C 2 points p0 , p1 , . . . , pn , pnC1 . The points p0 and pnC1 are


only control points. The code
cubic_spline

n+2

p_0

p_1 ... p_n

p_{n+1}

defines, for each i from 2 to n, the unique arc i : 0; 1 ! E D R2 or R3 of


degree  3 such that :
i .0/ D pi 1; i .1/ D pi
pi pi 2
pi C1 pi
i0.0/ D
; i0.1/ D
2
2

(2.4)
1

(2.5)

2.5. SURFACES BASED ON A CURVE

41

This arc i is, for t 2 0; 1 :


i .t / D t 3

3

pi

 pi C1 pi 
pi C
2

5
pi 1 C 2pi
C t 2 pi 2
2

pi C1 
pi pi
Ct
2
2

C pi

1:

This draws n 1 elementary arcs from p1 to pn .


Since i0 .0/ D i0 1.1/, this arc is, by construction, C 1, wich is (graphically)
much better than a quadratic_spline . It needs two extra-control points p0 and
pnC1 , but no information more, and is rather simple. Nevertheless, we must have
in mind the slope of the line .pi 1 pi C1/ to determine the direction of the tangent
at pi , which is uneasy when we have in mind a shape and look for the way of
drawing it. Another disadvantage is that this interpolation supposes implicitly
equality between the time intervals of parameters, which may have unpleasant
geometric consequences.

2.5.5

POV-Ray bezier spline

We are given a sequence of points denoted by : p1 , r1 , s1 , q1 , p2 , r2 , s2 , q2 ,


. . . , pi , ri , si , qi , . . . , pn , rn , sn , qn . The code
bezier_spline

4n

p_1

r_1

s_1

q_1

...

p_n

r_n

s_n

q_n

defines, for each i from 1 to n, the unique arc i of degree  3 : 0; 1 ! E D R2


or R3 ) such that :
i .0/ D pi ;

i0 .0/ D 3.ri

i .1/ D qi
pi /;

i0.1/ D 3.qi

(2.6)
si /:

(2.7)

The tangent at pi contains ri ant the tangent at qi contains si . Exactly what


you obtain with the pen tool of Adobe Illustrator (and any other graphic tool).
The coefficient 3 in the derivatives could be arbitrary. Figure (2.16) suggests a
justification of this consensual choice of 3. If
p1 D< 0; 0 >; r1 D< 0; 1 >; s1 D< 1; 1 >; q1 D< 1; 0 >;
the arc 1 is 1.t / < 3t 2

2t 3; 3t .1

t / >, see figure (2.16). The code

CHAPTER 2. GEOMETRIC OBJECTS

42

r1

s1

p1

q1

Figure 2.16: Basic Bezier curve (left Illustrator, right Prism-Bezier.pov)

prism{bezier_spline 0, 0.01, 8, <0,0> <0,-4> <4,-4> <4,0>


<4,0> <4,4> <0,4> <0,0>
pigment{Blue}
sturm}

gives figure (2.16) on the right, which proves that POV-Ray and Illustrator (and
everybody) agree. The n little arcs are constructed independently and this implies

r1

s1

q1 D p 2

p1
r2

s2

q2

Figure 2.17: Two consecutive Bezier arcs for C 1 linking (Illustrator)

a repetition for continuity : even if qi D pi C1 both must be specified in the code.


A necessary and sufficient condition to obtain a C 1 arc is : ri C1 pi C1 D qi si
(recall that qi D pi C1), see figure (2.17).

2.5. SURFACES BASED ON A CURVE

2.5.6

43

POV-Ray cubic spline with variable steps

We are given reals t0 < t1 <    < tn < tnC1, and n C 2 points p0 , p1 , . . . , pn ,
pnC1 . The code
cubic_spline

2n+2

t_0

p_0

t_1

p_1

...

t_{n+1}

p_{n+1}

defines the unique curve : t0 ; tnC1 ! E whose restriction to ti 1 ; ti for


each i from 2 to n, is the unique arc i of degree  3 : ti 1 ; ti ! E D R2 or R3
such that :
i .0/ D pi ; i .1/ D qi
1  pi pi 1
pi C1 pi 
0
.ti / D
C
2 ti ti 1
ti C1 ti
0
.ti 1 / D the analoguous for the index i

(2.8)
(2.9)
1:

(2.10)

This defines finally an arc of domain t1 ; tn, and an interpolating curve.

2.5.7

POV-Ray natural spline (with variable steps)

We are given reals t0 < t1 <    < tn < tnC1, and n C 2 points p0 , p1 , . . . , pn ,
pnC1 . The code
natural_spline

2n+2

t_0

p_0

t_1

p_1

...

t_{n+1}

p_{n+1}

defines the unique curve : t0 ; tnC1 ! E whose restriction to ti 1 ; ti has


degree  3, .ti / D pi , even for i D 0, n C 1, of class C 2 on the whole domain,
and with zero acceleration at t0 and at tnC1. This defines also an arc of domain
t0 ; tnC1, and an interpolating curve. This is the classical spline.
These two last splines define an arc from an interval of R to E, and allow
a draw of the arc itself, unlike the preceding splines for which the code defines
a global object used to construct formally a directing curve for a special surface
(and for which we want to draw the surface and not the spline).

2.5.8

Drawing a lathe

Each of the above types of splines may serve to draw a lathe. The curve is
not necessarily closed, but you should avoid to use a curve which cuts the y-axis.
The code

44

CHAPTER 2. GEOMETRIC OBJECTS

lathe{quadratic_spline 6 <6,-4> <3,-2> <2,0> <3,1> <2,2> <3,4>


pigment{color Blue}
no_shadow
rotate<90,0,0>
}

gives figure (2.18), a lathe with quadratic_spline meridian curve has ben
turned of 90 degrees and put on a floor at y D 4 to show control points (small
green balls, also turned) and some tangents (small red segments, in fact cylinders).
Notice that the tangent down on the right is indeed parallel to the segmen joining
the (images b rotation of) points p0 and p2 , the first being a control point, the
second on the meridian curve.

Figure 2.18: Lathe for quadratic spline meridian, without and with Sturm option
(Lathe2-no-sturm.pov and Lathe2.pov)
On the right, the option sturm avoids some problems of intersection of light
rays and the surface which appeared on the left. The reader is invited to compare
the base points and the control points (little green balls on figure) with the code.
For a cubic_spline meridian cuve, the code
lathe{cubic_spline 7 <6,-4> <3,-2> <2,0> <3,1> <2,2> <3,4> <6,2>
pigment{Blue}
no_shadow
rotate<90,0,0> sturm}

gives figure (2.19, left). Now, there are two extra control points (isolated green

2.5. SURFACES BASED ON A CURVE

45

balls on figure), but now the lathe is C 1 . Dont forget to write the total number of
points (even control points). For a bezier_spline meridian cuve, the code

Figure 2.19: Lathe for cubic spline and bezier spline meridian (Lathe3.pov and
Lathe4.pov)

lathe{bezier_spline 8 <3,-2> <1,-2> <1,0> <3,0>


<3,0> <5,0> <5,2> <3,2>
texture{T_Bottle_Glass}
no_shadow
rotate<90,0,0> sturm}

gives figure (2.19, right). The surface is in glass, to show control and base
points. Notice that each elementary curve is defined by four points.
In any case, a meridian curve needs not be closed for a lathe , as can be seen
on figure (2.12) on the right.

2.5.9

Drawing a prism

Unlike in a lathe , the directing curve of a prism has to be closed. That is :


the last base point has to be identical to the first (base point, and not control point).
This allows, for a same code prism to represent several cylindrical surfaces,
since when POV-Ray meets an already written base point, he closes the spline,
and, if there are new points, starts a new spline for a new surface (called a new
sub-prism). For example, for two linear sub-prisms, the code has the form

46

CHAPTER 2. GEOMETRIC OBJECTS

\begin{verbatim}
prims{linear_spline a b n+m+2 p_0 p_1 ... p_{n-1} p_0
q_0 q_1 ... q_{m-1} q_0 [options],
[texture, etc.] [sturm]}

Notice that the total number of points has to be written. The numbers a and b
are the y-coordinate of the extreme levels of the prism.

Figure 2.20: Prisms (Prism1.pov)


In the following example (figure (2.20))
prism{linear_spline 0 0.5 18 <0,0> <3,0> <3,3> <0,0>
<-2,-1> <4,-1> <4,5> <-2,-1>
<5,0> <7,0> <7,2> <5,2> <5,0>
<6,1> <8,1> <8,3> <6,3> <6,1>
pigment{Blue}}

the base curve is made of four polygons. POV-Ray chooses as base surface
the boolean addition of the domains bounded by them.
The same remarks apply to other spline types. For example, if the base of the
prism is the boolean sum of two domains bounded by a cubic_spline , the code
is
prims{cubic_spline a b n+2+m+2 p_0 p_1 ... p_{n-1} p_0 p_{n+1}
q_0 q_1 ... q_{m-1} q_0 q_{m+1}
[options], etc.

2.5. SURFACES BASED ON A CURVE

47

The control points are p0 , pnC1 , q0 , qnC1 . The closure points for the two
curves are p0 and q0 .
If the base of the prism is the boolean sum of two domains bounded by a
succession of elementary bezier_spline curves, the code is
prims{cubic_spline a b 4*(n+m) p_1 r_1 s_1 q_1
p_2 r_2 s_2 q_2
...
p_n r_n s_n q_n
p_1 r_1 s_1 q_1
p_2 r_2 s_2 q_2
...
p_m r_m s_m q_m
[options], etc.

where q1 D p2 , . . . , qn 1 D pn and the same with primes to ensure continuity


0
of the two Bezier curves, and qn D p1 to close the first Bezier curve, and qm
D p10
to close the second. For example, figure (2.16) on the right results from code
prism{cubic_spline 0, 0.01, 6,
<6,12> <0,0> <6,0> <0,12> <0,0> <0,0>
pigment{Blue}
sturm}

(followed by 90 degrees rotation).

2.5.10

Drawing a canal surface

For a sphere_sweep , we choose control and base points for the directing
curve, and control and base values for the variable radius of the mobile sphere.
In the code, each (base or control) point must be followed by the corresponding
(base or control) radius for the one parameter family of spheres.
For a linear_spline , the code is
sphere_sweep{cubic_spline n p_1 R_1 ... p_n R_n
[options, color, etc.]}

CHAPTER 2. GEOMETRIC OBJECTS

48

Figure 2.21: A canal surface with linear spline, outside and inside (Canal-LinearSpline.pov and Canal-Linear-Spline-Inside.pov)

Figure (2.21) is coded by


sphere_sweep{linear_spline 3 <0,0,0> 1 <3,0,0> 1 <3,0,3> 1}

where we have omitted texture coding for the blue glass (to see later). In
this example, sphere radii are constant. In genera, for a linear_spline canal
surface, sphere radii vary linearly on each segment, which means that the surface
has conic parts joined by spherical sectors.
For a cubic_spline sphere-sweep, the code is
sphere_sweep{cubic_spline n+2 p_0 R_0 p_1 R_1 ... p_{n+1} R_{n+1}
[options, color, etc.]}

We show now an example of sphere_sweep with a cubic_spline directing


curve, figure (2.22). The code is
sphere_sweep{cubic_spline 5
<0,8,0> 1 <4,0,0> 1 <8,2,4> 1/2 <12,0,0> 1 <16,-8,0>}

There is no Bezier version of sphere_sweep surfaces.

2.5. SURFACES BASED ON A CURVE

49

Figure 2.22: A canal surface with cubic spline (Canal-Cubic-Spline.pov)

2.5.11

Using a canal surface to draw a curve

A natural question is : why not representing curves in R3 by a solid


sphere_sweep ? It would avoid to code a sausage chain. In fact, it is
easy, since the sequence of points in a linear_spline (or any other spline) may
be programmed. The parabola arc of figure (2.2) may be coded as
#declare nbsegs=100;
#macro ff(tt)
tt*tt
#end
sphere_sweep{linear_spline 1+nbsegs
#declare i=0;
#while (i <= nbsegs)
<i/nbsegs,0,ff(i/nbsegs)> 1/nbsegs
#declare i=i+1;
#end
pigment{Blue}
no_shadow}

With a great number of base points, it seems very smooth, see figure (2.23).

2.5.12

Drawing parametrized spline curves

We have presented above parametrized spline curves with variable steps :


cubic_spline of subsection 2.5.6 and natural_spline of subsection 2.5.7.

CHAPTER 2. GEOMETRIC OBJECTS

50

Figure 2.23: A curve represented as a thin canal surface (Canal-Curve.pov)

In both cases, the sequence of base and control parameters and points define a
global arc . This arc become a function t 7! .t / when we use spline . Indeed,
spline is a function whose parameter is t and which returns .t /. It may be
used for example to draw the arc as a chain of small spheres.
Choose a personal arbitrary name, for example MySpline and write the code
#declare MySpline =
spline{cubic_spline n
t_0 p_0 t_1 p_1 ... t_n p_n t_{n+1} p_{n+1}
}

where, between the brackets of spline , you write the description of the
cubic_spline like in subsection 2.5.6 or subsection 2.5.7. Then, for each value
of t , the code MySpline(t) returns .t /, with which you can do what you want.
You may now draw the chain of spheres which represent the curve :
#declare tt = -3;
#while (tt <= 12)
sphere {MySpline(tt), 0.03
pigment{Blue}
}
#declare tt = tt + 0.01;
#end

The same may be done with natural_pline . Nothing like that exists for
bezier_spline . A detail : in the code above, we have used the variable tt ,
since the letter t is reserved in POV-Ray.

2.6. BEZIER BICUBIC SURFACES

2.6

51

Bezier bicubic surfaces

Using bicubic_patch reduces drastically memory needs in representing


surfaces. A patch is defined by four base points and twelve control points. We
see here what they are precisely, how to code them in POV-Ray, and how to put
several patches together to obtain a well controled C 1-surface.

2.6.1

Bicubic functions

We know, and we resume with slightly different notations, that given four
points p0 , p1 , p2, p3 in E D Rk , the curve parametrized on 0; 1 by :
!
3
X
3 i
t!
7 f .t / D
t .1
i
i D0

3 i

t/

pi D

3
X

Bi .t /pi

i D0

is the unique curve of degree  3 such that


 f .0/ D p0 , f .1/ D p3 ;
 f 0.0/ D 3.p1 p0 /, f 0.1/ D 3.p3 p2 /.
We shall examine a two variables analog .u; v/ 7! f .u; v/ of this result. From
now on, we denote by fu , fv , fuv , etc. the partial derivatives of f .
A bicubic polynomial or bicubic function is a mapping f : 0; 1  0; 1 !
E D Rk whose each component is a polynomial of degree  3 with respect to
each variable.

The four Bernstein polynomials Bi : t 7! 3i t i .1 t /3 i , i D 0; : : : 3 form a
basis of the vector space of degree  3 polynomials. Then a bicubic function
writes uniquely

f .u; v/ D

3
3 X
X

ui v j pi;j ;

i D0 j D0

pi;j 2 Rk :

The family .pi;j /i D0:::3;j D0:::3 characterizes f . Moreover :


Proposition 2.6.1. Let us be given 16 points pi;j , i D 0; : : : 3, j D 0; : : : 3.
The function f : 0; 1  0; 1 ! Rk defined by (2.11) :
.u; v/ 7! f .u; v/ D

3 X
3
X

i D0 j D0

Bi .u/Bj .v/pi;j

(2.11)

CHAPTER 2. GEOMETRIC OBJECTS

52

is the unique bicubic function with the 16 following properties :


f .0; 0/ D p0;0 ; f .1; 0/ D p3;0 ; f .0; 1/ D p0;3 ;
fu .0; 0/ D 3.p1;0 p0;0 /; fu .1; 0/ D 3.p3;0
fu .0; 1/ D 3.p1;3 p0;3 /; fu .1; 1/ D 3.p3;3
fv .0; 0/ D 3.p0;1 p0;0 /; fv .0; 1/ D 3.p0;3
fv .1; 0/ D 3.p3;1 p3;0 /; fv .1; 1/ D 3.p3;3
fu;v .0; 0/ D 9.p1;1
fu;v .1; 0/ D 9.p3;1
fu;v .0; 1/ D 9.p1;3
fu;v .1; 1/ D 9.p3;3

p1;0
p3;0
p1;2
p3;2

f .1; 1/ D p3;3
p2;0/
p2;3/
p0;2 /
p3;2 /

p0;1 C p0;0 /
p2;1 C p2;0/
p0;3 C p0;2 /
p2;3 C p2;2/

9
>
>
>
=

9
>
>
>
>
>
=

(2.12)

>
>
>
>
>
;
(2.13)

>
>
>
;

Proof. Only uniqueness needs a proof. If f is bicubic, null at the four vertices of
the unit square, with first partial derivatives and cross second derivatives null at
these points, then f is null.
Unlike what is sometimes written, and due to this proposition, determining the
vectors pi;j is easy if the data are the value of f and the above partial derivatives
at the four vertices of the unit square. Indeed, from the relations (2.12) we obtain
immediately the pi;j s at the four vertices. The eight following equations in (2.12)
give the pi;j s on the edges, and the four equations (2.13) give the four remaining
vectors p1;1 , p1;2 , p2;1, p2;2 .

2.6.2

POV-Ray bicubic patches

If we denote by Pij the point pi;j of proposition 2.6.1, the code for a
bicubic_patch is
bicubic_patch {
type T
flatness F
u_steps U v_steps V
P00, P10, P20, P30
P01, P11, P21, P31
P02, P12, P22, P32
P03, P13, P23, P33
texture{MyTexture}
}

2.6. BEZIER BICUBIC SURFACES

53

where T, F, U, V are values chosen by the user which modify POV-Rays


rendering. Their use is explained in section 3.4.5.2.1 Bicubic patches, and we
give here some precisions on these rather short explanations...
POV-RAy forces the user to write the parameter type which may take
two values 0 and 1 (otherwise, error message). If you dont specify the three
other parameters flatness , a_steps and v_steps , their value is implicitly
supposed to be 0.
Suppose you have written
bicubic_patch {
type 0
flatness 0
u_steps U
v_steps V
....

with values of U and V positive integers. Then POV-Ray replaces the image
of the parametrization f by its triangulated approximation in the following way.
Consider a grid of the domain 0; 1  0; 1 of 2U equal intervals for the first
variable u, and 2V equal intervals for the second variable v, each small rectangle
of the grid being decomposed in the canonical way into two triangles. Then,
these small triangles triangulate 0; 1  0; 1, and POV-Ray replaces the image
of f restricted to each of them by the image of the affine mapping coinciding
with f at the vertices of the small rectangle. Figure (2.24) shows POV-Rays
approximation for the same 16 base and control points according to the values
U D V chosen. A checker has been calibrated onto the surface to display the
triangulation. When the user decides type 1 , according to flatness value,
POV-Ray make simplifications and records intermediate results to win time and
economize memory in the ray-tracing step, but it doesnt seem to change the
geometric result, so we shall not go further into these details. You have just to
remember that a good value of U and V is in general U D V D 3 or at most
4 Indeed, U D 3 gives 64 rectangles (a chessboard), and 128 triangles for each
bicubic patch.

2.6.3

Joining bicubic patches

To obtain a C 1 surface by juxtaposition of bicubic patches forces contact


conditions fortunately simple and natural. Figure (2.25) shows immediately the
conditions : the rods should be the same at the common edge, and the transversal

54

CHAPTER 2. GEOMETRIC OBJECTS

Figure 2.24: POV-Ray bicubic patch with U D V D 1 and U D V D 2


(Bicubic-Patch-Steps1.pov and Bicubic-Patch-Steps2.pov)

Figure 2.25: A not-G1 and a G1 joining of two bicubic patches (Bicubic-PatchShow.pov and Bicubic-Patch-Show2.pov)
rods should be aligned on this common articulation. It will be a corollary of
proposition 2.6.1.
A shorter reformulation of proposition 2.6.1 simplifies things. For four vectors
p0 , p1 , p2 , p3 , we denote by Bp1; p2; p3; p4 the one variable vectorial function
P
t 7! 3iD0 Bi .t /pi .
Proposition 2.6.2. Given points pi;j , i D 0; : : : 3, j D 0; : : : 3, there exists a
unique bicubic fonction f on 0; 1  0; 1 bicubique such that :
9
f .; 0/ D Bp0;0 ; p1;0 ; p2;0 ; p3;0 >
>
>
=
f .; 1/ D Bp0;3 ; p1;3 ; p2;3 ; p3;3
f .0; / D Bp0;0 ; p0;1 ; p0;2 ; p0;3 >
>
>
f .1; / D Bp3;0 ; p3;1 ; p3;2 ; p3;3 ;

(2.14)

2.7. ISOSURFACES

55

fv .; 0/ D 3Bp0;1
fv .; 1/ D 3Bp0;3
fu .0; / D 3Bp1;0
fu .1; / D 3Bp3;0

p0;0 ; p1;1
p0;2 ; p1;3
p0;0 ; p1;1
p2;0; p3;1

p1;0 ; p2;1
p1;2 ; p2;3
p0;1 ; p1;2
p2;1 ; p3;2

p2;0 ; p3;1
p2;2 ; p3;3
p0;2 ; p1;3
p2;2; p3;3

p3;0
p3;2
p0;3
p3;2

9
>
>
>
=

(2.15)

>
>
>
;

Proof. The first four formulas are immediate. Afterwards, it suffices to derive
partially the formula (2.11) for example with respect to v and put v D 0 to obtain
the desired formula for fv .u; 0/. The same for the other ones.
Then the 16 points pi;j data dtermine entirely f by :
 its restriction to the boundary of the square ;
 the restriction of fv to the horizontal sides of the square ;
 the restriction of fu to the vertical sides of the square.
This gives the condition to obtain a C 1 surface by juxtaposition of bicubic
patches :
Corollaire 2.6.3. Let f be a function defined on the rectangle 0; n  0; m (n
and m entiers), whose restriction to each ; C 1  ; C 1 ( and entiers) is,
;
after integer translation, a bicubic patch associated to a family .pi;j
/i D0:::3;j D0::3.
1
A necessary and sufficient condition so that f be of class C is that, for all ,
, between evident bounds, and all i , j the follwing relations are verified :
;
p3;j
;
p3;j
;
pi;3

C1;
;
D p0;j
; pi;3
;
C1;
p2;j D p1;j
;
; C1
pi;2
D pi;1

; C1
D pi;0
C1;
p0;j
; C1
pi;0

9
>
=

(2.16)

>
;

A C 2 joining is beyond the scope of these notes and standard POV-Ray.

2.7
2.7.1

Isosurfaces
Volume by isosurface

Consider a compact domain D bounded by the surface B, for example a box


(bounded by a rectangle parallelipiped), or a ball bounded a sphere. Consider also
a function f : R3 ! R, .x; y; z/ 7! f .x; y; z/, and choose an arbitrary number a.
Then isosurface represents precisely the set V of < x; y; z >2 D (in POV-Ray
notations and coordinates) such that f .x; y; z/  a.
The minimal code is

CHAPTER 2. GEOMETRIC OBJECTS

56

isosurface{
f(x,y,z)
threshold a
contained_by D
max_gradient m
[open]
}

where you notice a very important parameter max_gradient whose value m


is written by the user, which is roughly an upper bound (not necessary the least)
of the norm of the gradient of f in the domain D. You have to know it a priori,
since POV-Ray really uses this value of m to draw the volume. This point will be
discussed latter in this subsection.
For example the code
isosurface{function{y-cos(2*x)*cos(2*z)}
threshold 0
max_gradient MaxGradient
contained_by{box{<-pi/2,-pi/2,-pi/2>
<pi/2,pi/2,pi/2>}}
}

gives figure (2.26) on the left, and when we replace f .x; y; z/ D y


cos 2x cos 2z by f .x; y; z/, we obtain figure (2.26) on the right. The value
of max_gradient has been calculated by another software (Mathematica or
Maple). If you forget it, POV-Ray assigns an arbitrary general value which leads
to holes like in figure (2.27). A first solution is to put a rough approximation of
max_gradient , and to increase it until the holes and visual artefacts disappear.
But for a too high value of max_gradient , execution time and memory size
increases drastically. To help users estimation of max_gradient , POV-Ray
offers an option evaluate . You will find its use in the Help.

2.7.2

Surface by isosurface

With the open option, POV-Ray represents only the (infinitely thin) surface
of points < x; y; z >2 D such that f .x; y; z/ D a, see figure (2.28).
A natural question (to which the answer is no so clear in the documentation) is

2.7. ISOSURFACES

57

Figure 2.26: Volumes f .x; y; z/  a and f .x; y; z/  a by isosurface. (Isosurface1.pov and Isosurface2.pov)

Figure 2.27: Isosurface without max_gradient control (Isosurface3.pov)

Figure 2.28: Isosurface with option open (Isosurface4.pov)

CHAPTER 2. GEOMETRIC OBJECTS

58

whether the image obtained is the set V of < x; y; z >2 D (in POV-Ray notations
and coordinates) such that f .x; y; z/  a or its boundary @V , that is the union of :
 the set of points < x; y; z > (in POV-Ray coordinates) such that f .x; y; z/ D
a;
 the set of points < x; y; z > of the boundary B such that f .x; y; z/  0.
To see that without the option open it is in fact the volume, it suffices to
assign it a texture of glass with refraction index, and to push in it a stick of wood.
If it is a volume, refraction will bend the image of the stick see figure (2.29).

Figure 2.29: An isosurface is a volume. (Isosurface5.pov)


It may happen that, for CSG, you have to thicken a bit the infinitely thin
surface obtained with the open option. A simple mean to do this, which
we shall find again in algebraic surfaces, is to suppress open option, and
to draw the intersection of V D f< x; y; z >2 D = f .x; y; z/  ag with
V 0 D f< x; y; z >2 D =
f .x; y; z/  a C "g, for an arbitrary small value of
". In figure (2.30), " has been taken not too small to show the thickening.

2.8
2.8.1

Algebraic surfaces
Surface with poly and polynomial

POV-Rays treatment of surfaces S : f .x; y; z/ D a by isosurface is


complicated, based on the gradient of f near the points of S , and requiring
control of a delicate parameter max_gradient . POV-Ray users are interested in
drawing with isosurface very irregular (even if smooth) surfaces.
For mathematicians, it gives good looking surfaces for a non-polynomial
surfaces, as seen in the above examples.

2.8. ALGEBRAIC SURFACES

59

Figure 2.30: Slightly thickened isosurface (Isosurface6.pov)


POV-Ray can benefit from the algebra when the equation f .x; y; z/ D 0 of
S is polynomial, since in this case, it usees a very different algorithm without
the risk of artefacts of the above methods. For example the code for Hadamards
double hyperboloid, of equation
..x

2/2 C z 2

y2

1/..x C 2/2 C z 2

y2

1/

2 D 0;

presented in the introduction is


object{
poly{4,
<1, 0, 0, 0, -2, 0, 0, 2, 0, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, -2, 0, -6, 0, 0, 0, 0, 1, 0, 6, 0, 7>
scale < 2,2,2>
texture{...}
clipped_by{box{<-13,-7,-8> <13,7,8>}}
no_shadow
}

In general the surface S is defined by the code


poly{N
<a_1, a_2, ... a_m>
clipped_by{...]}
}

CHAPTER 2. GEOMETRIC OBJECTS

60

where N is a degree chosen by us and between < and > are written the
coefficients of P which must have a total degree inferior or equal to N , in a very
precise order which we shall describe now.
For the three variables x, y, z (in this order), the chosen order for the
monomials x i y j z k is the decreasing lexicographic order. It means that
8
0

< .i > i / or
.i; j; k/ precedes .i 0 ; j 0; k 0 / , .i D i 0 and j > j 0 / or

:
.i D i 0 and j D j 0 and k > k 0 /

But an essential point is that all coefficients, even the null ones, for monomials of
degree  N must be present in the list. The number of coefficients depends only
on the chosen number N , and POV-Ray rejects the polynomial if the number of
 .N C 1/.N C 2/.N C 3/
coefficients between < and > is not N 2C3 D
.
6
This order may be visualized by grouping the terms as follows. Once chosen
N (recall that w have to choose N ), we write our polynomial P in the form
P D xN C xN

P1 .y; z/x N

P2 .y; z/ C : : : ;

where we attach to Pq the number q, and we think that the coefficients will be
written in this order. Next, each Pq is written in the form
Pq D y q Pq;0 .y; z/ C y q 1 Pq;1 .z/ C y q

Pq;2 .z/ C : : :

Finally, each Pq;r is written in decreasing degrees of z.


The list of monomials is given, for low degree, in section 3.4.5.3.5 of the
Help. This ordering is also called lexicographic ordering in [C-L-OS] (Definition
3 page 55). They say (where their strict inequality < is our precedes) :
D .1 ; 2; 3/ < D .1; 2; 3/ if and only if, in the vector difference
2 Z3 the left-most nonzero entry is positive.
We shall see later that Mathematica can construct this list of coefficients
for us, given a traditional mathematical formula. Anyway, if you have forgotten
lexicographic order (or the little Mathematica tool), you may use poynomial ,
and write precisely the correspondence between indices and coefficients like in
the following code

2.8. ALGEBRAIC SURFACES

61

object{
// Torus having major radius sqrt(40), minor radius sqrt(12)
polynomial { 4,
xyz(4,0,0):1,
xyz(2,2,0):2,
xyz(2,0,2):2,
xyz(2,0,0):-104,
xyz(0,4,0):1,
xyz(0,2,2):2,
xyz(0,2,0):56,
xyz(0,0,4):1,
xyz(0,0,2):-104,
xyz(0,0,0):784
}
texture{...}
clipped_by{box{<-13,-7,-13> <13,7,13>}}
no_shadow
}

which gives figure (2.31).

Figure 2.31: Drawing a polynomial (Draw-Polynomial.pov)

2.8.2

Singular surface with poly

There is no rose without a thorn. In mathematics, thorns are named cusps.


Some unpleasant artefact appears when drawing with poly the surface (with

62

CHAPTER 2. GEOMETRIC OBJECTS

POV-Ray conventions)
f .x; y; z/ D x 2 C y 2

z 3:

See the thin vertical line in figure (2.32) on the left. Such an inconvenient does
not arise with a conical singularity, like in figure (2.32) on the left. The precise

Figure 2.32: Cuspidal and conical singularity with poly (Cuspidal-singularitypoly.pov and Conical-singularity-poly.pov)
position of the artefact (a line testifying a problem of ray tracing in presence of a
cusp) can hardly be foreseen, since when there are two cusps, like in the famous
zitrus f .x; y; z/ D y 2 C z 2 C x 3.x 1/3 (figure (2.33)), there is only one unwanted
line, and it does not pass necessarily at the cusp. It is not necessarily orthogonal

Figure 2.33: Zitrus drawn with poly (and rotated) and with isosurface (Zitruspoly.pov and Zitrus-isosurface.pov)
to the cuspidal tangent. Is is really undesirable. See figure (2.33) on the left.

2.8. ALGEBRAIC SURFACES

63

Figure 2.34: Whitney umbrella drawn with poly and with isosurface (Whitneyumbrella-poly.pov and Whitney-umbrella-isosurface.pov)
Such problems arise in non isolated singularity, like Whitney umbrella, see
figure (2.34).
We may think that, as usual, POV-Ray doesnt feel at ease with codimension
two. The reason is certainly more technical, since isosurface (with a convenient
value of max_gradient ) solves quickly the problem, see figure (2.33) on the
right. The same is true for the cusp, perfectly represented by isosurface .
Another solution is to mask the artefact, by choosing well a clipping box,
or with a CSG technique like difference . All that to avoid to control
max_gradient ...

2.8.3

Complete intersection with poly

A CSG technique to enhance the complete intersection of the surface


f .x; y; z/ D 0 and g.x; y; z/ D 0 (in the domain D) is the following. First, we
thicken each surface by defining F D f< x; y; z >2 D =
"  f .x; y; z/  "g,
constructed as a difference , and G D f< x; y; z >2 D = "  g.x; y; z/  "g.
Then the (thickened) intersection curve will be rope F \ G, constructed with
intersection .
A transverse intersection is well represented in this way, but we have to accept
variations of the section of the rope thus constructed. For example, the rope in
figure (2.35) is flattened on its highest part (on the left) since the angle between
the tangent planes of the two surfaces is rather small. When the tangent planes
make an angle of 90 degrees, the section of the rope is a square.
The code of figure (refComplete-Intersection) (we give here only the drawing
of the black rope) is

CHAPTER 2. GEOMETRIC OBJECTS

64
#declare epsilon = 0.01;
object{
intersection{
difference{poly{2,
poly{2,
}
difference{poly{2,
poly{2,
}
}
pigment{Black}
no_shadow
}

<1, 0, 0, -1, 0, 0, 0, 1, 0, -epsilon>}


<1, 0, 0, -1, 0, 0, 0, 1, 0, epsilon>}
<-1, 0, 0, 0, 0, 0, 1, 1, 0, -epsilon>}
<-1, 0, 0, 0, 0, 0, 1, 1, 0, epsilon>}

where f .x; y; z/ D x 2 C z 2 x D 0 the blue cylinder) and g.x; y; z/ D


y x 2 C z 2 (the violet hyperboloid). Of course, at a point where the surfaces are

Figure 2.35: Complete intersection (Complete-Intersection.pov)

tangent, the thickened intersection will be thicker. We can play on ".


Essentially the same result would be obtained with isosurface instead of
poly .

2.9. PARAMETRIC SURFACES

2.9

65

Parametric surfaces

POV-Ray is able to draw parametrized surfaces, but, as we said above,


parametrized surfaces are not natural in ray tracing. They are faithfully represented, this is why they are evoked here, but rendering is very (very !) slow, even
with some special techniques proposed by POV-Ray to avoid useless or repeated
calculations.
As usual the code for a parametrized surface
< u; v >7!< X.u; v/; Y .u; v/; Z.u; v/ >
(with POV-Ray notations) where < u; v > runs in umi ni ; umaxi  vmi ni ; vmaxi
is
parametric{
function {X(u,v)},
function {Y(u,v)},
function {Z(u,v)}
<u_mini, v_mini>, <u_maxi, v_maxi>
[contained_by {box or sphere}]
[max_gradient m]
[accuracy alpha]
[precompute N x,y,z]
texture{...}
}

where the brackets mean that these parameter lay be forgotten since POV-Ray
assigns a default value to them.
Take care that the domain is denoted (as usual for a box ) by the extreme
points of the diagonal of the box, and not a pair of intervals.
Default value of accuracy is 0.0001. The documentation does not define
precisely this parameter, and as rendering is really very slow, the users would
have helped, in an concrete and simple situation how its value could help loose
less time...
The discussion of max_gradient is the same as before (in isosurface
section), and as before, it is important to give it a reasonable value. Of course,
here the gradient has not the same meaning as in isosurface section, since the
surface is defined by a parametrization and not an equation. The documentation
says (in section 3.4.5.1.10) that : its the maximum magnitude of all six partial
derivatives over the specified ranges of u and v. You have just to estimate an

66

CHAPTER 2. GEOMETRIC OBJECTS

upper bound of their absolute values, not necessarily the least. At least, you know
what max_gradient means...
The precompute parameters are used by POV-Ray like this. To represent
the surface, POV-Ray triangulates the image, this triangulation being the image
of a regular canonical triangulation of the rectangular domain, the same
triangulation as in section 2.6. But now, the bicubic parametrization of section
2.6 is replaced by .X; Y; Z/ D itself. Each elementary triangle .a; b; c/ of the
domain triangulation defines a triangle ..a/; .b/; .c//, and POV-Ray has to
determine which light rays cut this last triangle. If the value of the parameter
precompute is N , the values taken on a grid of 2N small rectangles by each
chosen coordinate (among x, y, z) are memorized, to accelerate the calculations.
A good value of this parameter is 4.
We give a famous example : the graph of the function of Calvert and
Vamanamurthy polynomial with only one critical point, strict local minimum
but not global minimum (see figure (2.36))

y D f .x; z/ D x 2 .1 C z/3 C z 2 :

The code is

Figure 2.36: Graph of Calvert and Vamanamurthy drawn with Parametric


(Calvert-Parametric.pov)

2.9. PARAMETRIC SURFACES

parametric{
function {u},
function {u*u*(1+v)*(1+v)*(1+v)+v*v},
function {v}
<-2, -2>, <2, 2>
contained_by {box{<-4,-1,-4>,<4,4,4>}}
accuracy 0.001
precompute 4 x,y,z
texture{...}
no_shadow
}

67

68

CHAPTER 2. GEOMETRIC OBJECTS

Bibliography
[C-L-OS] D. Cox, J. Little, D. OShea, Ideal, Varieties and Algorithms, UTM
Springer (1992)
[La-Si]

R. Langevin and J-C Sifre. Foliations of S3 by Dupin cyclides, in Foliations 2012, P. Walczak, J. A. Lopez, S. Hurder, R. Langevin, T. Suboi,
editors, Word Scientific (2013)

[La-Si2] R. Langevin and J-C Sifre. Foliations of S3 by Cyclides, preprint (2014)


[La-Si-Dru-Gar-Pa] R. Langevin, J-C. Sifre, L. Druoton , L. Garnier and
M. Paluszny. Gluing Dupin cyclides along circles, finding a cyclide
given three contact conditions, Preprint IMB, Dijon (2012).

69