Find the angle of a $2D$ line

44 Views Asked by At

I have this situation, a ball, a line indicating the ball's direction and a random point $A(X_a,Y_a)$ the center of the ball is $B(X_b,Y_b)$. The line $R$ is rotated around the ball from $0$ to $2\pi$ to point that line in the direction of point $A$. Find $\theta$ in order to increment the current angle of line $R$? I believe this is simple but I am not seeing how I can do this.

Example

P.S. This is a computer program; that is why the $Y$ axis is going down.

1

There are 1 best solutions below

0
On

Let $\mathbf u=(\cos\phi,\sin\phi)$, the unit vector that points in the ball’s current direction $\phi$. You then have $$\cos\theta={A-B\over\|A-B\|}\cdot\mathbf u.$$ Since $\cos\theta=\cos(-\theta)$ this has a sign ambiguity, so it doesn’t tell you whether you need to rotate clockwise or counterclockwise. To disambiguate that, compute the determinant $$\begin{vmatrix}X_b&Y_b&1 \\ X_b+\cos\theta_0&Y_b+\sin\theta_0&1 \\ X_a&Y_a&1\end{vmatrix}=(Y_a-Y_b)\cos\phi-(X_a-X_b)\sin\phi.$$ (This is also the two-dimensional “cross product” of $\mathbf u$ and $A-B$.) Since you’re using a left-handed coordinate system, a positive value means that you need to rotate clockwise, counterclockwise if negative.