Maths - Rotation about Any Point

For two dimensional rotations about x,y we can represent it with the following 3×3 matrix:

r00 r01 x - r00*x - r01*y
r10 r11 y - r10*x - r11*y
0 0 1

This represents the same as rotating round the origin but offset by:

(- r00*x - r01*y, - r10*x - r11*y).

For three dimensional rotations about x,y we can represent it with the following 4×4 matrix:

r00 r01 r02 x - r00*x - r01*y - r02*z
r10 r11 r12 y - r10*x - r11*y - r12*z
r20 r21 r22 z - r20*x - r21*y - r22*z
0 0 0 1

This represents the same as rotating round the origin but offset by:

(- r00*x - r01*y - r02*z,- r10*x - r11*y - r12*z,- r20*x - r21*y - r22*z).

We will then go on to show that, in two dimensions, that the converse is also true. That is any combination of translation and rotation can be represented by a single rotation provided that we choose the correct point to rotate it around.

Combined Rotation and Translation

In order to calculate the rotation about any arbitrary point we need to calculate its new rotation and translation. In other words rotation about a point is an 'proper' isometry transformation' which means that it has a linear and a rotational component.

Assume we have a matrix [R0] which defines a rotation about the origin:

We now want to apply this same rotation but about an arbitrary point P:

As we can see its orientation is the same as if it had been rotated about the origin, but it has been translated to a different point on space by the rotation.

In order to prove this and to calculate the amount of linear translation we need to replace:

With the following 3 simpler transforms which, when done in order, are equivalent:

So if we are using the global frame-of-reference (as explained here) then,

[resulting transform] = [third transform] * [second transform] * [first transform]

[resulting transform] = [+Px,+Py,+Pz] * [rotation] * [-Px,-Py,-Pz]

Note for matrix algebra, the order of operations is important, so these translations do not cancel out.

So matrix representing rotation about a given point is:

[R] = [T]-1 * [R0] * [T]

where:

[T]-1 = inverse transform = translation of point to origin

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1

[R0] = rotation about origin (if this is not clear see this discussion)

r00 r01 r02 0
r10 r11 r12 0
r20 r21 r22 0
0 0 0 1

[T] = translation of origin to point

1 0 0 -x
0 1 0 -y
0 0 1 -z
0 0 0 1

When these matrices are multiplied this will give the following result for rotation about x,y,z:

(to see all the steps see this page)

r00 r01 r02 x - r00*x - r01*y - r02*z
r10 r11 r12 y - r10*x - r11*y - r12*z
r20 r21 r22 z - r20*x - r21*y - r22*z
0 0 0 1

So the rotational components are the same but the rotation moves the position of the centre.

Isometry in 2 dimensions SE(2)

We now want to test the converse, that is, any combination of translation and rotation can be represented by a single rotation provided that we choose the correct point to rotate it around.

Imagine that we want to transform the solid body at 'A' into the solid body at 'B'

isometry in 2D

Then we can define a point on A (such as the centre-of-mass) and the corresponding point on B. We can then combine two transforms:

However, there is a second option, we can do the translation all in one rotation:

isometry in 2D

So, provided that we can find a suitable point to rotate around (in the above example shown as green point) we can do the translation and rotation in one operation. The point that we rotate around must by equidistant to the chosen point on each body, therefore it must lie on a line perpendicular to the line joining the two points. So is there always a point that we can find that will do any combination of translation and rotation? To find out we can take two extremes:

By putting the point at some distance between these we can get any rotation between 0 and 180 degrees. We can get negative angles by moving in the opposite direction along the line.

Therefore we can do any rotation, translation combination in one rotation.

Doing the rotation-translation in one operation like this can make some calculations simpler and we don't have to consider whether we do the rotation around its original position first and then the translation, or do the translation first and then the rotation about its final position, or do a translation to the mid point first, then the rotation about the mid position and then the final half translation.

Calculating Rotation Point

Given a translation (specified by a 2D vector) and a rotation (specified by a scalar angle in radians) how do we calculate the rotation point P ?

calculating rotation point

We know the points A and B and the angle at P which is theta.

sin(θ/2) = v/(2*r)

r = v/(2*sin(θ/2))

where:

We also know by Pythagoras:

(Px - Ax)2 + (Py - Ay)2 = r2
(Px - Bx)2 + (Py - By)2 = r2

This is getting a bit messy! Can we solve for P in vector coordinates?

I think I will have to give up with this approach and instead invert the matrix equations that we started with:

From the matrix derived above:

r00 r01 x - r00*x - r01*y
r10 r11 y - r10*x - r11*y
0 0 1

we get equations for offset:

Offsetx = x - r00*x - r01*y

Offsety = y - r10*x - r11*y

Where:

We want to solve for x and y so we take the inverse of:

