The POV-Ray Cyclopedia

Bill DeWitt (bdewitt@gateway.net) asked for more information about vrotate and other vector expressions.


The vcross expression in incredibly useful in orienting objects on the screen. The manual states that vcross "returns a vector that is the vector cross product of the two vectors. The resulting vector is perpendicular to the two original vectors and its length is proportional to the angle between them."

This makes sense visually with the following scene:

#declare p1 = <1,0,0>;
#declare p2 = <0,0,1>;
#declare p3 = vcross(p1,p2);
#declare p4 = vcross(p2,p1);

cylinder { <0,0,0> p1 0.025
           pigment { rgb <1,0,0> }
           finish { phong 1 } }

cylinder { <0,0,0> p2 0.025
           pigment { rgb <1,1,0> }
           finish { phong 1 } }

cylinder { <0,0,0> p4 0.025
           pigment { rgb <0,0,1> }
           finish { phong 1 } }
           
cylinder { <0,0,0> p3 0.025
           pigment { rgb <1,0,1> }
           finish { phong 1 } }
By adjusting p1 and p2 to various coordinates that match with +x,-x,+y,-y,+z,-z, you will see how they work together. The order that we pass the two vectors gives us two opposite vectors:

p1p2p1,p2Orientation
+x+y+z Right & Up gives Forward
+x+z-y Right & Forward gives Down
+y+z+x Up & Forward gives Right
+y+x-z Up & Right gives Back
+z+x+y Forward & Right give Up
+z+y-x Forward & Up give Left
The Orientation list is how I commonly think of objects, like the camera, the forward vector is towards positive z, the up (sky) vector is towards positive y, and the right vector is torwards positive x. Once I've established these basics I can twist and turn the object, reorient, or do whatever I'd like to it.

You can reorient objects with a few simple calulations and the matrix command:

#macro Orient(v1,v2)
  #local nz = vnormalize(v2 - v1);
  #local nx = vnormalize(vcross(y,nx));
  #local ny = vcross(nz,nx);
  matrix 
#end
To use this, build an object as I described above around the Origin, then apply this mactro. It places the object at point v1, pointing towards v2.


Send feedback, or head back to the Cyclopedia.

Thanks for watching.