# 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:

• translate about arbitrary point P (Px,Py,Pz).

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

• translate the arbitrary point to the origin (subtract P which is translate by -Px,-Py,-Pz)
• rotate about the origin (can use 3×3 matrix R0)
• then translate back. (add P which is translate by +Px,+Py,+Pz)

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:

 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' 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:

• Do a linear translation such that the point on 'A' is transformed to the point on 'B'.
• Do a rotation about the point so that the solid body is correctly transformed.

However, there is a second option, we can do the translation all in one rotation: 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:

• If the rotation point is exactly in the middle of the two objects then the object will be rotated by 180 degrees.
• If the rotating point is at infinity along the bisecting line then the object is translated only and the rotation will be zero.

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 ? 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:

• r = scalar distance of P from both A and B
• v = scalar distance of B from A
• θ = angle of rotation

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:

• Offset = linear distance that a point on the object has moved.
• x, y = coordinates of the point we are rotating around (relative to initial position of object).

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) 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 An object transforms between the following positions -

• A : position (2,1) angle 0°
• B : position (1,3) angle 30°
• C : position (-2,2) angle 90°

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): 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): If for instance, we want to combine it with a rotation of 90° about the x axis, we have a problem! 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:

 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.       3D Math Primer - Aimed at complete beginners to vector and matrix algebra. Other Math Books