Rotation of a square/rectangle around a point

6.3k Views Asked by At

this is the first time I ask a question here. I want to know what's the simplest way of calculating the coordinates for the 4 points of a square/rectangle on a plane, after a rotation around a point, given an angle.

Example of the rotation of a square.

enter image description here

Thanks in advance.

2

There are 2 best solutions below

6
On

Are you familiar with the equations for polar form: $r\cos\theta = x$ and $r\sin\theta = y$? These formulas will help you here.

Given a square, you can find the distance from any vertex to the origin ($r$) using Pythagorean theorem. You will know $x$ and $y$ because of the graph. Then, it's a matter of finding $\theta$.

Once this is done, all rotations are simply a matter of adding degrees to $\theta$. If you want to find the coordinates in Cartesian again, then simply use the above transformation equations.

0
On

Apply a rotation matrix. After rotation by an angle $\theta$, the coordinates of a point $(x,y)$ are $$\pmatrix{\cos\theta&-\sin\theta\\\sin\theta&\cos\theta}\pmatrix{x\\y}=\pmatrix{x\cos\theta-y\sin\theta\\x\sin\theta+y\cos\theta}.$$ Now compute that for the points of interest. For example, if the square is centered on $(R,0)$ and its side length is $2r$, then the upper left corner is at $(R-r, r)$.