How to get the number of degrees?

44 Views Asked by At

I'm going to simulate a clock.

enter image description here

Imagine that, the segment between $(a, b)$ and $(x_1, y_1)$ it's the clock's hand.

I want to move $n$ degree from $(x_1, y_1)$ to $(x_2, y_2)$, and how i can get that $n$ degree?

enter image description here

And with that, how can I calculate it? I have been looking and I have seen that it is trigonometry, but I have not understood other answers, because they do not adapt to my problem.

3

There are 3 best solutions below

0
On BEST ANSWER

Hint: If you let $$v_1=(x_1,y_1)-(a,b)=(x_1-a,y_1-a)$$ and $$v_2=(x_2,y_2)-(a,b)=(x_2-a,y_2-a)$$ then you can compute the cosine of the angle between $v_1$ and $v_2$ as $$\cos\theta = \frac{v_1\cdot v_2}{|v_1||v_2|}$$ where the numerator is the dot product and the denominator contains the product of the magnitudes.

This should let you find $\theta$ easily enough, right?

0
On

Hint:

consider the vectors (hand)

$$ \vec v_1=\begin{pmatrix} x_1-a\\y_1-b\end{pmatrix}\qquad \vec v_2=\begin{pmatrix} x_2-a\\y_2-b\end{pmatrix} $$

than the angle $\alpha$ between the two vectors is such that $$ \cos \alpha=\frac{\vec v_1 \cdot \vec v_2}{|\vec v_1||\vec v_2|} $$

0
On

Or as an alternative by Atan2

  • $\alpha_1=\operatorname{atan2}(y_1-b,x_1-a)$

  • $\alpha_2=\operatorname{atan2}(y_2-b,x_2-a)$

then

  • $\alpha=\alpha_1-\alpha_2$