Hi,
I have two lines with following coordinates
I will be thankful for any help on calculating the angle between 2 lines.Code:Line1 :
Start Point: (10,6)
end Point: (10,12)
Line 2:
Start Point: (10,9)
end Point: (14,9)
thanks
Printable View
Hi,
I have two lines with following coordinates
I will be thankful for any help on calculating the angle between 2 lines.Code:Line1 :
Start Point: (10,6)
end Point: (10,12)
Line 2:
Start Point: (10,9)
end Point: (14,9)
thanks
The first line is vertical, the second is horizontal, so the angle is trivially 90 degrees.... The more general question given arbitrary coordinates is a little more interesting. Given line 1 points of (X1, Y1), (X2, Y2) and line 2 points of (A1, B1), (A2, B2), the angle is the same as that between the vectors <X2-X1, Y2-Y1> and <A2-A1, B2-B1>. The angle between vectors is given by the inverse cosine of their dot product, presuming the vectors have been normalized to have length 1.
Hi Jemidiah,
Many thanks for your prompt response.
The problem in reference are 2 perpendicular lines; I am trying to build a generic VB routine that can calculate angle between 2 lines.
It has been longtime since I have done Vectors and I am trying to refresh my memory.
In the meantime, I will be grateful for any worked out example..
thanks again..
Alright. Let (X1, Y1) = (1, 1), (X2, Y2) = (3, 3); (A1, B1) = (-2, 3), (A2, B2) = (-2, 12). The second line is vertical and the first is the Y=X line, so the angle should be 45 degrees. As I mentioned, we want to find the angle between the vectors <2, 2> and <0, 9>. First we normalize each by dividing by their magnitude. The magnitude of a vector <x, y> is Sqrt(x^2 + y^2), so the magnitude of <2, 2> is Sqrt(4+4) = Sqrt(8) = ~2.82843, meaning <2, 2> normalized is <2/2.82843, 2/2.82843> = <0.70717, 0.70717>. Similarly <0, 9> normalized is <0, 9/9> = <0, 1>.
Now the angle is, as I said, the inverse cosine of their dot product. Given two vectors <x, y> and <a, b>, their dot product is (x*a + y*b), so the dot product of the above vectors is (0.70717 * 0 + 0.70717 * 1) = 0.70717. The inverse cosine of this value is 0.785398163 radians. Converting radians to degrees is done by multiplying by 180/pi, which in this case gives 45, as expected.
Hi Jemidiah,
Many thanks for your kind response.
I will apply the concept on different line pairs and revert back shortly .
thanks again..
One thing I should mention is that your question is vague. Some line segments don't intersect, in which case the "angle" between them is unclear. Some line segments intersect like your original example, which gives rise to multiple angles of intersection--90 and 180 are both valid in your example, and if you rotated the vertical line by, say, 30 degrees, 180, 60, and 120 would all be valid answers. Finally, if two segments share a common vertex, even then the angle between them is ambiguous--the segments (0,0)-(1,0) and (0,0)-(0,1) could be said to have angle 90 or 270.
In any case, the calculation I went through is basically the answer you want. You might have to modify it to deal with these technicalities in whatever way your application requires.