Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Rotations and Translations

As mentioned previously, the CDL maintains a stack of reference frames, and constantly pushes and pops frames as you apply operations. There are only two operations which change the reference frame explicitly, Rotations and Translations.

Rotations

Rotations can take either four or nine arguments. If given nine arguments, it is assumed that you are inputting a full rotation matrix. This matrix will be checked, and an error will occur if the determinant is not +1. An example of a full rotation matrix follows.
Rotation( cos(a), -sin(a), 0, // a rotation in the XY plane
          sin(a),  cos(a), 0,
               0,       0, 1);
A much simpler notation is that of axis-angle, which is what results if you supply only four numbers. The first three specify the axis of the rotation, and the last supplies the angle. A positive angle results in a counter-clockwise rotation around the axis. The following is an example of an axis-angle rotation.
Rotation(0,0,1,a); // same rotation as above

Translations

Translations are of course a lot simpler, taking only three arguments, and simply translating our frame of reference by that amount.
Translation(0,1,2); // translate by +1 in y, +2 in z

Cave Canem

It is important to note that the operation name for both rotations and translations is the noun, note the verb. The following would both be syntax errors.
Rotate(1,0,0,pi); // No! Bad!
Translate(1,1,1); // Wrong!

Transforms

The tricky part of all this comes when you must think through a series of operations, and realize where you end up in world coordinates. Let's walk through one example. When sitting down to design a robot, it is often useful to have a pad of paper and a pen nearby to sketch out the rotations and translations.

Translation(0,0,1) {
  Rotation(0,0,1,pi/2) {
    Translation(1,0,0) {
      Rotation(1,0,0,pi) {
        /* where are we now?? */
    }
  }
}
At the reference frame of the last operation, the axis is centered at (0,1,1), with z (local) pointing in the direction of -z (world), x (local) pointing in +y (world), and y (local) pointing -x.

As you can imagine, for later utility, it is extremely beneficial to document your CDL code, stating exactly where your axes are pointing, after you have performed a group of transforms.


SimLib Reference Documentation