### Section 4.4.9
Surface of Revolution Object

Bottles, vases and glasses make nice objects in ray-traced scenes. We want to create a golden cup using the surface of revolution object (SOR object).

We first start by thinking about the shape of the final object. It is quite difficult to come up with a set of points that describe a given curve without the help of a modelling program supporting POV-Eay's surface of revolution object. If such a program is available we should take advantage of it.

The point configuration of our cup object.

We will use the point configuration shown in the figure above. There are eight points describing the curve that will be rotated about the y-axis to get our cup. The curve was calculated using the method described in the reference section (see "Surface of Revolution").

Now it is time to come up with a scene that uses the above SOR object. We edit a file called sordemo.pov and enter the following text.

      #include "colors.inc"
      #include "golds.inc"

      global_settings { assumed_gamma 2.2 }

      camera {
        location <10, 15, -20>
        look_at <0, 5, 0>
        angle 45
      }

      background { color rgb<0.2, 0.4, 0.8>  }

      light_source { <100, 100, -100> color rgb 1 }

      plane { y, 0
        pigment { checker color Red, color Green scale 10 }
      }

      sor {
        8,
        <0.0,  -0.5>,
        <3.0,   0.0>,
        <1.0,   0.2>,
        <0.5,   0.4>,
        <0.5,   4.0>,
        <1.0,   5.0>,
        <3.0,  10.0>,
        <4.0,  11.0>
        texture { T_Gold_1B }
      }

The scene contains our cup object resting on a checkered plane. Tracing this scene at a resolution of 320x200 results in the image below.

A surface of revolution object.

The surface of revolution is described by starting with the number of points followed by the points with ascending heights. Each point determines the radius the curve for a given height. E. g. the first point tells POV-Ray that at height -0.5 the radius is 0. We should take care that each point has a larger height than its predecessor. If this is not the case the program will abort with an error message.

### Section 4.4.10
Text Object

Creating text objects using POV-Ray always used to mean that the letters had to be built either from CSG, a painstaking process or by using a black and white image of the letters as a height field, a method that was only somewhat satisfactory. Now, for POV-Ray 3.0, a new primitive has been introduced that can use any TrueType font to create text objects. These objects can be used in CSG, transformed and textured just like any other POV primitive.

For this tutorial, we will make two uses of the text object. First, let's just make some block letters sitting on a checkered plane. Any TTF font should do, but for this tutorial, we will use the ones bundled with POV-Ray 3.0.

We create a file called textdemo.pov and edit it as follows:

      #include "colors.inc"

      camera {
        location <0, 1, -10>
        look_at 0
        angle 35
      }

      light_source { <500,500,-1000> White }

      plane { y,0
        pigment { checker Green White }
      }

Now let's add the text object. We will use the font timrom.ttf and we will create the string POV-RAY 3.0. For now, we will just make the letters red. The syntax is very simple. The first string in quotes is the font name, the second one is the string to be rendered. The two floats are the thickness and offset values. The thickness float determines how thick the block letters will be. Values of .5 to 2 are usually best for this. The offset value will add to the kerning distance of the letters. We will leave this a 0 for now.

      text { ttf "timrom.ttf" "POV-RAY 3.0" 1, 0
        pigment { Red }
      }

Rendering this at 200x150 -A, we notice that the letters are off to the right of the screen. This is because they are placed so that the lower left front corner of the first letter is at the origin. To center the string we need to translate it -x some distance. But how far? In the docs we see that the letters are all 0.5 to 0.75 units high. If we assume that each one takes about 0.5 units of space on the x-axis, this means that the string is about 6 units long (12 characters and spaces). Let's translate the string 3 units along the negative x-axis.

      text { ttf "timrom.ttf" "POV-RAY 3.0" 1, 0
        pigment { Red }
        translate -3*x
      }

