### 2.2.7 POV-Ray Coordinate System

Objects, lights and the camera are positioned using a typical 3D coordinate system. The usual coordinate system for POV-Ray has the positive y-axis pointing up, the positive x-axis pointing to the right and the positive z-axis pointing into the screen. The negative values of the axes point the other direction as shown in the images in section "Understanding POV-Ray's Coordinate System".

Locations within that coordinate system are usually specified by a three component vector. The three values correspond to the x, y and z directions respectively. For example, the vector `<1,2,3>` means the point that is one unit to the right, two units up and three units in front of the center of the universe at `<0,0,0>`.

Vectors are not always points though. They can also refer to an amount to size, move or rotate a scene element or to modify the texture pattern applied to an object.

The size, location, orientation, and deformation of items within the coordinate system is controlled by modifiers called transformations. The follow sub-sections describe the transformations and their usage.

#### 2.2.7.1 Transformations

The supported transformations are `rotate`, `scale`, and `translate`. They are used to turn, size and move an object or texture. A transformation matrix may also be used to specify complex transformations directly. Groups of transformations may be merged together and stored in a transformation identifier. The syntax for transformations is as follows.

    TRANSFORMATION:
        rotate <Rotate_Amt> | scale <Scale_Amt> |
        translate <Translate_Amt> | transform TRANSFORM_IDENTIFIER |
        transform { TRANSFORMATION_BLOCK...} |
        matrix <Val00, Val01, Val02,
            Val10, Val11, Val12,
            Val20, Val21, Val22,
            Val30, Val31, Val32>
    TRANSFORMATION_BLOCK:
        TRANSFORM_IDENTIFIER | TRANSFORMATION | inverse
    TRANSFORM_DECLARATION:
        #declare IDENTIFIER = transform { TRANSFORMATION_BLOCK...} |
        #local IDENTIFIER = transform { TRANSFORMATION_BLOCK...}

##### 2.2.7.1.1 Translate

Items may be moved by adding a `translate` modifier. It consists of the keyword `translate` followed by a vector expression. The three terms of the vector specify the number of units to move in each of the x, y and z directions. Translate moves the element relative to its current position. For example

     sphere { <10, 10, 10>, 1
      pigment { Green }
      translate <-5, 2, 1>
     }

will move the sphere from the location `<10,10,10>` to `<5,12,11>`. It does not move it to the absolute location `<-5,2,1>`. Translations are always relative to the item's location before the move. Translating by zero will leave the element unchanged on that axis. For example:

     sphere { <10, 10, 10>, 1
      pigment { Green }
      translate 3*x // evaluates to <3,0,0> so move 3 units
             // in the x direction and none along y or z
     }

##### 2.2.7.1.2 Scale

You may change the size of an object or texture pattern by adding a `scale` modifier. It consists of the keyword `scale` followed by a vector expression. The three terms of the vector specify the amount of scaling in each of the x, y and z directions.

Uneven scaling is used to stretch or squish an element. Values larger than one stretch the element on that axis while values smaller than one are used to squish it. Scale is relative to the current element size. If the element has been previously re-sized using scale then scale will size relative to the new size. Multiple scale values may used.

For example

     sphere { <0,0,0>, 1
      scale <2,1,0.5>
     }

will stretch and smash the sphere into an ellipsoid shape that is twice the original size along the x-direction, remains the same size in the y-direction and is half the original size in the z-direction.

If a lone float expression is specified it is promoted to a three component vector whose terms are all the same. Thus the item is uniformly scaled by the same amount in all directions. For example:

     object {
      MyObject
      scale 5 // Evaluates as <5,5,5> so uniformly scale
          // by 5 in every direction.
     }

When one of the scaling components is zero, POV-Ray changes this component to 1 since it assumes that 0 means no scaling in this direction. A warning "Illegal Value: Scale X, Y or Z by 0.0. Changed to 1.0." is printed then.

##### 2.2.7.1.3 Rotate

You may change the orientation of an object or texture pattern by adding a `rotate` modifier. It consists of the keyword `rotate` followed by a vector expression. The three terms of the vector specify the number of degrees to rotate about each of the x-, y- and z-axes.

Note: that the order of the rotations does matter. Rotations occur about the x-axis first, then the y-axis, then the z-axis. If you are not sure if this is what you want then you should only rotate on one axis at a time using multiple rotation statements to get a correct rotation.

     rotate <0, 30, 0>  // 30 degrees around Y axis then,
     rotate <-20, 0, 0> // -20 degrees around X axis then,
     rotate <0, 0, 10>  // 10 degrees around Z axis.

Rotation is always performed relative to the axis. Thus if an object is some distance from the axis of rotation it will not only rotate but it will orbit about the axis as though it was swinging around on an invisible string.

POV-Ray uses a left-handed rotation system. Using the famous "Computer Graphics Aerobics" exercise, you hold up your left hand and point your thumb in the positive direction of the axis of rotation. Your fingers will curl in the positive direction of rotation. Similarly if you point your thumb in the negative direction of the axis your fingers will curl in the negative direction of rotation. See "Understanding POV-Ray's Coordinate System" for an illustration.

##### 2.2.7.1.4 Matrix