Offsetx
Offsety
=
1-r00 -r01
-r10 1-r11
x
y

to give:

x
y
=
__1__
(1-r00)(1-r11) - r01r10
1-r11 r01
r10 1-r00
Offsetx
Offsety

In this case the rotation matrix is:

cos(θ) -sin(θ)
sin(θ) cos(θ)

where

θ = angle of rotation

which gives:

x
y
=
__1__
(1-cos(θ))(1-cos(θ)) + sin(θ)sin(θ)
1-cos(θ) -sin(θ)
sin(θ) 1-cos(θ)
Offsetx
Offsety

expanding out the determinant (and using sin2(θ)+cos2(θ)=1) gives:

x
y
=
__1__
2-2cos(θ)
1-cos(θ) -sin(θ)
sin(θ) 1-cos(θ)
Offsetx
Offsety

Check

We can check some special cases to see if we are getting reasonable results:

if θ = 0 then:

x
y
=
0 0
0 0
Offsetx
Offsety

If theta = 0 then the rotation point is at infinity.

if θ = 90° then:

x
y
=
__1__
2
1 -1
1 1
Offsetx
Offsety

so if the offset is at (1,0) then the rotation point is at (0.5,0.5)

rotate 90 degrees

if θ = 180° then:

x
y
= 1/4
2 0
0 2
Offsetx
Offsety

So we rotate around a point half way to B.

Combining Rotations about different Points

How do we apply two such rotations, one after the other, to produce a third rotation which is equivalent?

So imagine we apply a rotation of:

ra00 ra01
ra10 ra11

Centred at: (tax,tay,taz) followed by a rotation of:

rb00 rb01
rb10 rb11

Centred at: (tbx,tby,tbz)

The overall rotation is just the product of the two rotation matricies:

ra00*rb00 + ra01*rb10 ra00*rb01 + ra01*rb11
ra10*rb00+ ra11*rb10 ra10*rb01 + ra11*rb11
=
ra00 ra01
ra10 ra11
rb00 rb01
rb10 rb11

The offset will be:

tax - ra00*tax - ra01*tay + tbx - rb00*tbx - rb01*tby
tay - ra10*tax - ra11*tay + tbx - rb00*tbx - rb01*tby

So the overall centre will be:

x
y
=
__1__
(1-(ra00*rb00 + ra01*rb10))(1-(ra10*rb01 + ra11*rb11)) - (ra00*rb01 + ra01*rb11)(ra10*rb00+ ra11*rb10)
1-(ra10*rb01 + ra11*rb11) ra00*rb01 + ra01*rb11
ra10*rb00+ ra11*rb10 1-(ra00*rb00 + ra01*rb10)r00
tax - ra00*tax - ra01*tay + tbx - rb00*tbx - rb01*tby
tay - ra10*tax - ra11*tay + tbx - rb00*tbx - rb01*tby

Example

2D rotation example

An object transforms between the following positions -

What is the centre and angle of the single rotation to transform from A to B?

What is the centre and angle of the single rotation to transform from B to C?

What is the centre and angle of the single rotation to transform from A to C?

Isometry in 3 dimensions SE(3)

In 3 dimensions we can also represent an isometry as a rotation and a translation. Can we represent any isometry as a single rotation as we can in the 2D case as explained above?

In three dimensions there are three degrees of freedom of rotation but when we look for points that are equidistant to the centres of the objects pre and post transform position. The equidistant points lie on a plane which only has two degrees of freedom, but there is also the possibility to rotate around the line from the point. Therefore there are enough degrees of freedom to represent all possible isometrys.

So, imagine that we want to translate from point A (0,0) to point B (0,1), we can do this by rotating around any point in the plane x=0.5.

If for instance, we want to combine it with a rotation of 90° about the z axis, we can do this by rotating around (0.5,0.5,0):

rotate around z axis

If for instance, we want to combine it with a rotation of 90° about the y axis, we can do this by rotating around (0.5,0,0.5):

rotate around y axis

If for instance, we want to combine it with a rotation of 90° about the x axis, we have a problem!

rotate around x axis

We need to rotate it around the x axis to get the rotation we want and we need to rotate around the y or z axis to get the translation we want and these two don't seem to be compatible?

So when there is a component of rotation axis in the same direction as the translation vector the two don't seem to be compatible.

In order to represent all possible translations and rotations in one operation then we have to allow the rotation about a point together with a translation along a vector parallel to the rotation axis. The operation is represented by a line round the outside of a cylinder. This is known as a screw (see this page to take this subject further).


Code for rotation about a point

The following pages have code to calculate the affine translation when rotating about a point:


Further Reading

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

Or you may be interested in how these quantities are used to simulate physical objects:


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

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

Copyright (c) 1998-2014 Martin John Baker - All rights reserved - privacy policy.