Matlab routines for Rotations


Return to voicebox home page


Rotation Conventions

In 3-dimensions, the x, y and z axes form a right-handed triple. A positive rotation of π/2 radians around one of these axes will rotate y->z, z->x or x->y respectively, i.e. it corresponds to a clockwise rotation when looking along the corresponding axis from the origin.

Euler Angles

Applying a sequence of rotations to an object can have one of four interpretations: (a) they can be viewed as rotating the object or as rotating the axes (or, equivalently, the camera) and (b) the rotation axes can remain fixed in space ("extrinsic") or can change with each rotation ("intrinsic"). The choice of interpretation affects the order and sign of the rotations. The four examples listed below all result in the same rotation matrix: in each case, multiplying by the rotation matrix converts a column vector containing the coordinates of an object-point  to its new value.

  1. [extrinsic+object]: m='zx', t=[0.1; 0.2]: keeping the axes fixed in space, rotate the object first around the z axis and then rotate it around the original x axis. This is the point of view from which the routines have been written.
  2. [intrinsic+object]: m='xz', t=[0.2; 0.1]: rotate the object  first around the z axis and then rotate it around the line on the object that was originally aligned with the x axis (i.e. the rotation axes have moved with the object).
  3. [extrinsic+axes]: m='xz', t=[-0.2; -0.1]: keeping the object fixed in space, rotate the frame of reference around the z axis and then rotate it around the original x axis (which has not moved relative to the object).
  4. [intrinsic+axes]: m='zx', t=[-0.1; -0.2]: keeping the object fixed in space, rotate the frame of reference around the z axis and then rotate it around the new position of the x axis.

To perform an arbitrary rotation, it is necessary to rotate about three axes in sequence. Consecutive rotations must be around different axes but the first and third axes may either be the same ("Proper Euler angles") or different ("Tait-Bryan angles"). In the aerospace field, the conventional axes orientations relative to an aeroplane are: x=forward, y=right, z=down. Using the intrinsic+object formulation and an axis order zyx, the three rotations are called yaw, pitch and roll.

There is a redundancy in the Euler angle representation:

  1. If the first and third axes are the same, e.g. m='zxz', then  t=[a; b; c] is equivalent to  t=[a+π; -b; c+π]
  2. If the first and third axes are different, e.g. m='xyz', then  t=[a; b; c] is equivalent to  t=[a+π; π-b; c+π]

Conversion Routines

Rotations can be represented in any of the eight forms listed below; each has a two-letter mnemonic given in the first column. The conversion routine from form xx to form yy is called v_rotxx2yy. The second column lists the parameters required: A,a,a,a denote matrix, vector, scalar and text arguments and the subscripts indicate their dimension. The ro and pl forms can be used in a n-dimensional space; the other forms are restricted to 3-dimensions. To visualize a rotation, call any of the routines without any output argument; a rotated cube will be plotted in 3D.

Code Params Convert from Convert to Description
ro Rn#n eu, pl, qr eu, pl, qr Rotation Matrix: This is an n by n rotation matrix. Multiplying the coordinates of an object by R gives the coordinates of the rotated object. [rotation matrix properties]
eu m,t3 qr, ro qr, ro Euler Angles: t contains a sequence of "euler angles" while m contains the sequence of axes around which the rotations should be performed (e.g. 'xzy' means rotate around x first). The axes are fixed in space and do not rotate with the object.
ax a3,t qr qr Axis of Rotation: the axis of rotation is a, while t gives the rotation angle in radians.
pl un,vn,t ro ro Plane of Rotation: The plane of rotation is that containing u and v while t gives the rotation angle in radians. If t is omitted, the rotation moves direction u to direction v.
lu l3,u3 ro ro Look and Up directions: The rotation moves direction l to the negative z-axis and direction u onto the y-z plane with a positive y component. This corresponds to a camera looking in direction l that has been rotated around its optical axis to make direction u upwards in the image.
qr q4 ax, eu, mr, qc, ro ax, eu, mr, qc, ro Real Quaternion Vector: q = [c; s*a] where c=cos(t/2), s=sin(t/2) and a is the axis of rotation. The values q and -q represent the same rotation. [quaternion properties]
mr Q4#4 qr qr Real Quaternion Matrix: A 4 by 4 real matrix whose first column is the real quaternion vector defined above. Multiplication of quaternion matrices is homomorphic to multiplication of the corresponding rotation matrices.
qc q2 mc, qr mc, qr Complex Quaternion Vector: A 2 element vector of the form a+jb  where [a; b] is the real quaternion vector defined above.
mc Q2#2 qc qc Complex Quaternion Matrix:  A 2 by 2 complex matrix whose first column is the complex quaternion vector defined above. Multiplication of quaternion matrices is homomorphic to multiplication of the corresponding rotation matrices.