That's better. Now let's play around with some of the parameters of the text object. First, let's raise the thickness float to something outlandish... say 25!

      text { ttf "timrom.ttf" "POV-RAY 3.0" 25, 0
        pigment { Red }
        translate -2.25*x
      }

Actually, that's kind of cool. Now let's return the thickness value to 1 and try a different offset value. Change the offset float from 0 to 0.1 and render it again.

Wait a minute?! The letters go wandering off up at an angle! That is not what the docs describe! It almost looks as if the offset value applies in both the x- and y-axis instead of just the x axis like we intended. Could it be that a vector is called for here instead of a float? Let's try it. We replace 0.1 with 0.1*x and render it again.

That works! The letters are still in a straight line along the x-axis, just a little further apart. Let's verify this and try to offset just in the y-axis. We replace 0.1*x with 0.1*y. Again, this works as expected with the letters going up to the right at an angle with no additional distance added along the x-axis. Now let's try the z-axis. We replace 0.1*y with 0.1*z. Rendering this yields a disappointment. No offset occurs! The offset value can only be applied in the x- and y-directions.

Let's finish our scene by giving a fancier texture to the block letters, using that cool large thickness value, and adding a slight y-offset. For fun, we will throw in a sky sphere, dandy up our plane a bit, and use a little more interesting camera viewpoint (we render the following scene at 640x480 +A0.2):

      #include "colors.inc"

      camera {
        location <-5,.15,-2>
        look_at <.3,.2,1>
        angle 35
      }

      light_source { <500,500,-1000> White }

      plane { y,0
        texture {
          pigment { SeaGreen }
          finish { reflection .35 specular 1 }
          normal { ripples .35 turbulence .5 scale .25 }
        }
      }

      text { ttf "timrom.ttf" "POV-RAY 3.0" 25, 0.1*y
        pigment { BrightGold }
        finish { reflection .25 specular 1 }
        translate -3*x
      }

      #include "skies.inc"

      sky_sphere { S_Cloud5 }

Let's try using text in a CSG object. We will attempt to create an inlay in a stone block using a text object. We create a new file called textcsg.pov and edit it as follows:

      #include "colors.inc"
      #include "stones.inc"

      background { color rgb 1 }

      camera {
        location <-3, 5, -15>
        look_at 0
        angle 25
      }

      light_source { <500,500,-1000> White }

Now let's create the block. We want it to be about eight units across because our text string (POV-RAY 3.0) is about six units long. We also want it about four units high and about one unit deep. But we need to avoid a potential coincident surface with the text object so we will make the first z-coordinate 0.1 instead of 0. Finally, we will give this block a nice stone texture.

      box { <-3.5, -1, 0.1>, <3.5, 1, 1>
        texture { T_Stone10 }
      }

Next, we want to make the text object. We can use the same object we used in the first tutorial except we will use slightly different thickness and offset values.

      text { ttf "timrom.ttf" "POV-RAY 3.0" 0.15, 0
        pigment { BrightGold }
        finish { reflection .25 specular 1 }
        translate -3*x
      }

We remember that the text object is placed by default so that its front surface lies directly on the x-y-plane. If the front of the box begins at z=0.1 and thickness is set at 0.15, the depth of the inlay will be 0.05 units. We place a difference block around the two objects.

      difference {
        box { <-3.5, -1, 0.1>, <3.5, 1, 1>
          texture { T_Stone10 }
        }
        text { ttf "timrom.ttf" "POV-RAY 3.0" 0.15, 0
          pigment { BrightGold }
          finish { reflection .25 specular 1 }
          translate -3*x
        }
      }

Text carved from stone.

We render this at 200x150 -A. We can see the inlay clearly and that it is indeed a bright gold color. We re-render at 640x480 +A0.2 to see the results more clearly, but be forewarned... this trace will take a little time.

### Section 4.4.11
Torus Object

