x - y^3 + 3 cubic
x^3 + 3 x^2 y + 3 x y^2 + y^3 cubic
x^2 y^2 - 6 not cubic, in first term 2 + 2 > 3
y z - z x^2 - x y^2 - y z^3 cubic
3 cubic (but rather pointless)
Note also that the exponents in each terms are non-negative integers. For a better definition of polynomials see poly or just about any algebra text. The syntax for a cubic is as follows:
cubic {
<a0, a1, a2, . . . a19>
}
a0 through a19 are all floats. They are the coefficients for the general cubic equation in three variables:
a0 x^3 + a1 x^2 y + a2 x^2 z + a3 x^2 + a4 x y^2 + a5 x y z + a6 x y + a7 x z^2 + a8 x z + a9 x + a10 y^3 + a11 y^2 z + a12 y^2 + a13 y z^2 + a14 y z + a15 y + a16 z^3 + a17 z^2 + a18 z + a19 = 0
The second equation above would be defined by
cubic {
<1, 3, 0, 0, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>
}
Cubics are useful shapes as they can be used to smoothly join two curves together. See the section on tips and tricks for more information on this technique.
Calculations for cubics (as well as any type of poly) must be very accurate or the surface will appear strangely deformed. If you have a cubic that dessn't seem to be rendering correctly, the keyword sturm may be added to the definition to tell POV to use its more accurate (but unfortunately slower) Sturmian root solver. Also, sometimes the problem can be fixed by rotating, scaling, or translating the object by some small amount.
Cubics (like all polys) can be used in CSG as they have a defined inside and outside. The inside is defined to be all points where the equation is less than zero. The outside is all points where the equation is greater than zero. Points where the equation equals zero are on the surface. Note that cubics are considered infinite objects by POV, so they will not be optimized with automatic bounds.
plane {
<normal>, offset
}
<normal> is an <x, y, z> vector that describes the plane by giving a normal to its surface. By default, the plane goes through the origin. This is changed with the offset value. It is a float that translates the plane along its normal vector. It may be positive, negative, or zero, and can be used to position the plane anywhere in space. Here are some examples of planes:
plane {
y, 3
}
This plane is parallel to the x-z coordinate plane. It extents infinitely in both the x and z directions.
plane {
<1, 1, 1>, 0
}
This plane is diagonal and goes through the origin.
Planes are acutally a very simple (first order) poly. The primitive can also be represented by
plane {
<a, b, c>, d
}
which would represent the equation
a x + b y + c z = d
This is important because it defines the "inside" and "outside" of a plane for use in CSG. By this definition, the normal vector always points to the "outside" of the plane.
Very quickly, a polynomial is an expression that consists of
But anyway, the general syntax for poly is like this:
poly {
order, <a0, a1, . . . an>
}
order is a float which defines the order of the polynomial. order should be an integer between 2 and 7 inclusive. a0 through an are the coefficients for the generic polynomial equation of order order. The number of coefficients in the equation m is defined by the equation
m = (order + 1) * (order + 2) * (order + 3) / 6
Note that n = m - 1. This relationship can make defining seventh order polynomials by hand a real pain (they have 120 coefficients).
The other concern when defining polys is the order of the coefficients. This is not well covered in the POV-Ray documentation, but after some experimentation the pattern was determined. The following pseudocode segment will print out the terms in order:
for x : order -> 0
for y : order - x -> 0
for z : order - x - y -> 0
print "x^", x, " y^", y, " z^", z
As an example of this, the generic fifth order equation (all 56 terms) is
a0 x^5 + a1 x^4 y + a2 x^4 z + a3 x^4 + a4 x^3 y^2 + a5 x^3 y z + a6 x^3 y + a7 x^3 z^2 + a8 x^3 z + a9 x^3 + a10 x^2 y^3 + a11 x^2 y^2 z + a12 x^2 y^2 + a13 x^2 y z^2 + a14 x^2 y z + a15 x^2 y + a16 x^2 z^3 + a17 x^2 z^2 + a18 x^2 z + a19 x^2 + a20 x y^4 + a21 x y^3 z + a22 x y^3 + a23 x y^2 z^2 + a24 x y^2 z + a25 x y^2 + a26 x y z^3 + a27 x y z^2 + a28 x y z + a29 x y + a30 x z^4 + a31 x z^3 + a32 x z^2 + a33 x z + a34 x + a35 y^5 + a36 y^4 z + a37 y^4 + a38 y^3 z^2 + a39 y^3 z + a40 y^3 + a41 y^2 z^3 + a42 y^2 z^2 + a43 y^2 z + a44 y^2 + a45 y z^4 + a46 y z^3 + a47 y z^2 + a48 y z + a49 y + a50 z^5 + a51 z^4 + a52 z^3 + a53 z^2 + a54 z + a55 = 0
Ugh. This is definitely not something that one would want to type by hand. The cumbersomeness (cumbersomity?) of high order polys is the main limitation on their usefulness. POV comes with a number of predefined poly shapes; they can be found in shapesq.inc. The POV-Ray authors also recommend
The CRC Handbook of Mathematical Curves and Surfacesas a good resource for finding cool surface equations.
David von Seggern
CRC Press
1990
Another concern with high order polys is the extreme accuracy required to render them accurately. If you have a poly that seems to rendering incorrectly, you can include the keyword sturm in the object definition. This will tell POV to use its more accurate (but somewhat slower) Sturmian root solver.
All polys can be used in CSG and clipped_by constructs. The inside of the poly is defined to be all points with values (when plugged into the equation) is less than zero. Conversely, the outside is all points with values greater than zero. All points with values of zero are on the surface of the object. Note also that POV considers all polys of any order to be infinite objects (regardless of whether or not they actually are) and so it does not automatically bound them.
The syntax for a quadric is as follows:
quadric {
<a, b, c>,
<d, e, f>,
<g, h, i>,
j
}
a through j are all floats and correspond to the following second order poly equation:
ax^2 + by^2 + cz^2 + dxy + exz + fyz + gx + hy + iz + j = 0
Some examples of quadrics:
quadric { // an infinite cone opening in the x direction
<1, -1, -1>,
<0, 0, 0>,
<0, 0, 0>,
0
}
quadric { // a sphere of radius 3 centered at <3, 3, 3>
<1, 1, 1>,
<0, 0, 0>,
<-6, -6, -6>,
18
}
quadric { // a rotated cone
<1, 0, 1>,
<-2, 0, 0>,
<0, 0, 0>,
0
}
Well, you get the idea. There are actually quite a large number of useful shapes that can be generated with quadrics. This is nice because quadrics are easy to define and are fairly efficient to render.
As with all polys, accuracy is a factor in rendering quadrics. Although quadric surfaces will rarely cause problems, if you have one that's rendering incorrectly, you can throw in the keyword sturm to tell POV to use its slow but accurate Sturmian root solver.
Quadrics have a clearly defined inside and outside, and so can be used in CSG. They are considered to be infinite and so are not automatically bounded.
quartic {
<a0, a1, . . . a34>
}
Each of a0 through a34 is a float. The correspondence of these numbers to terms in the generic quartic equation is covered with the discussion of poly.
The Online POV-Ray Tutorial © 1996 The Online POV-Ray Tutorial ThinkQuest Team