# Finding the angle between two lines meeting at one point.

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.

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

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

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

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*}

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