Sign in to follow this  
xycos

[java] Rotation with AffineTransform

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
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

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