The `matrix` keyword can be used to explicitly specify the transformation matrix to be used for objects or textures. Its syntax is:

    MATRIX:
        matrix <Val00, Val01, Val02,
            Val10, Val11, Val12,
            Val20, Val21, Val22,
            Val30, Val31, Val32>

Where `Val00` through `Val32` are float expressions enclosed in angle brackets and separated by commas.

Note: this is not a vector. It is a set of 12 float expressions.

These floats specify the elements of a 4 by 4 matrix with the fourth column implicitly set to `<0,0,0,1>`. At any given point P, P=<px, py, pz>, is transformed into the point Q, Q=<qx, qy, qz> by

qx = Val00 * px + Val10 * py + Val20 * pz + Val30

qy = Val01 * px + Val11 * py + Val21 * pz + Val31

qz = Val02 * px + Val12 * py + Val22 * pz + Val32

Normally you will not use the matrix keyword because it is less descriptive than the transformation commands and harder to visualize. However the matrix command allows more general transformation effects like shearing. The following matrix causes an object to be sheared along the y-axis.

     object {
      MyObject
      matrix < 1, 1, 0,
           0, 1, 0,
           0, 0, 1,
           0, 0, 0 >
     }

#### 2.2.7.2 Transformation Order

Because rotations are always relative to the axis and scaling is relative to the origin, you will generally want to create an object at the origin and scale and rotate it first. Then you may translate it into its proper position. It is a common mistake to carefully position an object and then to decide to rotate it. However because a rotation of an object causes it to orbit about the axis, the position of the object may change so much that it orbits out of the field of view of the camera!

Similarly scaling after translation also moves an object unexpectedly. If you scale after you translate the scale will multiply the translate amount.
For example

      translate <5, 6, 7>
      scale 4

will translate to `<20,24,28>` instead of `<5,6,7>`. Be careful when transforming to get the order correct for your purposes.

#### 2.2.7.3 Inverse Transform

      transform { scale <20,24,28> translate y*3  inverse }

An inverse transform does the opposite of what the transform would normally do, and can be used to "undo" transforms without messing around with huge numbers of transformations. To do the same without this `inverse`, you would have to duplicate each transform, change them to do the opposite of what they would normally do (for example `translate -y*3` instead of `translate y*3`)and reverse their order.

#### 2.2.7.4 Transform Identifiers

At times it is useful to combine together several transformations and apply them in multiple places. A transform identifier may be used for this purpose. Transform identifiers are declared as follows:

    TRANSFORM_DECLARATION:
      #declare IDENTIFIER = transform{ TRANSFORMATION... } |
      #local IDENTIFIER = transform{ TRANSFORMATION... }

Where IDENTIFIER is the name of the identifier up to 40 characters long and TRANSFORMATION is any valid transformation modifier. See "#declare vs. #local" for information on identifier scope. Here is an example...

      #declare MyTrans =
        transform {
          rotate THISWAY
          scale SOMUCH
          rotate -THISWAY
          scale BIGGER
          translate OVERTHERE
          rotate WAYAROUND
        }

A transform identifier is invoked by the `transform` keyword with or without brackets as shown here:

      object {
        MyObject              // Get a copy of MyObject
        transform MyTrans     // Apply the transformation
        translate -x*5        // Then move it 5 units left
      }
      object {
        MyObject              // Get another copy of MyObject
        transform { MyTrans } // Apply the same transformation
        translate x*5         // Then move this one 5 units right
      }

On extremely complex CSG objects with lots of components it may speed up parsing if you apply a declared transformation rather than the individual `translate`, `rotate`, `scale`, or `matrix` modifiers. The `transform` is attached just once to each component. Applying each individual `translate`, `rotate`, `scale`, or `matrix` modifiers takes longer. This only affects parsing - rendering works the same either way.

#### 2.2.7.5 Transforming Textures and Objects

When an object is transformed all textures attached to the object at that time are transformed as well. This means that if you have a `translate`, `rotate`, `scale`, or `matrix` modifier in an object before a texture, then the texture will not be transformed. If the transformation is after the texture then the texture will be transformed with the object. If the transformation is inside the `texture` statement then only the texture is affected. The shape remains the same. For example:

     sphere { 0, 1
      texture { Jade } // texture identifier from TEXTURES.INC
      scale 3          // this scale affects both the
                       // shape and texture
     }
     sphere { 0, 1
      scale 3          // this scale affects the shape only
      texture { Jade }
     }
     sphere { 0, 1
      texture {
       Jade
       scale 3        // this scale affects the texture only
      }
     }

Transformations may also be independently applied to pigment patterns and surface normal patterns.

Note: scaling a normal pattern not only affects the width and spacing. It does also affect the apparent height or depth of the bumps, for how to avoid this see Scaling normals.

For example:

     box { <0, 0, 0>, <1, 1, 1>
      texture {
       pigment {
        checker Red, White
        scale 0.25 // This affects only the color pattern
       }
       normal {
        bumps 0.3 // This specifies apparent height of bumps
        scale 0.2 // Scales diameter and space between bumps
                  // and also the height. Has no effect on
                  // color pattern.
       }
       rotate y*45 // This affects the entire texture but
      }            // not the object.
     }