#### Archived

This topic is now archived and is closed to further replies.

# Equation calculating specified degree rotation

## Recommended Posts

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

##### Share on other sites
Guest Anonymous Poster
Angle-Axis Rotation or Quaternion

##### Share on other sites
grhodes_at_work    1385
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.
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}