Formulas for Angle Between Two Lines The angle between two lines, of which, one of the line is ax + by + c = 0, and the other line is the x-axis, is θ = Tan-1(-a/b). The angle between two lines, of which one of the line is y = mx + c and the other line is the x-axis, is θ = Tan-1m.
double theta1 = atan(m1) * (180.0 / PI); double theta2 = atan(m2) * (180.0 / PI); After to know the angle I calculate the following: double angle = abs(theta2 - theta1);
One is an acute angle and another is an obtuse angle or equal. Both these angles would be supplements(Sum equals 180◦) of each other. By definition, when we say 'angle between two straight lines' we mean the acute angle between the two lines.
I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2)
and P1L1(x1, y1), P2L3(x2, y3))
. I want to know the inner angle defined by these two lines.
For do it I calculate the angle of each line with the abscissa:
double theta1 = atan(m1) * (180.0 / PI);
double theta2 = atan(m2) * (180.0 / PI);
After to know the angle I calculate the following:
double angle = abs(theta2 - theta1);
The problem or doubt that I have is: sometimes I get the correct angle but sometimes I get the complementary angle (for me outer). How can I know when subtract 180º
to know the inner angle? There is any algorithm better to do that? Because I tried some methods: dot product,
following formula:
result = (m1 - m2) / (1.0 + (m1 * m2));
But always I have the same problem; I never known when I have the outer angle or the inner angle!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With