Escolar Documentos
Profissional Documentos
Cultura Documentos
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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).
CONTENTS
2/2 C z 2
y2
1/..x C 2/2 C z 2
y2
1/
2 D 0;
CONTENTS
CONTENTS
CONTENTS
10
CONTENTS
Chapter 1
Use of POV-Ray
1.1
12
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.
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))
14
You include a file by
#include "[file name]"
1.2
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 .
15
y D < 0; 1; 0 >;
z D < 0; 0; 1 >
1.3
16
1.3.1
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>
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
:
Z D < sin ' cos ; sin ; cos ' cos > :
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
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
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
19
Figure 1.8: When the cameraman looks at a foot of a leg (Cubes-cone2.pov and
Camera-Cubes-Cone2.pov)
20
gives figure (1.11). As we see a little part of the blue cube and of the horizon,
21
1.3.3
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 ...
or
22
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.
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;
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 !.
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
1.4
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.
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 2
Geometric objects
2.1
Elementary solids
Figure 2.1:
solids2.pov)
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
28
The box
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 ...}}}
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).
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
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
30
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
31
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
2.4.1
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
32
33
2.4.2
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
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
35
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
36
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
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
}
37
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]}
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
n+1
p_0
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 :
pi
pi
2.5.3
f .1/ D q;
f 0.0/ D v;
f 0 .1/ D w:
(2.1)
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)
2.5.4
n+2
p_0
p_{n+1}
(2.4)
1
(2.5)
41
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:
2.5.5
4n
p_1
r_1
s_1
q_1
...
p_n
r_n
s_n
q_n
i0 .0/ D 3.ri
i .1/ D qi
pi /;
i0.1/ D 3.qi
(2.6)
si /:
(2.7)
2t 3; 3t .1
42
r1
s1
p1
q1
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
2.5.6
43
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}
(2.8)
(2.9)
1:
(2.10)
2.5.7
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}
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
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
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)
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
46
\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.
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.
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.
2.5.10
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.]}
48
Figure 2.21: A canal surface with linear spline, outside and inside (Canal-LinearSpline.pov and Canal-Linear-Spline-Inside.pov)
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.]}
49
2.5.11
With a great number of base points, it seems very smooth, see figure (2.23).
2.5.12
50
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
51
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
f .u; v/ D
3
3 X
X
ui v j pi;j ;
i D0 j D0
pi;j 2 Rk :
3 X
3
X
i D0 j D0
Bi .u/Bj .v/pi;j
(2.11)
52
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
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}
}
53
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
54
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)
>
;
2.7
2.7.1
Isosurfaces
Volume by isosurface
56
isosurface{
f(x,y,z)
threshold a
contained_by D
max_gradient m
[open]
}
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)
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).
2.8
2.8.1
Algebraic surfaces
Surface with poly and polynomial
59
2/2 C z 2
y2
1/..x C 2/2 C z 2
y2
1/
2 D 0;
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 : : :
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
}
2.8.2
62
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.
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
64
#declare epsilon = 0.01;
object{
intersection{
difference{poly{2,
poly{2,
}
difference{poly{2,
poly{2,
}
}
pigment{Black}
no_shadow
}
2.9
65
Parametric surfaces
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
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
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
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)
69