Equation calculating specified degree rotation

Started by
1 comment, last by DevLiquidKnight 21 years, 6 months ago
Im trying to figure out if there is some type of equation that someone wouldn''t mine possibly explaining to me that shows how to rotate a point around a specified point a specifed amount of degrees
Advertisement
Angle-Axis Rotation or Quaternion
You cannot rotate a point about a point. You can rotate a point about a line. If you''re talking 2D, then you probably mean to rotate the point about a line perpendicular to the plane that passes through the second point. Lets look at that case. Suppose you have a point A = (Ax, Ay) and you would like to rotate about the line perpendicular to the xy plane that passes through point B = (Bx, By). And suppose you want to rotate by, say c radians. Here are the equations to do the rotation:

Arx = Bx + cos(c)*(Ax-Bx) - sin(c)*(Ay-By)
Ary = By + sin(c)*(Ax-Bx) + cos(c)*(Ay-By)

Here, Ar = (Arx, Ary) is the rotated point. but how did we actually get to those equations? Lets look at the generalized matrix equation equation to find Ar:

Ar = B + R * (A - B)

Where R is a 2x2 rotation matrix,

R = [Rxx Rxy]    [Ryx Ryy] 


This causes the equation to expand out (in matrix notation) to:

[Arx] = [Bx] + [Rxx Rxy]*[Ax - Bx][Ary]   [By]   [Ryx Ryy] [Ay - By] 


Which simplifies to 2 normal equations:

Arx = Bx + Rxx*(Ax-Bx) + Rxy*(Ay-By)
Ary = By + Ryx*(Ax-Bx) + Ryy*(Ay-By)

Now, you know Bx, Ax, Bx. But how to find that pesky R matrix. I''ll give it to you, but suggest you go back and read some introductory material on matrices and vector math to get a better understanding---for 3D graphics, and even 2D, it can be critical that you really understand this rather than just using canned solutions.

For the case of rotating A about the specified line by c radians, The R matrix is:

R = [cos(c) -sin(c)]    [sin(c)  cos(c)] 


The columns of that matrix are exactly equal to the basis vectors of a 2D cartesian coordinate system that is rotated by c radians relative to another cartesian coordinate system, and the basis vectors are represented in the coordinate system about which the rotation is performed.

If you plug in this R matrix, you will get:

Arx = Bx + cos(c)*(Ax-Bx) - sin(c)*(Ay-By)
Ary = By + sin(c)*(Ax-Bx) + cos(c)*(Ay-By)

Which is exactly what we started with.

I can suggest the following resource for a more formal introduction to matrix math. This is an excellent featured article on gamedev.net:

http://www.gamedev.net/reference/programming/features/vecmatprimer/

You''ll notice that my R matrix is exactly equal to the upper 2x2 portion of the Rz matrix given on the second page of that article under the section titled "Transformation Matrices." Get to know and understand Transformation Matrices. They are your friend!

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement