Jump to content
  • Advertisement


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


probleme with rotation in 2d

This topic is 5809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.


[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

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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!