Deriving Rotation Formulas

From CGAFaq

Jump to: navigation, search

In 2D, the rotated point is computed from the original point with a rotation by angle by

While plugging values into this formula works, a beginning computer graphicist will surely wonder where this formula came from. Just looking at the formula brings no clearance, because it isn't easy to geometrically "see" in your mind, what is going on in here. So in this text we shall derive this formula, which hopefully brings light to the subject.

In mathematics, there are usually two ways people think about a given problem: geometric and algebraic. Geometric thinking tries to bring the problem to our familiar 3D or 2D space, where we can actually see the (supposed) answer by a looking a picture we drew on the paper. However, there is a danger here, because we might (by accident) assume something that we should not have assumed (for example perpendicularity of lines), and thus only get a specialized or even a wrong answer. Algebraic thinking is purely formal: you are given a set of rules by which you must modify your equations from the starting situation to the desired situation. If you can do it, then you are done, and the answer must be right (if there were no errors done following the rules). When you have both a geometric and algebraic understanding of the problem, you have mastered it.

Contents

Geometric derivation

We shall first look at the geometric construction of a rotation in 2D. The problem is rotating a point (x,y) around the origin with angle to a new point (x',y'). We naturally start thinking about ways to actually move the point into its new position. If you were to move a rock around a circle in nature, that is what you would do. Now consider yourself in void space with the rock. In which other way you could seemingly rotate the rock around you? That's right: turn yourself. To turn this observation into mathematical terms, rather than rotating the point, we shall rotate the coordinate system.

Let a coordinate system be defined by 2D basis vectors a and b. Then every vector on the plane spanned by a and b can be written with the use of coordinates (u,v), where u gives how far we shall go in the direction of a and v gives how far we shall go in the direction of b.

Clearly this a vector space, and its elements are vectors, not points. Assuming the coordinate system origin is located at the center of rotation C, the two spaces are related by the equation:

From this we see that to rotate points around point C, we must first move the points, such that C is in the origin, then rotate, and then move the origin back to C.

Now our problem is to define a' and b' such that they have been rotated degrees from a and b, respectively. If we can do this, then we can take the coordinates (u,v) of the vector and represent it in this new coordinate system.

Now lets see an image of the problem and see what we can deduce from it. Note, here we make an assumption to use an orthonormal basis. This is not a restriction: if we did not have orthonormal basis vectors we could take it a step back and describe those vectors in an orthonormal basis. This observartion makes the derivation easier.

Image:Coordinaterotation.png

With the math of upper elementary school, it is easy to deduce the new vectors a' and b':

Clearly

Remember we get the vector in this new coordinate system with

Substituting our results into this, we get

By combining:

Which you notice to be the same formula, as the one given in the beginning of this article.

Algebraic derivation

Algebraic derivation is most easily shown with using complex exponentials.

Euler's formula gives:

where i is the imaginary unit.

We shall use complex exponentials to describe our points. Real part contains the x-axis coordinate and imaginary part contains the y-axis coordinate.

First convert your point p = u + iv to the exponential form:

In this notation we would like to have a point p'

Lets separate the exponentials:

But that's just the original point multiplied by !

Using Euler's formula and expanding p in complex form:

Now expanding the multiplications we get:

Which is again the same formula.

Matrix form of 2D rotation

This is what we derived geometrically:

We can say the same with a matrix-vector multiplication:

Where the matrix is called a rotation matrix. Matrix representation is especially useful, because we can easily combine individual rotations into a one net rotation by multiplying their rotation matrices together.

Extending from 2D rotations to axis-aligned 3D rotations

Given our 2D rotation formula, we can construct axis-aligned rotations in 3D by choosing two basis vectors, which we will rotate around the third basis vector. The third vector remains unchanged by the rotation: it lies on the fixed line of the rotation.

Then the rotation matrices around three axes are:

Personal tools