# Maths - Rotations in a plane

Here we define the rotation in terms of what does change, that is the two dimensional plane within which points move as they rotate. We will factor the rotation into the following steps:

• Move point along perpendicular line to the plane which goes through the origin.
• Do simple 2 dimensional rotation in the plane.
• Move point back along the perpendicular line to the same distance from the plane that it was originally.

This method seems to work best when using matrices. I don't think this method will work properly for compound rotations in 4 dimensions and above since we need to take into account the quadvector and other even blades generated (see this page for the issues concerning higher dimension rotations).

## Working

To map a three dimensional space onto a two dimensional in a linear way we can use two basis vectors:

 basis1 basis2

where:

• basis1 = (b1x,b1y,b1z) = 3D vector in plane of rotation toward initial position of point projected onto plane.
• basis2 = (b2x,b2y,b2z) = 3D vector in plane of rotation perpendicular to initial position of point.

Each of these basis vectors are 3 dimensional so this gives a 3×2 matrix:

 b1x b1y b1z b2x b2y b2z

When a 3 dimensional vector is multiplied by this matrix the result is a two dimensional matrix. So this transforms points in three dimensional space to points in a two dimensional space:

x'
y'
=
 b1x b1y b1z b2x b2y b2z
x
y
z

What if we want to go in the opposite direction? That is, we want to map from a two dimensional space to a three dimensional space?

In that case we just transpose the row and columns of the matrix to give:

 basis1 basis2

Which is a 2×3 matrix:

 b1x b2x b1y b2y b1z b2z

So this transforms points in two dimensional space to points in a three dimensional space:

x'
y'
z'
=
 b1x b2x b1y b2y b1z b2z
x
y

We can also map points, which remain in 3D space, but move to the plane in a direction perpendicular to the plane, that is they move to the nearest point on the plane. To do this we combine the previous two transforms:

 basis1 basis2
 basis1 basis2

we can expand this out to:

 b1x b2x b1y b2y b1z b2z
 b1x b1y b1z b2x b2y b2z

multiplying out gives:

 b1x2 + b2x2 b1x*b1y + b2x*b2y b1x*b1z + b2x*b2z b1x*b1y + b2x*b2y b1y2 + b2y2 b1z*b1y + b2z*b2y b1x*b1z + b2x*b2z b1z*b1y + b2z*b2y b1z2 + b2z2

We can use the following notation for this:

P2 = P1 || plane

This means P2 is the component of P1 which is perpendicular to the plane.

### Perpendicular to plane

See this page for full introduction to Parallel and Perpendicular components of planes.

We can also calculate the component of P1 which is perpendicular to the plane, this is denoted as follows:

P2 = P1 plane

If we add the parallel component and the perpendicular component we get the original vector as follows:

P1 = P1 || plane + P1 plane

Canceling out P1 gives:

[I] = || plane + plane

where [I] is the identity matrix.

We can therefore calculate the perpendicular component as follows:

plane = [I] - || plane

So in terms of the matrix elements this is:

 1 0 0 0 1 0 0 0 1
-
 b1x2 + b2x2 b1x*b1y + b2x*b2y b1x*b1z + b2x*b2z b1x*b1y + b2x*b2y b1y2 + b2y2 b1z*b1y + b2z*b2y b1x*b1z + b2x*b2z b1z*b1y + b2z*b2y b1z2 + b2z2

which gives:

 1 - b1x2 - b2x2 - b1x*b1y - b2x*b2y - b1x*b1z - b2x*b2z - b1x*b1y - b2x*b2y 1 - b1y2 - b2y2 - b1z*b1y - b2z*b2y - b1x*b1z - b2x*b2z - b1z*b1y - b2z*b2y 1 - b1z2 - b2z2

## Rotate in Plane

We can also rotate in a given plane, first we translate to a 2D plane, then we rotate, then translate back to 3D, as follows:

x'
y'
z'
=
 b1x b2x b1y b2y b1z b2z
 cos(θ) -sin(θ) sin(θ) cos(θ)
 b1x b1y b1z b2x b2y b2z

where:

• basis1 = (b1x,b1y,b1z) = 3D vector in plane of rotation toward initial position of point projected onto plane.
• basis2 = (b2x,b2y,b2z) = 3D vector in plane of rotation perpendicular to initial position of point.

Multiplying out the right hand terms gives:

x'
y'
z'
=
 b1x b2x b1y b2y b1z b2z
 c*b1x - s*b2x c*b1y - s*b2y c*b1z - s*b2y s*b1x + c*b2x s*b1y + c*b2y s*b1z + c*b2z

Where:

• c = cos(θ)
• s = sin(θ)

Multiplying out the remaining terms:

x'
y'
z'
=
 c*b1x2 + c*b2x2 b1x*(c*b1y - s*b2y) + b2x*(s*b1y + c*b2y) b1x*(c*b1z - s*b2y) + b2x*(s*b1z + c*b2z) b1y*(c*b1x - s*b2x) + b2y*(s*b1x + c*b2x) c*b1y2 + c*b2y2 b1y*(c*b1z - s*b2y) + b2y*(s*b1z + c*b2z) b1z*(c*b1x - s*b2x) + b2z*(s*b1x + c*b2x) b1z*(c*b1y - s*b2y) + b2z*(s*b1y + c*b2y) c*b1z2 + c*b2z2

We can divide this into the cosine part and the sine part:

x'
y'
z'
= c*
 b1x2 + b2x2 b1x*b1y + b2x*b2y b1x*b1z + b2x*b2z b1y*b1x + b2y*b2x b1y2 + b2y2 b1y*b1z + b2y*b2z b1z*b1x + b2z*b2x b1z*b1y + b2z*b2y c*b1z2 + c*b2z2
+ s*
 0 -b1x*b2y + b2x*b1y -b1x*b2y + b2x*b1z -b1y*b2x + b2y*b1x 0 -b1y*b2y + b2y*b1z -b1z*b2x + b2z*b1x -b1z*b2y + b2z*b1y 0

To get the final rotation in 3D we need to add the parallel and perpendicular components:

x'
y'
z'
= c*
 b1x2 + b2x2 b1x*b1y + b2x*b2y b1x*b1z + b2x*b2z b1y*b1x + b2y*b2x b1y2 + b2y2 b1y*b1z + b2y*b2z b1z*b1x + b2z*b2x b1z*b1y + b2z*b2y c*b1z2 + c*b2z2
+ s*
 0 -b1x*b2y + b2x*b1y -b1x*b2y + b2x*b1z -b1y*b2x + b2y*b1x 0 -b1y*b2y + b2y*b1z -b1z*b2x + b2z*b1x -b1z*b2y + b2z*b1y 0
+
 1 - b1x2 - b2x2 - b1x*b1y - b2x*b2y - b1x*b1z - b2x*b2z - b1x*b1y - b2x*b2y 1 - b1y2 - b2y2 - b1z*b1y - b2z*b2y - b1x*b1z - b2x*b2z - b1z*b1y - b2z*b2y 1 - b1z2 - b2z2