Sign in to follow this  

[java] Rotation with AffineTransform

This topic is 4718 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

May apologies for bothering everyone... AffineTransform's getRotateInstance() gets an instance that rotates it around the top-left corner instead of the middle... and if I use the getRotateInstance() with an anchor point, it rotates my image out into the middle of nowhere... Any ideas? Thanks in advance and best of wishes, xycos

Share this post


Link to post
Share on other sites
Quote:
Original post by xycos
May apologies for bothering everyone...

AffineTransform's getRotateInstance() gets an instance that rotates it around the top-left corner instead of the middle... and if I use the getRotateInstance() with an anchor point, it rotates my image out into the middle of nowhere... Any ideas?

Thanks in advance and best of wishes,
xycos

you need three transformations
translate(width/2, height/2);
rotate(angle);
translate(-width/2, -height/2);

you need to put the center of your object at the origin (that's the third line), rotate (second), and then put the object back (first line).

Share this post


Link to post
Share on other sites
Wow that was... exactly what I needed. Thank you SO much!

Best of wishes,
xycos

Share this post


Link to post
Share on other sites
reading up on AffineTransform.getRotateInstance(double theta, int x, int y), you should use this method and pass -width/2 for x and -height/2 for y. It will do the same as my 3 steps above, but will be 3 times faster (only one transform).

Share this post


Link to post
Share on other sites

This topic is 4718 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this