[Solved] How To Calculate angle between 2 lines at intersection


Calculate the direction vectors of both lines and normalize them:

d := (x2 - x1, y2 - y2)
length = sqrt(d.x^2 + d.y^2)
d := (d.x / length, d.y / length)

Then, you have multiple options to calculate the angle. One simple way is to use the dot product:

dot = dRed.x * dGreen.x + dRed.y * dGreen.y
angle = arc cos(dot)

If you also want to reconstruct angles greater than 180° (you will need correct line orientations then), you need the cross product:

cross = dRed.x * dGreen.y - dRed.y * dGreen.x
angle = atan2(cross, dot)

6

solved How To Calculate angle between 2 lines at intersection