A torus can be thought of as a donut or an inner-tube. It is a shape that is vastly useful in many kinds of CSG so POV-Ray has adopted this 4th order quartic polynomial as a primitive shape. The syntax for a torus is so simple that it makes it a very easy shape to work with once we learn what the two float values mean. Instead of a lecture on the subject, let's create one and do some experiments with it.

We create a file called tordemo.pov and edit it as follows:

      #include "colors.inc"

      camera {
        location <0, .1, -25>
        look_at 0
        angle 30
      }

      background { color Gray50 } // to make the torus easy to see

      light_source{ <300, 300, -1000> White }

      torus { 4, 1        // major and minor radius
        rotate -90*x      // so we can see it from the top
        pigment { Green }
      }

We trace the scene. Well, it's a donut alright. Let's try changing the major and minor radius values and see what happens. We change them as follows:

      torus { 5, .25      // major and minor radius

That looks more like a hula-hoop! Let's try this:

      torus { 3.5, 2.5    // major and minor radius

Whoa! A donut with a serious weight problem!

With such a simple syntax, there isn't much else we can do to a torus besides change its texture... or is there? Let's see...

Torii are very useful objects in CSG. Let's try a little experiment. We make a difference of a torus and a box:

      difference {
        torus { 4, 1
          rotate x*-90  // so we can see it from the top
        }
        box { <-5, -5, -1>, <5, 0, 1> }
        pigment { Green }
      }

Interesting... a half-torus. Now we add another one flipped the other way. Only, let's declare the original half-torus and the necessary transformations so we can use them again:

      #declare Half_Torus = difference {
        torus { 4, 1
          rotate -90*x  // so we can see it from the top
        }
        box { <-5, -5, -1>, <5, 0, 1> }
        pigment { Green }
      }

      #declare Flip_It_Over = 180*x

      #declare Torus_Translate = 8  // twice the major radius

Now we create a union of two Half_Torus objects:

      union {
        object { Half_Torus }
        object { Half_Torus
          rotate Flip_It_Over
          translate Torus_Translate*x
        }
      }

This makes an S-shaped object, but we can't see the whole thing from our present camera. Let's add a few more links, three in each direction, move the object along the +z-direction and rotate it about the +y-axis so we can see more of it. We also notice that there appears to be a small gap where the half torii meet. This is due to the fact that we are viewing this scene from directly on the x-z-plane. We will change the camera's y-coordinate from 0 to 0.1 to eliminate this.

      union {
        object { Half_Torus }
        object { Half_Torus
          rotate Flip_It_Over
          translate x*Torus_Translate
        }
        object { Half_Torus
          translate x*Torus_Translate*2
        }
        object { Half_Torus
          rotate Flip_It_Over
          translate x*Torus_Translate*3
        }
        object { Half_Torus
          rotate Flip_It_Over
          translate -x*Torus_Translate
        }
        object { Half_Torus
          translate -x*Torus_Translate*2
        }
        object { Half_Torus
          rotate Flip_It_Over
          translate -x*Torus_Translate*3
        }
        object { Half_Torus
          translate -x*Torus_Translate*4
        }
        rotate y*45
        translate z*20
      }

Rendering this we see a cool, undulating, snake-like something-or-other. Neato. But we want to model something useful, something that we might see in real life. How about a chain?

Thinking about it for a moment, we realize that a single link of a chain can be easily modeled using two half toruses and two cylinders. We create a new file. We can use the same camera, background, light source and declared objects and transformations as we used in tordemo.pov:

      #include "colors.inc"

      camera {
        location <0, .1, -25>
        look_at 0
        angle 30
      }

      background { color Gray50 }

      light_source{ <300, 300, -1000> White }

      #declare Half_Torus = difference {
        torus { 4,1
          sturm
          rotate x*-90  // so we can see it from the top
        }
        box { <-5, -5, -1>, <5, 0, 1> }
        pigment { Green }
      }

      #declare Flip_It_Over = x*180

      #declare Torus_Translate = 8

