Sara S.
Sara S.

Reputation: 1375

How can i resize a rotated rectangle with aspect ratio?

I have an array of points

PArr [0..3]

which correspond to the rectangle points , i know how to rotate the rectangle around its center but i want to resize it after a rotation process of angle theta.

i searched on web but i didn't find an algorithm that works well for rotated rectangles Regarding that i resize it in Mouse Move action.

How can i resize the points while keeping the aspect ratio of the rectangle sides, i know it's a vectors issue but i'm a bit confused about it?

Upvotes: 1

Views: 3123

Answers (1)

Dmitry Sapelnikov
Dmitry Sapelnikov

Reputation: 1149

Use transformation matrices. They provide clear multiple transforms.

http://en.wikipedia.org/wiki/Transformation_matrix

In your case you need 4 matrices:

  1. Translation (-sizeX/2, -sizeY/2) - to process further transformations around the center of the rectangle

  2. Rotation by a specified angle

  3. Scale by a specified factor (aspect ratio of the rectangle will be preserved!)

  4. Translation (sizeX/2, sizeY/2) - to revert the first positioning

Multiply these 4 matrices and apply the result to your rectangle points. Oh, and your rectangle must have its origin in (0, 0) to apply the matrix. If the origin of your rectangle has (x0, y0) coordinates, use

(-x0 - sizeX/2, -y0 - sizeY/2) for the first matrix

and (x0 + sizeX/2, y0 + sizeY/2) for the fourth one

Upvotes: 2

Related Questions