Rotation Matrix
Author |
Message |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu Apr 12, 2012 10:24 am Post subject: Rotation Matrix |
|
|
in this formula:
x = x cos (t) - y sin (t)
y = x sin (t) + y cos (t)
How do you change where the origin is? I want to use this for rotation, but so far I can only get my object to rotate around the point 0, 0. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu Apr 12, 2012 10:27 am Post subject: RE:Rotation Matrix |
|
|
Actually let me reword that: How do I change the point of rotation? |
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Thu Apr 12, 2012 11:10 am Post subject: RE:Rotation Matrix |
|
|
What you're using there is actually a specialization of a "transform matrix" ( http://en.wikipedia.org/wiki/Transformation_matrix ) -- one which handles only 2D rotation. Matrix transformations are really excellent because they let you apply multiple distinct transformations in order.
If you don't want to work with matricies, you could do the following:
1. Translate (x,y) such that (0,0) is the point you want to rotate around (rx,ry): (x,y) -= (rx,ry)
2. Rotate (as above)
3. Translate back: (x,y) += (rx,ry)
In most cases, the "rotation point" is just set to be (0,0) when modeling (creating the square, etc), so you can skip steps 1 and 3 and just use step 2. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Thu Apr 12, 2012 10:09 pm Post subject: RE:Rotation Matrix |
|
|
Thanks, I got it |
|
|
|
|
![](images/spacer.gif) |
|
|