Previous page Next page

Infinite Solid Primitives

There are five polynomial primitive shapes that are possibly infinite and do not respond to automatic bounding. They are plane, cubic, poly, quadric and quartic. They do have a well defined inside and may be used in CSG and inside a clipped_by statement. As with all shapes they can be translated, rotated and scaled.

Plane

The plane primitive is a simple way to define an infinite flat surface. The plane is specified as follows:

PLANE:
plane { <Normal>, Distance [OBJECT_MODIFIERS...] }

The <Normal> vector defines the surface normal of the plane. A surface normal is a vector which points up from the surface at a 90 degree angle. This is followed by a float value that gives the distance along the normal that the plane is from the origin (that is only true if the normal vector has unit length; see below). For example:

  plane { <0, 1, 0>, 4 }

This is a plane where straight up is defined in the positive y-direction. The plane is 4 units in that direction away from the origin. Because most planes are defined with surface normals in the direction of an axis you will often see planes defined using the x, y or z built-in vector identifiers. The example above could be specified as:

  plane { y, 4 }

The plane extends infinitely in the x- and z-directions. It effectively divides the world into two pieces. By definition the normal vector points to the outside of the plane while any points away from the vector are defined as inside. This inside/outside distinction is important when using planes in CSG and clipped_by. It is also important when using fog or atmospheric media. If you place a camera on the "inside" half of the world, then the fog or media will not appear. Such issues arise in any solid object but it is more common with planes. Users typically know when they've accidentally placed a camera inside a sphere or box but "inside a plane" is an unusual concept. You can reverse the inside/outside properties of an object by adding the object modifier inverse. See "Inverse" and "Empty and Solid Objects" for details.

A plane is called a polynomial shape because it is defined by a first order polynomial equation. Given a plane:

  plane { <A, B, C>, D }

it can be represented by the equation A*x + B*y + C*z - D*sqrt(A2 + B2 + C2) = 0.

Therefore our example plane{y,4} is actually the polynomial equation y=4. You can think of this as a set of all x, y, z points where all have y values equal to 4, regardless of the x or z values.

This equation is a first order polynomial because each term contains only single powers of x, y or z. A second order equation has terms like x2, y2, z2, xy, xz and yz. Another name for a 2nd order equation is a quadric equation. Third order polys are called cubics. A 4th order equation is a quartic. Such shapes are described in the sections below.

Poly, Cubic and Quartic

Higher order polynomial surfaces may be defined by the use of a poly shape. The syntax is

POLY:
poly { Order, <A1, A2, A3,... An> [POLY_MODIFIERS...] }
POLY_MODIFIERS:
sturm | OBJECT_MODIFIER

where Order is an integer number from 2 to 7 inclusively that specifies the order of the equation. A1, A2, ... An are float values for the coefficients of the equation. There are m such terms where

n = ((Order+1)*(Order+2)*(Order+3))/6.

The cubic object is an alternate way to specify 3rd order polys. Its syntax is:

CUBIC:
cubic { <A1, A2, A3,... A20> [POLY_MODIFIERS...] }

Also 4th order equations may be specified with the quartic object. Its syntax is:

QUARTIC:
quartic { <A1, A2, A3,... A35> [POLY_MODIFIERS...] }

The following table shows which polynomial terms correspond to which x,y,z factors. Remember cubic is actually a 3rd order polynomial and quartic is 4th order.

 

2nd

3rd

4th

5th

6th

7th

   

5th

6th

7th

   

6th

7th

A1

x2

x3

x4

x5

x6

x7

 

A41

y3

xy3

x2y3

 

A81

z3

xz3

A2

xy

x2y

x3y

x4y

x5y

x6y

 

A42

y2z3

xy2z3

x2y2z3

 

A82

z2

xz2

A3

xz

x2z

x3z

x4z

x5z

x5z

 

A43

y2z2

xy2z2

x2y2z2

 

A83

z

xz

A4

x

x2

x3

x4

x5

x5

 

A44

y2z

xy2z

x2y2z

 

A84

1

x

A5

y2

xy2

x2y2

x3y2

x4y2

x5y2

 

A45

y2

xy2

x2y2

 

A85

 

y7

A6

yz

xyz

x2yz

x3yz

x4yz

x5yz

 

A46

yz4

xyz4

x2yz4

 

A86

 

y6z

A7

y

xy

x2y

x3y

x4y

x5y

 

A47

yz3

xyz3

x2yz3

 

A87

 

y6

A8

z2

xz2

x2z2

x3z2

x4z2

x5z2

 

A48

yz2

xyz2

x2yz2

 

A88

 

y5z2

A9

z

xz

x2z

x3z

x4z

x5z

 

A49

yz

xyz

x2yz

 

A89

 

y5z

A10

1

x

x2

x3

x4

x5

 

A50

y

xy

x2y

 

A90

 

y5

A11

 

y3

xy3

x2y3

x3y3

x4y3

 

A51

z5

xz5

x2z5

 

A91

 

y4z3

A12

 

y2z

xy2z

x2y2z

x3y2z

x4y2z

 

A52

z4

xz4

x2z4

 

A92

 

y4z2

A13

 

y2

xy2

x2y2

x3y2

x4y2

 

A53

z3

xz3

x2z3

 

A93

 

y4z

A14

 

yz2

xyz2

x2yz2

x3yz2

x4yz2

 

A54

z2

xz2

x2z2

 

A94

 

y4

A15

 

yz

xyz

x2yz

x3yz

x4yz

 

A55

z

xz

x2z

 

A95

 

y3z4

A16

 

y

xy

x2y

x3y

x4y

 

A56

1

x

x2

 

A96

 

y3z3

A17

 

z3

xz3

x2z3

x3z3

x4z3

 

A57

 

y6

xy6

 

A97

 

y3z2

A18

 

z2

xz2

x2z2

x3z2

x4z2

 

A58

 

y5z

xy5z

 

A98

 

y3z

A19

 

z

xz

x2z

x3z

x4z

 

A59

 

y5

xy5

 

A99

 

y3

A20

 

1

x

x2

x3

x4

 

A60

 

y4z2

xy4z2

 

A100

 

y2z5

A21

   

y4

xy4

x2y4

x3y4

 

A61

 

y4z

xy4z

 

A101

 

y2z4

A22

   

y3z

xy3z

x2y3z

x3y3z

 

A62

 

y4

xy4

 

A102

 

y2z3

A23

   

y3

xy3

x2y3

x3y3

 

A63

 

y3z3

xy3z3

 

A103

 

y2z2

A24

   

y2z2

xy2z2

x2y2z2

x3y2z2

 

A64

 

y3z2

xy3z2

 

A104

 

y2z

A25

   

y2z

xy2z

x2y2z

x3y2z

 

A65

 

y3z

xy3z

 

A105

 

y2

A26

   

y2

xy2

x2y2

x3y2

 

A66

 

y3

xy3

 

A106

 

yz6

A27

   

yz3

xyz3

x2yz3

x3yz3

 

A67

 

y2z4

xy2z4

 

A107

 

yz5

A28

   

yz2

xyz2

x2yz2

x3yz2

 

A68

 

y2z3

xy2z3

 

A108

 

yz4

A29

   

yz

xyz

x2yz

x3yz

 

A69

 

y2z2

xy2z2

 

A109

 

yz3

A30

   

y

xy

x2y

x3y

 

A70

 

y2z

xy2z

 

A110

 

yz2

A31

   

z4

xz4

x2z4

x3z4

 

A71

 

y2

xy2

 

A111

 

yz

A32

   

z3

xz3

x2z3

x3z3

 

A72

 

yz5

xyz5

 

A112

 

y

A33

   

z2

xz2

x2z2

x3z2

 

A73

 

yz4

xyz4

 

A113

 

z7

A34

   

z

xz

x2z

x3z

 

A74

 

yz3

xyz3

 

A114

 

z6

A35

   

1

x

x2

x3

 

A75

 

yz2

xyz2

 

A115

 

z5

A36

     

y5

xy5

x2y5

 

A76

 

yz

xyz

 

A116

 

z4

A37

     

