# Given two corners of a rectangle, and an angle of rotation, is it possible to calculate the position of the other corners?

Given two co-ordinates, representing opposite corners of a rectangle, and an angle of rotation that the original rectangle was rotated about the center, is it possible to calculate the position of the other two corners in order to re-create the original rectangle, but now rotated?

To clarify - I know the original rectangle had two sides perpendicular to the x-axis and two perpendicular to the y-axis...

So lets say we have a rectangle with a longer side perpendicular to the x-axis. We rotate it by 20 degrees clockwise about its center. We store the coordinates of what was the top right and the bottom left corners and the angle we rotated (20 degrees, and the assumption it was clockwise). Given just these new co-ordinates and the knowledge that we rotated by 20 degrees, is it possible to calculate the location of the other two corners. If so, can you provide me some steps to do so?

So in the picture below I know E, D' and B' and the Angle between the lines E-D and E-D'. Is it possible to calculate A' and C' with just those bits of knowledge?

• @MattFellows - Is the original rectangle always oriented so that the sides are perpendicular to the $x,y$ axes? – Myridium Oct 27 '16 at 9:21
• @Myridium Yes the original is always perpendicular – Matt Fellows Oct 27 '16 at 9:22

Assuming that the vertices $A,B,C$ and $D$ are oriented as in your diagram, and $\theta$ measures the anticlockwise rotation:

Given $B'=(a',b')$ and $D'(c',d')$:

1. Translate coordinate system so that the rectangle's center is at the origin: $$E' = (B' + D') / 2$$ $$B'_T = B' - E', \qquad D'_T = D' - E'$$

2. Rotate coordinate system so that the rectangle is oriented with its sides parallel to the $x,y$ axes (i.e. undo the rotation): $$B_T=\left(\begin{matrix} a_T \\ b_T\end{matrix}\right) = \left( \begin{matrix} \cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{matrix}\right)\left(\begin{matrix} a'_T \\ b'_T\end{matrix}\right), \quad D_T=\left(\begin{matrix} c_T \\ d_T\end{matrix}\right)=\left( \begin{matrix} \cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{matrix}\right)\left(\begin{matrix} c'_T \\ d'_T\end{matrix}\right)$$

3. Find other corners $A_T,C_T$ by $$A_T = \left(\begin{matrix} a_T \\ d_T \end{matrix}\right), \qquad C_T = \left(\begin{matrix} b_T \\ c_T \end{matrix}\right)$$

4. Rotate $A_T$ and $C_T$ back to obtain $A'_T$ and $C'_T$: $$A'_T=\left( \begin{matrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{matrix}\right)\left(\begin{matrix} a_T \\ d_T\end{matrix}\right), \qquad C'_T=\left( \begin{matrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{matrix}\right)\left(\begin{matrix} b_T \\ c_T\end{matrix}\right)$$
5. Translate coordinate system back that the rectangle's center returns to where it was.

$$A' = A'_T + E', \qquad C' = C'_T + E'$$

First you need to shift your center to orign(0,0) and respectively the corners will also shift. suppose your center is (x,y) and corner points as (x1,y1) and (x2,y2), solve as (x,y)+(-x,-y)=(0,0) and similarly corner points by (newX1,newY1)=(x1,y1)+(-x,-y)=(x1-x,y1-y) and (newX2,newY2)=(x2,y2)+(-x,-y)=(x2-x,y2-y) then use this equation

x' = x * cos θ - y * sin θ

y' = y * cos θ + x * sin θ

with value of angle as -20. x and y as your new corner points.... first solve for values of x and y as (newx1, newY1) and then for (newx2, newY2). You will have two equations solve them simultaneously. You will now have the points of rotated trianles.... now shift back to orignal center by adding x and y respectively in corner points you got after solving above equations.

Now you have got your rectangle rotated back by 20 degree and its orignal position. now you can find corner points by using pathagoras theorem... as when we draw diagonal in rectangle it splits up into two right triangles. using pathagoras theorem you can get the corner points.

Shift the origin to the centre of rectangle and get the position of points according to new origin. From there I guess you can carry on.