Rotation Matrix Instructor

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6
At a glance
Powered by AI
Rotation matrices are used to characterize the orientation and rotation between different coordinate systems. They allow relating vectors expressed in different bases through matrix multiplication.

Rotation matrices can be used to relate vectors expressed in different bases by performing matrix multiplication. They also allow calculating dot products and angles between vectors in different bases.

Given the components of two vectors in different bases related by a rotation matrix, you can calculate the angle between the vectors by taking the dot product of their components in one of the bases and using the inverse cosine function.

Chapter 4

Rotation matrices
4.1 Basis orientation

The figure to the right shows two right-handed, unitary or-


thogonal bases, a and b whose basis vectors are ax , ay , az , and ay by bx
bx , by , bz , respectively. a bz
az x

A convenient way to store the orientation between right-handed


unitary orthogonal bases a and b is with the 3×3 rotation matrix
aRb , whose elements aRb (i, j=x, y, z) are defined in equation (1).
ij

The definition of the dot-product in equation (2.2) shows aRijb is aRb =
ij ai · bj = cos[  (ai , bj ) ] (1)
also equal to the cosine of the angle between ai and bj .a (2.2)

a
A rotation matrix is sometimes called a direction cosine matrix and (i, j = x, y, z)
its elements are called direction cosines.

aRb
A rotation matrix R is an orthogonal matrix which means that bx by bz
the transpose of R is equal to the inverse of R, i.e., R T = R -1 . ax ax · bx ax · by ax · bz
It is convenient to encapsulate the orientation information in a (2)
ay ay · bx ay · by ay · bz
rotation table that can be read either horizontally or vertically.a
az az · bx az · by az · bz
a
If one or both of the bases are non-orthogonal, a rotation matrix (not
a rotation table) stores information because the inverse of a non-orthogonal
bRa
a b -1  T
matrix is not its transpose. = R = aRb (3)

Equation (4) shows the rotation matrix aRd can be formed by


successive matrix multiplication of the aRb , bRc , and cRd rotation aRd = aRb ∗ bRc ∗ cRd (4)
matrices.

Uses for rotation matrices


Several uses for the rotation matrix aRb in geometry, statics, motion analysis, etc., include
• Determining the dot-product between the unit vectors ai and bj , (i, j=x, y, z)
• Calculating the angle between the unit vectors ai and bj , (i, j=x, y, z)
• Calculating the dot-product or cross-product between a vector v and a vector w, each of which
may be expressed in terms of ax , ay , az and/or bx , by , bz
• Expressing a vector written in terms of ax , ay , az in terms of bx , by , bz (or vice-versa)
• Using matrix multiplication to calculate other rotation matrices, e.g., aRd = aRb ∗ bRc ∗ cRd
• Relating the column matrix representation of a vector v expressed in basis a to the column matrix
representation of v expressed in basis b, i.e., [v]a = aRb [v]b
33
Example: Calculation of rotation matrix inverse

The following rotation matrix R relates two right-handed, orthogonal, unitary bases.
Calculate its inverse by-hand (no calculator) in less than 30 seconds.

   
0.3830 -0.6634 0.6428 0.3830 0.9237 -0.0058
R =  0.9237 0.2795 -0.2620  -
R =
1  -0.6634 0.2795 0.6941 
-0.0058 0.6941 0.7198 0.6428 -0.2620 0.7198

Example: Calculating angles between unit vectors

The following rotation table aRb relates right-handed, orthogonal, unit vectors ax , ay , az and bx , by , bz .
Calculate the angle between ax and bz to four (or more) significant digits.

aRb
az
bx by bz bz by
ax 0.9622502 -0.08418598 0.258819 ay
ay 0.1700841 0.9284017 -0.3303661
az -0.2124758 0.3619158 0.9076734
ax bx

 (ax , bz ) = 75

4.2 Rotation matrices and matrix multiplication

Two bases can be related with column matrices of unit vectors as

       
ax bx bx ax  -1
 ay  = a b
R by  or  by  = b a
R ay  where R
b a
= R
a b

az bz bz az

4.3 Rotation matrices - who cares? nz =bz


ny
N
In 2D (two dimensional) analysis, it is possible to characterize the orien- by
tation of a rigid body B in a reference frame N with a single angle, e.g., θ
the “pendulum” angle θ shown to the right. nx B
bx

In 3D (three dimensional) analysis, the orientation of a rigid body B (e.g.,


a spiraling, wobbling, football) in a reference frame N (e.g., a stadium) cannot
be characterized by a single angle. One convenient way to characterize the
orientation of the football in the stadium is with a rotation matrix.

Copyright 
c 1992-2009 by Paul Mitiguy 34 Chapter 4: Rotation matrices
ay
4.4 Example: Using a rotation matrix A
ax
The figure to the right shows a rod B connected to a fixed support A by a revolute az

joint. Right-handed sets of orthogonal unit vectors ax , ay , az and bx , by , bz , are L

