• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

2D rotation question

Ah, I see. Stretching out the box this way doesn't leave it as a square, so if you "forget" how you stretched it and just rely on the 140x80 your box will still be bigger than it needs to be for some angles.
Hey, if all you're wanting to do is flip, stretch, and rotate, why don't you just keep the four corner points in memory and do the boundary calculations based on them?
 
Aha, here's a solution. Keep four values in memory, representing the lengths and angles of the original diagonals.
The bounds are always equal to max(length1*sin(angle1),length2*sin(angle2)) and max(length1*cos(angle1),length2*cos(angle2)).
Example:
Start with 100x50 bound. Data points are (112, 26.6, 112, 333.4).
Rotate 37 degrees, so new data points are (112, 63.6, 112, 10.4).
So new bounds are 110x100 using the above equation.
When you flip or stretch, flip or stretch the two diagonals as well using appropriate equations (basic mathematical geometry).
 
Last edited:
Aha, here's a solution. Keep four values in memory, representing the lengths and angles of the original diagonals.
The bounds are always equal to max(length1*sin(angle1),length2*sin(angle2)) and max(length1*cos(angle1),length2*cos(angle2)).
Example:
Start with 100x50 bound. Data points are (112, 26.6, 112, 333.4).
Rotate 37 degrees, so new data points are (112, 63.6, 112, 10.4).
So new bounds are 110x100 using the above equation.
When you flip or stretch, flip or stretch the two diagonals as well using appropriate equations (basic mathematical geometry).

Thanks for that. I was having a mental block and forgetting that I had access to the original diagonals!

I just need to work out how to detect when the mouse is within the bounds of a rotated edge now...
 
Just rotate the position of the mouse cursor the same as the image was rotated. That will make it easy.

Could you expand on this a little please. It rings a bell from something I did a few years ago.
By rotating the mouse position are you saying that I can do a simple bounds test, the same as if the object wasn't rotated?
 

Back
Top Bottom