Rotation Math Question

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Rotation Math Question

Post by BlackDragon777 »

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!
AudioMonster
Posts: 37
Joined: Wed Sep 07, 2005 3:41 am
Contact:

Post by AudioMonster »

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.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

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.
AudioMonster
Posts: 37
Joined: Wed Sep 07, 2005 3:41 am
Contact:

Post by AudioMonster »

Would that achieve less multiplication / additions ?
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Hey! Thanks! I wasn't subtracting the origin points away. Thanks, that fixed my problem!

GOD Bless you Always!!!!
Post Reply