fixed in A and B, respectively. The bRa rotation matrix is given to the right. θ bx
by
B
This example shows how to use a rotation matrix to express a vector in another
bz
basis and to perform dot-products and cross-products. For example, the bx row
of the bRa rotation table allows bx to be expressed in terms of ax , ay , az as
bRa ax ay az
bx = cos(θ) ax + sin(θ) ay bx cos(θ) sin(θ) 0
by -sin(θ) cos(θ) 0
The ax column of the bRa rotation table expresses ax in terms of bx , by , bz as
bz 0 0 1
ax = cos(θ) bx − sin(θ) by

The dot-product by · ax is simply the element in the by row and ax column of the bRa rotation table, i.e.,

by · ax = -sin(θ)

A more complicated dot-product example computes

(ax + 2 ay ) · (x bx + y by ) = x (ax · bx ) + y (ax · by ) + 2 x (ay · bx ) + 2 y (ay · by )


= x [cos(θ)] + y [-sin(θ)] + 2 x [sin(θ)] + 2 y [cos(θ)]

An example of doing a mixed-basis cross-product is

bx × (x ax + y ay ) = [cos(θ) ax + sin(θ) ay ] × (x ax + y ay ) = [y cos(θ) − x sin(θ)] az

A more complicated cross-product example computes

(ax + 2 ay ) × (x bx + y by ) = {[cos(θ) + 2 sin(θ)] bx + [2 cos(θ) − sin(θ)] by } × (x bx + y by )


= {y [cos(θ) + 2 sin(θ)] − x [2 cos(θ) − sin(θ)]} bz

Copyright 
c 1992-2009 by Paul Mitiguy 35 Chapter 4: Rotation matrices
nz

4.5 Rotation matrix example ny

The figure to the right shows a plate B connected by a revolute joint to a


rod A so that B can rotate freely about A’s axis. Rod A is connected to a N
az
fixed support N by a revolute joint. (Note: The revolute joints’ axes are ay

perpendicular not parallel.). qA

There are three sets of basis vectors, namely nx , ny , nz ; ax , ay , az ; and B

bx , by , bz , fixed in N , A, and B, respectively. The point of this problem


by
is to relate these sets of unit vectors with rotation matrices.a
qB bz

bx
a
Simple rotation matrices can be determined with little more than the definitions of
sine and cosine (SohCahToa).

4.5.1 Simple rotation matrix aRn


A rotation matrix aRn is called a simple rotation matrix when one of nz
the a basis vectors is always equal to one of the n basis vectors. In this az qA
example, aRn is a simple rotation matrix because ax = nx . ay
To calculate R , the rotation matrix relating the ax , ay , az and nx , ny , nz
a n
qA
unit vectors, it is helpful to redraw these vectors in a geometrically
suggestive way as shown to the right. After using the definitions of sine ny
ax=nx
and cosine to express each of ax , ay , az in terms of nx , ny , nz one can form
the aRn rotation table as shown below.
aRn nx ny nz
ax = nx ax 1 0 0
ay = cos(qA ) ny + sin(qA ) nz ay 0 cos(qA ) sin(qA )
az = -sin(qA ) ny + cos(qA ) nz az 0 -sin(qA ) cos(qA )

4.5.2 Simple rotation matrix bRa


In order to form bRa , the rotation matrix relating the bx , by , bz and ax , ay , az unit vectors, it is worthwhile
to see that bRa is a simple rotation matrix because bz is always equal to az . An easy way to form bRa is to
first redraw the vectors in a geometrically suggestive way by drawing the plane perpendicular to bz=az
(complete the figure below by adding ax , ay , and bx ). Then, use the definitions of sine and cosine to express
each of bx , by , bz in terms of ax , ay , az and complete the rotation table.1
bRa ax ay az
qB
bx cos(qB ) sin(qB ) 0
bx
qB by -sin(qB ) cos(qB ) 0
bz 0 0 1
bz = az

1
When two sets of basis vectors ax , ay , az and bx , by , bz are initially aligned and then the bases undergoes a simple
rotation about bi = ai by an angle θ, the bRa rotation matrix has a specific pattern. The bi row and ai column contains
cos(θ) ± sin(θ)
only 1 or 0 and the remaining elements have the pattern where the ± sign is plus (+) if the
± sin(θ) cos(θ)
unit vector is “hugged” (e.g, bx is between ax and ay ) or minus (-) when the unit vector is “left out in the cold” (e.g, by is
not between ax and ay ). [Analogy courtesy of Dr. Mandy Koop].
Copyright 
c 1992-2009 by Paul Mitiguy 36 Chapter 4: Rotation matrices
4.5.3 Matrix multiplication and bRn
The rotation matrix bRn which relates bx , by , bz with nx , ny , nz is formed R
b n
= R
b a
∗ R
a n
(4)
by matrix multiplication of bRa by aRn as shown to the right.
     
