PDA

View Full Version : Rotation matrix. How does it work?



Paolo De Leva
07-15-2005, 01:26 AM
Dear subscribers,

We have been recently discussing about a multi-purpose “general
transformation matrix” format, widely used in computer graphics to perform
many different kinds of geometrical transformations (including rotation,
translation, shearing, scaling and reflection). In biomechanics, a simple
orthonormal rotation matrix (3x3 in 3D) is perhaps more frequently used, for
several purposes (including transformation of the inertia tensor). That
matrix is also one of the “bricks” used to build a 4x4 “general
transformation matrix”. It has been called with several appropriate names:

ROTATION MATRIX
ORIENTATION MATRIX
ATTITUDE MATRIX

The rotation matrix is a wonderful and useful tool, and exactly
understanding in a visual, intuitive way how it performs its task is, in my
opinion, an enlightening exercise. In one of my previous postings I promised
to explain this, and I’ll do it now. In the following text, I will assume
that the reader knows what the unit vectors of a reference frame are, how a
scalar product can be used to find a projection of a vector on a Cartesian
axis, and how the rotation matrix is used to perform a transformation. I
will only explain what’s inside the magic box, i.e. how the product of a
rotation matrix by a vector works.

LEGENDA
A (x,y,z) A Cartesian reference frame
B (x’,y’,z’) Another Cartesian reference frame with
different orientation with respect to A
i, j, k The 3 unit vectors of A, each represented in B
i', j’, k’ The 3 unit vectors of B, each represented in A
V A vector
(a)V = [Vx; Vy; Vz] (3x1) Components of V with respect to A
(b)V = [Vx’; Vy’; Vz’] (3x1) Components of V with respect to B

NOTE: (a)V and (b)V are formatted as “column vectors”
(3x1 matrices)

There are two kinds of rotation matrices, both used to compute the
components of a vector V in a rotated reference system. Let’s make this
clear: a vector V is resolved into components with respect to (i.e.
“represented in”) a reference frame A. We need to determine its components
with respect to a new reference frame B. We can use two different kinds of
rotation matrixes (R and R’) and two different methods to perform the
transformation:

1) (b)V = R * (a)V (“pre-multiplication of a column vector”)
2) (b)V’ = (a)V’ * R’ (“post-multiplication of a row vector”)

In equation 2, (a)V’, (b)V’ and R’ are the transpose of (a)V, (b)V
and R. The two methods are perfectly equivalent. I believe most CG experts
prefer using method 2, and most biomechanists prefer using method 1. In the
following text, I will only explain method 1 (“pre-multiplication of column
vector”).

I am surprised that, in the biomechanics textbooks I have read, the
three basic equations from which the matrix is built are not shown. These
equations are just three dot products (see
http://kwon3d.com/theory/transform/transform.html):

Vx’ = i' * (a)V
Vy’ = j' * (a)V
Vz’ = k' * (a)V

It is truly enlightening to notice that each one of these dot
products determines the projection of vector V on a unit vector belonging to
B, the “final” reference frame. As a consequence, as you can see, the unit
vectors (i', j', k') of the "final" reference frame (B) are used in these
equations. In fact, the product of a matrix R by a vector V (R * V), is
defined as (and represents) the set of scalar products of V by each of the
ROWS of R. And the ROWS of the rotation matrix R contain the unit vectors of
B, the “FINAL” reference frame:

R = [i'; j’; k’]
(interpreted as orientation of B relative to A)

where “;” means “go to next row” (i.e. “line feed”), as in the
programming language MATLAB, and the three unit vectors are formatted as
“ROW vectors” (1x3 matrices).

Are you mixed up or do you think I am wrong? If you do, I do
understand why: unfortunately, almost everybody teaches and writes that the
matrix is built by inserting the unit vectors of A (i, j, k), the “INITIAL”
reference frame, in its COLUMNS:

R = [i, j, k]
(interpreted as orientation of A relative to B)

where “,” means “go to next column”, as in the programming language
MATLAB, and the three unit vectors are formatted as “COLUMN vectors” (3x1
matrices). And that’s correct as well. Notice that both equations are
correct, i.e.

R = [i'; j’; k’] = [i, j, k]

So, we have two different descriptions of the method used to “build”
R. They are both correct, but the first description allows you to understand
how the matrix works when used to perform the transformation. The second
does not.

The second description is useful for a practical purpose: typically,
you happen to measure i, j and k in frame B, rather than i', j’ and k’ in
frame A. I used general symbols in the above equations, and I think this is
useful, but in the most frequent application in biomechanics, the FINAL
frame B is the global frame (G), or world frame (W), or laboratory frame
(L), and the INITIAL frame A is the local frame (L, again) attached to a
body segment or bone (bone embedded frame or BEF), and motion analysis
systems measure the position of markers with respect to frame B, the global
and FINAL frame. In other words, although you can quite easily obtain the
ROWS of the rotation matrix (just by reading them after building the
matrix), you initially have direct information on its COLUMNS and you build
it by adding COLUMNS...

In sum, several experts suggest, without explaining why, that for
rotating a reference frame from A to B you actually need to know what's the
angle from B to A, i.e. from the FINAL to the INITIAL orientation! That may
seem a little bit crazy to a student, but hardly anybody cares to justify
it! It's the same as suggesting to read the time by measuring how much the
clock is rotated counter-CLOCKwise relative to its hands, without caring to
explain the reason why you did it! You just do it and show that, eventually,
it works and proves to be magically useful, but you don't explain why.
Several experts suggest using matrices like black magic boxes and are not
interested to explain to students how they work. The accent is on making
easy the practical application of matrices as magic boxes. It's a "just
press the switch" approach. It works, it is justifiable, it becomes even
elegant when a proper notation makes it easy to describe it, but...

I prefer understanding. It allows me to avoid mistakes. I am not
able to blindly remember a magic rule. I prefer to be aware of what I am
doing, to understand why I am pre-multiplying and why I need to insert unit
vectors of A in the matrix COLUMNS. I just need to know:

1) what projections I need,
2) how scalar products work, and
3) how the matrix products are defined.

In this case, understanding is not even difficult, as I may have
proved in this message. I hope that this contribution will be useful to many
students and teachers in biomechanics.

P.S. In my opinion, the most elegant and effective notation to write
transformation equations is that suggested by Cappozzo et al. (Gait and
posture 21, 2005, 186-196).


With kind regards,

Paolo de Leva
Sport Biomechanics
University Institute of Motor Sciences
Rome, Italy