y4z

xy4z

x2y4z

 

A77

 

y

xy

 

A117

 

z3

A38

     

y4

xy4

x2y4

 

A78

 

z6

xz6

 

A118

 

z2

A39

     

y3z2

xy3z2

x2y3z2

 

A79

 

z5

xz5

 

A119

 

z

A40

     

y3z

xy3z

x2y3z

 

A80

 

z4

xz4

 

A120

 

1

Polynomial shapes can be used to describe a large class of shapes including the torus, the lemniscate, etc. For example, to declare a quartic surface requires that each of the coefficients (A1 ... A35) be placed in order into a single long vector of 35 terms.

As an example let's define a torus the hard way. A Torus can be represented by the equation:

x4 + y4 + z4 + 2 x2 y2 + 2 x2 z2 + 2 y2 z2 -

2 (r_02 + r_12) x2 + 2 (r_02 - r_12) y2 -

2 (r_02 + r_12) z2 + (r_02 - r_12)2 = 0

Where r_0 is the major radius of the torus, the distance from the hole of the donut to the middle of the ring of the donut, and r_1 is the minor radius of the torus, the distance from the middle of the ring of the donut to the outer surface. The following object declaration is for a torus having major radius 6.3 minor radius 3.5 (Making the maximum width just under 20).

  // Torus having major radius sqrt(40), minor radius sqrt(12)

  quartic {

    < 1,   0,   0,   0,   2,   0,   0,   2,   0,

   -104,   0,   0,   0,   0,   0,   0,   0,   0,

      0,   0,   1,   0,   0,   2,   0,  56,   0,

      0,   0,   0,   1,   0, -104,  0, 784 >

    sturm

  }

Poly, cubic and quartics are just like quadrics in that you don't have to understand what one is to use one. The file shapesq.inc has plenty of pre-defined quartics for you to play with.

Polys use highly complex computations and will not always render perfectly. If the surface is not smooth, has dropouts, or extra random pixels, try using the optional keyword sturm in the definition. This will cause a slower but more accurate calculation method to be used. Usually, but not always, this will solve the problem. If sturm doesn't work, try rotating or translating the shape by some small amount.

There are really so many different polynomial shapes, we can't even begin to list or describe them all. If you are interested and mathematically inclined, an excellent reference book for curves and surfaces where you'll find more polynomial shape formulas is:

"The CRC Handbook of Mathematical Curves and Surfaces"

David von Seggern

CRC Press, 1990

Quadric

The quadric object can produce shapes like paraboloids (dish shapes) and hyperboloids (saddle or hourglass shapes). It can also produce ellipsoids, spheres, cones, and cylinders but you should use the sphere, cone, and cylinder objects built into POV-Ray because they are faster than the quadric version. Note that you do not confuse "quaDRic" with "quaRTic". A quadric is a 2nd order polynomial while a quartic is 4th order. Quadrics render much faster and are less error-prone but produce less complex objects. The syntax is:

QUADRIC:
quadric { <A,B,C>,<D,E,F>,<G,H,I>,J [OBJECT_MODIFIERS...] }

Although the syntax actually will parse 3 vector expressions followed by a float, we traditionally have written the syntax as above where A through J are float expressions. These 10 float that define a surface of x, y, z points which satisfy the equation

A x2 + B y2 + C z2 + D xy + E xz + F yz + G x + H y + I z + J = 0

Different values of A, B, C, ... J will give different shapes. If you take any three dimensional point and use its x, y and z coordinates in the above equation the answer will be 0 if the point is on the surface of the object. The answer will be negative if the point is inside the object and positive if the point is outside the object. Here are some examples:

X2 + Y2 + Z2 - 1 = 0

Sphere

X2 + Y2 - 1 = 0

Infinite cylinder along the Z axis

X2 + Y2 - Z2 = 0

Infinite cone along the Z axis

The easiest way to use these shapes is to include the standard file shapes.inc into your program. It contains several pre-defined quadrics and you can transform these pre-defined shapes (using translate, rotate and scale) into the ones you want. For a complete list, see the file shapes.inc.

Previous page Next page