Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
up vote 2 down vote accepted

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)$.

share|cite|improve this answer
That would work if I knew the rect that the point was moving across, but I don't. Like for example if that red point in the first image was at (6.5, -1) instead of (0, -1) then it would be mirrored to the other side of the rect at (6.5, 8) after the 180 rotation. – Shenjoku Feb 24 '12 at 2:09
For what you're describing to work I would need to somehow be able to find the rectangle connecting the two points, which seems tricky if I only know one point, which can be at any of the four corners of the rectangle, and the size. (couldn't edit anymore so had to make a new post, sorry) – Shenjoku Feb 24 '12 at 2:22
@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
@Rahul Huh, I must have been doing something extremely wrong because I swear it wasn't working when I was trying different things. I guess that does work. Is there a similar formula for doing 90 degree rotation? Because I need that too, though only on squares (which I assume doesn't matter). – Shenjoku Feb 24 '12 at 4:31
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.