logo back up home forward   further reading more topics »

Maths - Using 4x4 matrix to represent rotation and translation

Prerequisites

Upto now we have used 3x3 matrices to represent rotations.

If you are not familiar with this subject you may like to look at the following pages first:

Combined Rotation and Translation using 4x4 matrix.

A 4x4 matrix can represent all affine transformations (including translation, rotation around origin, reflection, glides, scale from origin contraction and expansion, shear, dilation, spiral similarities). On this page we are mostly interested in representing "proper" isometries, that is, translation with rotation.

We can combine two sucsessive rotations about the origin by multiplying their matrices:

r00 r01 r02
r10 r11 r12
r20 r21 r22
=
ra00 ra01 ra02
ra10 ra11 ra12
ra20 ra21 ra22
*
rb00 rb01 rb02
rb10 rb11 rb12
rb20 rb21 rb22

We can combine two successive translations by adding their vectors:

t0
t1
t2
=
ta0
ta1
ta2
+
tb0
tb1
tb2

So how can we represent both rotation and translation in one transform matrix?

To do this we put the rotation matrix in columns and rows 0,1 and 2, we put the translation vector in the right column, the bottom row is 0,0,0,1.

r00 r01 r02 t0
r10 r11 r12 t1
r20 r21 r22 t2
0 0 0 1

 

 

 

 

 

 

 

 

To combine subsequent transforms we multiply the 4x4 matrices together. How is this multiplication of matrices equivalent to addition of the translation vectors? To show this we can multiply two matrices representing pure translation:

1 0 0 ta0
0 1 0 ta1
0 0 1 ta2
0 0 0 1
*
1 0 0 tb0
0 1 0 tb1
0 0 1 tb2
0 0 0 1

The multiplication of two 4x4 matrices is:

ma00*mb00 + ma01*mb10 + ma02*mb20 + ma03*mb30 ma00*mb01 + ma01*mb11 + ma02*mb21 + ma03*mb31 ma00*mb02 + ma01*mb12 + ma02*mb22 + ma03*mb32 ma00*mb03 + ma01*mb13 + ma02*mb23 + ma03*mb33
ma10*mb00 + ma11*mb10 + ma12*mb20 + ma13*mb30 ma10*mb01 + ma11*mb11 + ma12*mb21 + ma13*mb31 ma10*mb02 + ma11*mb12 + ma12*mb22 + ma13*mb32 ma10*mb03 + ma11*mb13 + ma12*mb23 + ma13*mb33
ma20*mb00 + ma21*mb10 + ma22*mb20 + ma23*mb30 ma20*mb01 + ma21*mb11 + ma22*mb21 + ma23*mb31 ma20*mb02 + ma21*mb12 + ma22*mb22 + ma23*mb32 ma20*mb03 + ma21*mb13 + ma22*mb23 + ma23*mb33
ma30*mb00 + ma31*mb10 + ma32*mb20 + ma33*mb30 ma30*mb01 + ma31*mb11 + ma32*mb21 + ma33*mb31 ma30*mb02 + ma31*mb12 + ma32*mb22 + ma33*mb32 ma30*mb03 + ma31*mb13 + ma32*mb23 + ma33*mb33

Substituting the values from the translation gives:

1*1 + 0*0 + 0*0 + ta0*0 1*0 + 0*1 + 0*0 + ta0*0 1*0 + 0*0 + 0*1 + ta0*0 1*tb0 + 0*tb1 + 0*tb2 + ta0*1
0*1 + 1*0 + 0*0 + ta1*0 0*0 + 1*1 + 0*0 + ta1*0 0*0 + 1*0 + 0*1 + ta1*0 0*tb0 + 1*tb1 + 0*tb2 + ta1*1
0*1 + 0*0 + 1*0 + ta2*0 0*0 + 0*1 + 1*0 + ta2*0 0*0 + 0*0 + 1*1 + ta2*0 0*tb0 + 0*tb1 + 1*tb2 + ta2*1
0*1 + 0*0 + 0*0 + 1*0 0*0 + 0*1 + 0*0 + 1*0 0*0 + 0*0 + 0*1 + 1*0 0*tb0 + 0*tb1 + 0*tb2 + 1*1

Removing any terms containing 0 gives,

1 0 0 tb0 + ta0
0 1 0 tb1 + ta1
0 0 1 tb2 + ta2
0 0 0 1

Which is the addition of the vectors as required?

Further Reading

You may be interested in other means to represent orientation and rotational quantities such as:


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover 3D Math Primer - Aimed at complete beginners to vector and matrix algebra.

Other Math Books

Commercial Software Shop

Where I can, I have put links to Amazon for commercial software, not directly related to the software project, but related to the subject being discussed, click on the appropriate country flag to get more details of the software or to buy it from them.

 

cover Dark Basic Professional Edition - It is better to get this professional edition

cover This is a version of basic designed for building games, for example to rotate a cube you might do the following:
make object cube 1,100
for x=1 to 360
rotate object 1,x,x,0
next x

cover Game Programming with Darkbasic - book for above software

Can you help?

Please send me any improvements to here. I would appreciate ideas to make the pages more useful including error correction, ideas for new pages, improvements to wording. It helps if you quote the full URL of the page.

 

progam

I am working on a project which uses these principles, if you would like to help me with this you are welcome to join in, here:

http://sourceforge.net/projects/mjbworld/

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2008 Martin John Baker - All rights reserved.