| View previous topic :: View next topic |
| Author |
Message |
BlackDragon777
Joined: 15 Sep 2005 Posts: 32
|
Posted: Sun Sep 25, 2005 11:36 am Post subject: Rotation Math Question |
|
|
Hey everyone. I have a simple math question for you. I know how to rotate a point about the origin by using matricies. I also know how to do it using the formula.
The way I do it is
x = x*cos(theta) - y*sin(theta)
y = x*sin(theta) + y*cos(theta)
However I want to rotate my triangle about an arbitrary point. I read in my graphics book that the way to do that using a formula would be,
x = x*cos(theta) - y*sin(theta) + ORIGIN_VARIABLE
y = x*sin(theta) + y*cos(theta) + ORIGIN_VARIABLE
HOwever that doesn't seem to work. I am not great at math. I can do it with matricies but I think it is easier and faster to use a formula if at all possible. can anyone correct my latter formula? Thanks! |
|
| Back to top |
|
 |
AudioMonster
Joined: 07 Sep 2005 Posts: 37
|
Posted: Sun Sep 25, 2005 4:39 pm Post subject: |
|
|
I am not good a 3D maths too but i can try :
Your first formula rotates the point [X Y] around [0 0]
Your second formula does the same but then translates the rotated point by [OriginX OriginY].
What you want to do is to rotate around [OriginX OriginY], so you have to translate each point by [-OriginX -OriginY] and do a rotation around [0 0] by using your first formula, then you retranslate the rotated point by [OriginX OriginY].
Like:
x' = x - OriginX;
y' = y - OriginY;
x = x'*cos(theta) - y'*sin(theta) + OriginX;
y = x'*sin(theta) + y'*cos(theta) + OriginY;
That SHOULD work, but i don't guarantee anything ;)
There is probably a way to simplify that though. |
|
| Back to top |
|
 |
ector
Joined: 12 May 2005 Posts: 195
|
Posted: Sun Sep 25, 2005 4:52 pm Post subject: |
|
|
| AudioMonster wrote: | | There is probably a way to simplify that though. |
Yes, you can express all of these operations as 3x2 matrices, and multiply them all together into one. Though depending on your previous level of math knowledge, that may or may not be a simplification to you :) _________________ http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come. |
|
| Back to top |
|
 |
AudioMonster
Joined: 07 Sep 2005 Posts: 37
|
Posted: Sun Sep 25, 2005 5:02 pm Post subject: |
|
|
| Would that achieve less multiplication / additions ? |
|
| Back to top |
|
 |
BlackDragon777
Joined: 15 Sep 2005 Posts: 32
|
Posted: Sun Sep 25, 2005 5:07 pm Post subject: |
|
|
Hey! Thanks! I wasn't subtracting the origin points away. Thanks, that fixed my problem!
GOD Bless you Always!!!! |
|
| Back to top |
|
 |
|