# Find a point on a rotated rectangle with known angle

I have an example: How to find point A's xy location (assuming point A can be anywhere on rectangle (not 4 small one, I mean the large one), including corners, but not inside or outside rectangle), with known alpha, beta angles, width, height and center xy location (center can be any position too, not just (0, 0) ) ?

Is there a formula too? If so, include it :)

To solve this problem, you need to first calculate the coordinates of the corners of your rectangle. Let's name the corners of this rectangle as $MNPQ$. When the angle $\alpha=0$, the coordinate of point $M$ with respect to the center of the rectangle $(x_c,y_c)$ is $(-w/2,h/2)$. The angle that this point is seen from the center of the rectangle is $\gamma_M=\arctan2(-w/2,h/2)=\arctan2(-w,h)$, and the distance to the center is $\sqrt{w^2+h^2}/2$. In terms of polar coordinates the rotation by $\alpha$ means that we just need to add $\alpha$ to this $\gamma_M$. If you keep the trigonometric sense for the angles then the $\alpha$ in your figure is negative. We also need to add the coordinates of the center of the rectangle to this value, in order to get the coordinates in the original reference frame. What you get in this case is: $$x_M=x_c+\cos(\gamma_M+\alpha)\sqrt{w^2+h^2}/2\\y_M=y_c+\sin(\gamma_M+\alpha)\sqrt{w^2+h^2}/2$$ Similarly you can get the coordinates of all corners using $$\gamma_M=\arctan2(-w,+h)\\ \gamma_N=\arctan2(+w,+h)\\ \gamma_P=\arctan2(+w,-h)\\ \gamma_Q=\arctan2(-w,-h)$$ The equation of the line $MN$ can be written as$$\frac{x-x_M}{x_N-x_M}=\frac{y-y_M}{y_N-y_M}$$ while the equation of $OA$ line is $$\beta=\arctan2(y,-x)$$ I assumed here that the $\beta$ is measured clockwise from the $-y$ axis. You should modify this equation if it's not the case.
From the last two equations we can find the intersection of $OA$ with $MN$, meaning the coordinates of point $A$ if the intersection is between $M$ and $N$. That means that it's a solution if $(x_A-x_M)(x_A-x_N)\le0$. Similarly, you should find intersection points with $NP, PQ, QM$. You might find 0, 1, or 2 intersections