1
$\begingroup$

I have $3$ points : $(x_1, y_1), (x_2, y_2)$ and $(x_3, y_3)$.

By joining these $3$ points I get $2$ lines meeting at $(x_2, y_2)$.

Now, I want to find the angle formed at the point $(x_2, y_2)$ when the lines intersect.

I have tried doing this by finding the slope $(m)$ of the two lines and then finding the angle by using the "$\tan \theta = \frac{m_1 – m_2 }{1+ m_1m_2}$" formula but I find that it doesn't work in some particular situations.

So is there any way by which I can convert the lines into vectors and then find the angle using $\cos \theta = \frac{v_1·v_2}{|v_1||v_2|}$ formula.

If not, could you please let me know any other way by which I can find the angle between the $2$ lines, even if I place the two lines in any direction.

$\endgroup$
4
  • $\begingroup$ Please edit mathematical expressions by using MathJax. I've already edited a line or two, which should serve as an example. $\endgroup$ – vitamin d Apr 1 at 5:42
  • $\begingroup$ You mean you can't calculate the vector from $(x_2,y_2)$ to $(x_1,y_1)$? $\endgroup$ – user10354138 Apr 1 at 5:45
  • $\begingroup$ @user10354138, Yes, can you please let me know the formula for that. ( converting the x and y coordinates into a vector) $\endgroup$ – Sharath Prajith Apr 1 at 5:52
  • $\begingroup$ @vitamind , Thanks a lot for editing the formula. I was not able to do so. $\endgroup$ – Sharath Prajith Apr 1 at 6:07
1
$\begingroup$

The vector from $(a,b)$ to $(c,d)$ is $(c-a, d-b)$

$\endgroup$
1
  • $\begingroup$ Thank You very much Michael. In the formula a,b,c and d refer to x1, y1, x2 and y2 respectively. Am I right? $\endgroup$ – Sharath Prajith Apr 1 at 6:42
0
$\begingroup$

Let $\textbf{p}_1$, $\textbf{p}_2$, and $\textbf{p}_3$ denote the vectors with tips at $(x_1,y_1)$, $(x_2,y_2)$, and $(x_3,y_3)$, respectively, then the vector with initial point $(x_2,y_2)$ and terminal point $(x_1,y_1)$ is $\textbf{p}_1-\textbf{p}_2=(x_1-x_2,y_1-y_2)$. Similarly, the vector with initial point $(x_2,y_2)$ and terminal point $(x_3,y_3)$ is $\textbf{p}_3-\textbf{p}_2=(x_3-x_2,y_3-y_2)$. It follows that the angle between the vectors (and thus the lines) is

\begin{align*} \theta &= \cos^{-1}\left(\frac{(\textbf{p}_3-\textbf{p}_2)\cdot(\textbf{p}_1-\textbf{p}_2)}{||\textbf{p}_3-\textbf{p}_2||\text{ }||\textbf{p}_1-\textbf{p}_2||}\right)\\ &= \cos^{-1}\left(\frac{(x_3-x_2)(x_1-x_2)+(y_3-y_2)(y_1-y_2)}{\sqrt{(x_3-x_2)^2+(y_3-y_2)^2}\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}}\right) \end{align*}

$\endgroup$
2
  • $\begingroup$ Wow! Thanks a lot Alann, I will surely try it out and let you know if it works. $\endgroup$ – Sharath Prajith Apr 1 at 6:39
  • $\begingroup$ Thank you very, very much. I wrote the code and it works perfectly. Couldn't have done it without you both. $\endgroup$ – Sharath Prajith Apr 1 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.