Rotate rectangles in a rectangle

636 Views Asked by At

Is there a general and easy way to calculate the new x and y coords of the rectangles in the big rectangle if I rotate the parent rectangle about 90deg. I know the x and y coords of each rectangle in the first picture and of course the width and height are also known.

chart

2

There are 2 best solutions below

1
On BEST ANSWER

In this case the origin appears to be on the upper left corner. Then following cofeemath ideas you can send every coordinate $(x,y)\to (y,-x+37)$ for a $90$ degree rotation.

$(x,y)\to (-x+37,-y+37)$ for a $180$ degree rotation

and $(x,y) \to (-y+37,x)$ for a $270$ degree rotation

1
On

If the origin is at the lower left corner, then the map $(x,y) \to (-y,x)$ rotates the entire plane by 90 degrees (counterclockwise, as suggested by your diagrams). At this point the big square is correctly rotated but lies to the left by 37 units of where you want it. So you then need to add 37 to the new $x$ coordinate.

Conclusion: sending $(x,y)$ to $(-y+37,x)$ for each point inside should work.

edit: seems the origin is at the upper left corner. With this system the orientation of the two axes is different, making the 90 counterclockwise into $(x,y)->(y,-x)$ and then (it's upside down) add $37$ to the $y$ to arrive finally at $(y,37-x).$