Archived

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

spillsome

probleme with rotation in 2d

Recommended Posts

I have a triangle on screen and i want to rotate it using the formula x = x * cos(Angle) - y * sin(Angle); y = y * cos(Angle) + x * sin(Angle); it works, it rotates, but it is getting smaller and smaller. is there a problem with the type of x and y (with float ?)

Share this post


Link to post
Share on other sites
1) The first line is changing the value of x which is used by the second line. For the rotation to work properly the x and y used on both lines must be the original values *before* the rotation:

newx = oldx * cos(Angle) - oldy * sin(Angle);
newy = oldy * cos(Angle) + oldx * sin(Angle);


2) The input x,y should always be the original non rotated version (i.e. always at 0 degrees), then you change only the Angle parameter and any display of the object uses newx and newy.



It *is* possible to perform rotation which modifies the input data, but issues such as floating point precision affect you very quickly, and the numerical error snowballs causing things such as the values heading toward 0. That's why always starting with the original version with full precision is far more stable.

500

[edit]changed emphasis on newx and newy since forum code inserts an extra unwanted space which made it look like a memory alloc [/edit]

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - s1ca on January 19, 2003 12:47:47 PM]

Share this post


Link to post
Share on other sites