I'm sorry if my question in not for here and because it's so stupid. I have a function, which draws a rectangle - it takes 4 parameters - width and lenght and 2 for positioning it. However, this is not so important. What I want to do, is to rotate it. Can you please tell e what to do with the coordinates of the rectangle to rotate it for example with 45 degrees?
Rotate a figure with given coordinates
0
$\begingroup$
geometry
-
0The center of the rectangle, you mean? – 2012-11-11
1 Answers
1
After writing down the coordinates of the corners of your rectangle, you'll want to multiply the coordinates (technically, the vector) by the rotation matrix: $$\begin{pmatrix} \cos θ & -\sin θ\\ \sin θ & \cos θ \end{pmatrix}$$ $θ$ is the angle you want to rotate the rectangle(counterclockwise).
So, if your coordinate is $\left(x,y\right)$, your rotated coordinate will be: $$\left(x\cos θ+y\sin θ, -x\sin θ + y\cos θ\right)$$
Note: this assumes you're rotating about the origin.