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