Rotating some rectangles to make them horizontal

geometryrotationstransformation

I am new to math.stackexchange, so pardon me if I made any mistake. My question is – I have some rectangles along some lines inside another rectangle. They are at an angle other than 0 and 180 along horizontal line and I want to rotate them so that they are along the horizontal line. I know that in order to rotate a rectangle I have to rotate the four corner points with respect to a reference point. How can I achive this and what should be my reference point for rotation. Please see the image below to better understand my question.

This is what I have

This is what I am going for

So far I have tried to rotate individual rectangle using the top left corner point of the rectangle I am working with as a reference, but this didn't work because then the rectangles rotate remaining in their position. So I get a set of rectangles like stairs, not in the same line. I now know that I have to rotate all of them using the same reference point. Which should be the point- the top left of the outer rectangle?

EDIT:
The image for my current approach

My Current approach result

What I need

Best Answer

If I understand your problem correctly, the solution would be to find coordinates of all the corners of rectangle in a new other coordinate system where:

  1. Origin of the coordinate system is at the bottom left corner of the bottom left rectangle.
  2. The angle between x-axis of new coordinate system with respect to horizontal is $\omega$ Original Image

As shown in above image you just need to get $(a, b)$ in that new coordinate system.

Now if you assume $(a, b)$ (all the corners of rectangle in new system) in orthogonal Cartesian system ($x'$-axis and $y$-axis with the same origin $(0, 0)$) as shown in figure you get your desired result with width and height preserved.

So the set of coordinates in this system is your final coordinates you want.

Shifting Origin and finding coordinates is left to you as an exercise!