views:

127

answers:

4

Let's say I have a polygon with points:

(0,0)
(100,0)
(100,100)
(0,100)

Lets also let it's center be (50,50).

To rotate it would I add 50 to each component of each point, then do

x' = cos(theta)*x - sin(theta)*y
y' = sin(theta)*x + cos(theta)*y

Then subtract 50 from each component of each point?

Thanks

+4  A: 
andand
good answer! affine transformations on homogeneous coordinates -- suggest citing sources such as http://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations
Jason S
@Jason S: A good suggestion; post updated.
andand
+4  A: 

Thats right, except at the start you need to subtract 50 to bring the polygon center back to 0, then at the end add 50 to bring the polygon back to its orignal position.

Actually what you are using here is the rotation matrix in 2D:

alt text

ldog
Perfect thanks, glad I asked!
Milo
A: 

If you want to rotate around a point (call it center), you need to do the following transformations:

  1. Translate points from world positions into center relative positions.
  2. Rotate positions around the origin.
  3. Translate points from center relative points to world positions.
MSN
+1  A: 

You should subtract 50 from each component (this causes (50,50) to be the center), do the rotation, and then add 50 to each component.

Tomer Vromen