Reputation: 471
I am trying to scale a shape that I have in Java around a certain point.
When I use the AffineTransform.scale method, it scales based on the top left corner. Is there anyway to scale anchored at a point (say the center of the window for this case).
Thanks,
Ty
Upvotes: 7
Views: 4486
Reputation: 2343
I agree with Hovercraft Full of Eels that the proper way to do this is to translate the center to the top left corner, scale, then translate the top left corner back to the center.
However, if you want it to perform it in fewer than three steps, the transform is:
x ⟼ S(x – c) + c = Sx + (c – Sc),
where S is the scaling transformation, and c is the center in coordinates relative to the top left.
So, you need to do your scaling, then translate by c – Sc.
Upvotes: 5