# Rotating some rectangles to make them horizontal

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

• Try center of mass of them Aug 25 '19 at 6:25
• You should not try to rotate the figures. You have to do matrix multiplication for shear deformation where only y coordinate of second row reduces. Aug 25 '19 at 6:30
• @Narasimham, Thanks for the reply. But I have to maintain the width and height of the rectangle. Sorry if the image is misleading but shearing is not what I want. Aug 25 '19 at 6:52

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

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!

• Sorry to comment, but is this basically my answer? Aug 25 '19 at 12:17
• Ooh! Pardon me but I couldn't understand your approach, that's why I posted my answer. In your answer you are translating centroids and I thought it can be solved without centroids involved. Just find all coordinates in this one new system rather than going for every rectangle and doing translations. Aug 25 '19 at 12:27
• +1 That's fine then. I like your picture which adds a lot to the answer. Aug 25 '19 at 12:28
• Thank you for your response. Aug 25 '19 at 13:09

Forget about rotating all of the rectangles about one reference point, since all of them will end up being rotated by different amounts.

What you can do instead is to find the angle $$\theta$$ of the bottom sides of the rectangles from the horizontal. You can do this by using the coordinates of the corners.

Then, translate the centroids of the rectangles to $$(0,0)$$. Now you can apply the rotation matrix and rotate by $$- \theta$$:

$$R = \begin{bmatrix} \cos(-\theta) & -\sin(-\theta) \\ \sin(-\theta) & \cos( -\theta) \end{bmatrix} = \begin{bmatrix} \cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{bmatrix}$$

using the properties of $$\cos$$ and $$\sin$$. Don't forget to translate back to the position you want the rectangles to be in!

• Thank you for your fast reply. I have added some image for my current approach and I think What you are suggesting will result same as my current approach. Please see the added image in edit and correct me if I am not understanding your process properly. Thanks in advance. Aug 25 '19 at 10:28
• No, it's completely different. This answer uses multiple reference points: each rectangle has its own reference from the inclination of the bottom side. In addition you are translating each rectangle by a different amount after it has been moved to the origin. Aug 25 '19 at 11:58
• Try this method first and notify me if you have any problems. Aug 25 '19 at 11:59
• Thank you for your time but I think I understand clearly from the answer of @Kartoos. I gave you an upvote but don't have enough reputation to make it public. :( Aug 25 '19 at 13:08
• That's fine. Feel free to accept the other answer if it helps you more. Aug 25 '19 at 13:09