Now, we make a complete torus of two half toruses:

      union {
        object { Half_Torus }
        object { Half_Torus rotate Flip_It_Over }
      }

This may seem like a wasteful way to make a complete torus, but we are really going to move each half apart to make room for the cylinders. First, we add the declared cylinder before the union:

      #declare Chain_Segment = cylinder { <0, 4, 0>, <0, -4, 0>, 1
        pigment { Green }
      }

We then add two chain segments to the union and translate them so that they line up with the minor radius of the torus on each side:

      union {
        object { Half_Torus }
        object { Half_Torus rotate Flip_It_Over }
        object { Chain_Segment translate  x*Torus_Translate/2 }
        object { Chain_Segment translate -x*Torus_Translate/2 }
      }

Now we translate the two half toruses +y and -y so that the clipped ends meet the ends of the cylinders. This distance is equal to half of the previously declared Torus_Translate:

      union {
        object { Half_Torus
          translate y*Torus_Translate/2
        }
        object { Half_Torus
          rotate Flip_It_Over
          translate -y*Torus_Translate/2
        }
        object { Chain_Segment
          translate x*Torus_Translate/2
        }
        object { Chain_Segment
          translate -x*Torus_Translate/2
        }
      }

We render this and viola! A single link of a chain. But we aren't done yet! Whoever heard of a green chain? We would rather use a nice metallic color instead. First, we remove any pigment blocks in the declared toruses and cylinders. Then we add the following before the union:

      #declare Chain_Gold = texture {
        pigment { BrightGold }
        finish {
          ambient .1
          diffuse .4
          reflection .25
          specular 1
          metallic
        }
      }

We then add the texture to the union and declare the union as a single link:

      #declare Link = union {
        object { Half_Torus
          translate y*Torus_Translate/2
        }
        object { Half_Torus
          rotate Flip_It_Over
          translate -y*Torus_Translate/2
        }
        object { Chain_Segment
          translate x*Torus_Translate/2
        }
        object { Chain_Segment
          translate -x*Torus_Translate/2
        }
        texture { Chain_Gold }
      }

Now we make a union of two links. The second one will have to be translated +y so that its inner wall just meets the inner wall of the other link, just like the links of a chain. This distance turns out to be double the previously declared Torus_Translate minus 2 (twice the minor radius). This can be described by the expression:

      Torus_Translate*2-2*y

We declare this expression as follows:

      #declare Link_Translate = Torus_Translate*2-2*y

In the object block, we will use this declared value so that we can multiply it to create other links. Now, we rotate the second link 90*y so that it is perpendicular to the first, just like links of a chain. Finally, we scale the union by 1/4 so that we can see the whole thing:

      union {
        object { Link }
        object { Link translate y*Link_Translate rotate y*90 }
        scale .25
      }

We render this and we will see a very realistic pair of links. If we want to make an entire chain, we must declare the above union and then create another union of this declared object. We must be sure to remove the scaling from the declared object:

      #declare Link_Pair =
      union {
        object { Link }
        object { Link translate y*Link_Translate rotate y*90 }
      }

Now we declare our chain:

      #declare Chain = union {
        object { Link_Pair}
        object { Link_Pair translate  y*Link_Translate*2 }
        object { Link_Pair translate  y*Link_Translate*4 }
        object { Link_Pair translate  y*Link_Translate*6 }
        object { Link_Pair translate -y*Link_Translate*2 }
        object { Link_Pair translate -y*Link_Translate*4 }
        object { Link_Pair translate -y*Link_Translate*6 }
      }

And finally we create our chain with a couple of transformations to make it easier to see. These include scaling it down by a factor of 1/10, and rotating it so that we can clearly see each link:

      object { Chain scale .1 rotate <0, 45, -45> }

The torus object can be used to create chains.

We render this and we should see a very realistic gold chain stretched diagonally across the screen.

Next Section
Table Of Contents