basic 2d rotation / geometry

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

Recommended Posts

Please bare with me on this, I'm still new and figuring stuff out.

So far I'm displaying an image file onto the screen with GDI, and have some code to turn the image 90 degrees based on mouse movement. However, I would like the image to rotate all the time based on the mouse coordinates.

If I think logically about it, I should create a downward line from the image middle point, create a line from the image middle point to the current mouse cooridinates, and measure the opening of that angle. Then rotate the image to the new measurement angle - the previous rotation percentage (this should provide fluid rotation instead of always from an original facing image).

However, the geometry escapes my mind since it's been 11 years since I've seen anything geometry related, and every rotation and matrix example deals with opengl/dx/other api/library functions/calls.

Any help in trying to figure out the math of finding the angles would be greatly appreciated!

Example: Image of 50x50 at x=50 y=50 location (middle rotation point = 75,75). Imaginary downward line = 75,0 to 75,y where y=anything > 75. New line = 75,75 to mouselocx,mouselocy. Need to find the angle between those two lines going clockwise

Share on other sites
You can find the angle with the help of a function called atan2. People usually use the right side of the x axis instead of your downward line. In the more standard convention and with the center of rotation being at the origin, the angle required to move the right side of the x axis to the point (a,b) is atan2(b,a).

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 16
• 18
• 12
• 14
• 9
• Forum Statistics

• Total Topics
633362
• Total Posts
3011527
• Who's Online (See full list)

There are no registered users currently online

×