Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Affine Transform - Scale Around a Point

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

like image 501
Ty Rozak Avatar asked Jun 14 '13 16:06

Ty Rozak


People also ask

How do you scale a point?

Usually, to scale about a particular point you first translate the object so that the point is at the origin. You then perform the scaling and then the inverse of the original translation to move the fixed point back to its original position.

Is scaling affine transformation?

Examples of affine transformations include translation, scaling, homothety, similarity, reflection, rotation, shear mapping, and compositions of them in any combination and sequence.

How do you calculate affine transformation?

The affine transforms scale, rotate and shear are actually linear transforms and can be represented by a matrix multiplication of a point represented as a vector, [x y ] = [ax + by dx + ey ] = [a b d e ][x y ] , or x = Mx, where M is the matrix.

What order of transformation is the affine transformation?

This sequence of operations can be combined into a single affine transform matrix by combining the transform matrices in the correct mathematical order: The affine transform resulting from a X translation, then a Y translation and then a Z rotation sequence.


1 Answers

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.

like image 101
landweber Avatar answered Oct 01 '22 05:10

landweber