1

I am using the rotation to rotate a rectangle I have displaying on the screen by a degree of θ°. My rectangle matrix of vertices is:

my rectangle matrix of vertices

Where the first column is the x values and the second column is the y values. I load my vertices like this: bottomLeft (2,4), topLeft (2,5), topRight (3,5), and finally bottomRight (3,4).

Next I multiply it against the rotation matrix:

rotation matrix

Finally once the calculation is done, I get a new set of vertices:

new set of vertices

This is great and all but a problem is here, it rotates around the center point of (0,0). I want it to rotate around my bottomLeft vertex (2,4) (the first vertex in my matrix for this rectangle). How do I go about doing this? What do I have to do to rotate it around my bottomLeft vertex (basically change the center point of (0,0) to (2,4) as my center)?

Code Doggo
  • 2,146
  • 6
  • 33
  • 58

1 Answers1

1

All rotations will be done around the origin, so you have to move your rectangle to the origin, rotate it, then move it back.

If you use Affine Transforms you can do all three with matrix multiplications, and you can have a single matrix that does all three operations at once. If your rotation matrix must stay 2x2 then you'll have to do the translation (i.e. move) manually.

This answer shows how to compose the transforms for a point rotation.

Community
  • 1
  • 1
Adam
  • 16,808
  • 7
  • 52
  • 98
  • Thanks, I did what you said, I moved it to the origin, rotated it and moved it back. Worked just fine. Ill also look at affine transforms. Thanks again – Code Doggo Sep 30 '13 at 04:48