# Rotate a point around a rectangle

This is kind of a strange problem so I'll do my best to describe it.

If you have a rectangle, the example I've been testing with is 13x8, and you have a point that is around the outside of the rectangle like the image below. The top left of the rect is at (0, 0). rect1

How would you rotate the point around the rectangle 180 degrees so it now looks like this: rect2

And in the opposite case how would you rotate to get it from the bottom right back to the top left? The data I have available is the current door location (the red dot), the size of the building (the black box), the location of the building (top left of the black box), and that the point will always be on the edge of a rectangle one size larger in both dimensions than the base rect. So the point in the example will always land on the edge of a 14x9 rectangle that is at (-1, -1).

Basically what this is being used for is to determine where the player needs to be to enter the door on a building, so when the building rotates 180 degrees the door location needs to move accordingly.

-

If I understand you correctly, you are rotating the point $(x,y)$ by 180 degrees around the centre of the rectangle. If that centre is at $(a,b)$, the rotation takes $(x,y)$ to $(2a-x, 2b-y)$.
@Shenjoku, Robert means the rectangle you already have. Your $13\times 8$ rectangle is centered at $(6.5, 4)$, so the point $(0,-1)$ gets rotated to $(2\cdot 6.5 - 0, 2\cdot 4 - (-1)) = (13,9)$ (by the way, the coordinates of the point you've drawn in the second image are incorrect), and $(6.5,-1)$ gets rotated to $(6.5,9)$ (again, not the coordinates you wrote, but the correct ones). – Rahul Feb 24 '12 at 3:28
@Shenjoku, rotating a point $(x,y)$ 90 degrees about the origin gives either $(-y,x)$ or $(y,-x)$ depending on the direction of rotation. So if you want to rotate about the center of the square at $(a,b)$ instead, you'd get $(a-(y-b),b+(x-a))$ or $(a+(y-b),b-(x-a))$. – Rahul Feb 24 '12 at 10:22