cos(qB ) sin(qB ) 0 1 0 0 cos(qB ) sin(qB ) cos(qA ) sin(qB ) sin(qA )
  
b n
R = -sin(qB ) cos(qB ) 0  ∗  0 cos(qA ) sin(qA )  =  -sin(qB ) cos(qB ) cos(qA ) cos(qB ) sin(qA ) 
0 0 1 0 -sin(qA ) cos(qA ) 0 -sin(qA ) cos(qA )

The bRn rotation table shown to the right is


b
Rn nx ny nz
copied from its associated rotation matrix. The bx cos(qB ) sin(qB ) cos(qA ) sin(qB ) sin(qA )
bRn rotation table is the starting point for most by -sin(qB ) cos(qB ) cos(qA ) cos(qB ) sin(qA )
relationships between bx , by , bz and nx , ny , nz . bz 0 -sin(qA ) cos(qA )

For example, reading the first row and first column of the rotation table gives

bx = cos(qB ) nx + sin(qB ) cos(qA ) ny + sin(qB ) sin(qA ) nz


nx = cos(qB ) bx + -sin(qB ) by + 0 bz

As shown below, the dot product bx · nz is simply the element in the bx row and nz column of the bRn
rotation table (the angle between bx and nz can be calculated via the definition of the dot-product).

bx · nz = sin(qB ) sin(qA )  (bx , nz ) = acos [sin(qB ) sin(qA )]

4.5.4 Calculating babyboot rotation matrices with Autolev


The Autolev input and output responses for the rotation matrices in Section 4.5 are shown below.
(1) % File: BabybootRotationMatrices.al
(2) %-------------------------------------- nz
(3) RigidFrame N % Reference frame
(4) RigidBody A % Upper rod
ny
(5) RigidBody B % Lower plate
(6) Variable qA % Pendulum angle A
(7) Variable qB % Plate angle
(8) %--------------------------------------
(9) A.RotateX( N, qA ) % A rotates "about +x" in N by qA N
-> (10) A_N = [1, 0, 0; 0, cos(qA), sin(qA); 0, -sin(qA), cos(qA)] az
ay
(11) B.RotateZ( A, qB ) % B rotates "about +z" in A by qB qA
-> (12) B_A = [cos(qB), sin(qB), 0; -sin(qB), cos(qB), 0; 0, 0, 1]
B
(13) BRotationMatrixN = B.GetRotationMatrix( N )
-> (14) BRotationMatrixN[1,1] = cos(qB)
-> (15) BRotationMatrixN[1,2] = sin(qB)*cos(qA) qB bz by
-> (16) BRotationMatrixN[1,3] = sin(qA)*sin(qB)
bx
-> (17) BRotationMatrixN[2,1] = -sin(qB)
-> (18) BRotationMatrixN[2,2] = cos(qA)*cos(qB)
-> (19) BRotationMatrixN[2,3] = sin(qA)*cos(qB)
-> (20) BRotationMatrixN[3,1] = 0
-> (21) BRotationMatrixN[3,2] = -sin(qA)
-> (22) BRotationMatrixN[3,3] = cos(qA)

4.6 What is an angle?


As described in Section ??, distance is the measure of space between two points. The rotational analog
to distance is angle, defined as the measure of the sweep between two vectors. For example:
Copyright 
c 1992-2009 by Paul Mitiguy 37 Chapter 4: Rotation matrices
Angle between two vectors b θ
The angle θ between two vectors a and b can be calculated from equa- a
a· b ◦
tion (2.2) as θ = acos( |a| |b| ) where the acos function returns 0 ≤ θ ≤ 180 .

Angle between two lines


θ
The angle θ between two lines is defined as the smallest angle between all
vectors aligned with the lines, hence 0 ≤ θ ≤ 90◦ .
b a
Angle between a vector and a plane θ
The angle θ between a vector a and a plane perpendicular to a vector b
is θ = 90◦ −  (a, b), where  (a, b) is the angle between a and b.
Alternately, if b points oppositely so a · b < 0, θ =  (a, b) − 90◦ .

Using three vectors (or two vectors and a sense) an angle θ can be calculated with the atan2 function
described in Section 1.6.4 so that -180 ≤ θ ≤ 180◦ . By using wrap, θ may have values -∞ < θ < +∞.
It is worth reiterating that, like distances, angles are inherently positive quantities. Angles may be
regarded as negative when one associates a sense with their value. For example, one may measure a
distance from sea level as 10 m. Alternately, one may say the distance from sea-level is -10 m by implying
that a upward sense is positive. Similarly, angles measurements are inherently positive, but an angle may
be regarded as negative when a sense is associated with the angle (e.g., counter-clockwise is positive).
Historically, angles (e.g., used by the ancient Greeks) predate negative numbers (in widespread use by
Europeans in 1700 A.D.) by thousands of years.

Copyright 
c 1992-2009 by Paul Mitiguy 38 Chapter 4: Rotation matrices

You might also like