Bill DeWitt (bdewitt@gateway.net) asked for more information about vrotate and other vector expressions.
This makes sense visually with the following scene:
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:
#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 } }
| p1 | p2 | p1,p2 | Orientation |
|---|---|---|---|
| +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 |
You can reorient objects with a few simple calulations and the matrix command:
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.
#macro Orient(v1,v2)
#local nz = vnormalize(v2 - v1);
#local nx = vnormalize(vcross(y,nx));
#local ny = vcross(nz,nx);
matrix
Thanks for watching.