Calculate specific angle between two lines

1k Views Asked by At

I have some problem with math today :) Could you tell me how should I calculate $P$ angle?

img]

I know first and last point of each line. So I have:

L1 = [(10,10),(15,15)]
L2 = [(15,15),(20,8)]

But I don't have idea how calculate this angle. If I should be more specific I need to know $\cos$ of this angle. I would like to write this in Python.

2

There are 2 best solutions below

0
On

Find the slope of the two lines, then use the trig identity: $$\tan{\left(A+B\right)}=\frac{\tan{A}+\tan{B}}{1-\tan{A}\tan{B}}$$ Where $\tan{A}$ is the slope of one line, $\tan{B}$ is the slope of the other line, and $\tan{\left(A+B\right)}$ is the tangent of the angle between the two lines. Then use the following identity to solve for the secant of the angle: $$\tan^2{\left(A+B\right)}+1=\sec^2{\left(A+B\right)}$$ Then find cosine by taking the reciprocal of the secant.

0
On

What you need to use is the dot product formula which finds the angle between two vectors.It is

$a \cdot b=|a||b|\cos{\theta}$

where $\theta$ is the angle and |a| means magnitudte of vector a. You can treat both the lines as the two vectors a and b then plug it into the formula above to get the cosine of the angle.