Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Intersection of 2 lines
Message
 
To
27/02/2001 08:32:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00479322
Message ID:
00480287
Views:
37
Hi Bob,

Thanks for the help (Neil, Al, Albert, and Yuri as well). I'll be working on it tonight and post the code here to the UT when it's finished. Thanks again.


>I think I have a solution to your problem. If the points on one line are (x1,y1) and (x2,y2) and the points on the second line are (x3,y3) and (x4,y4), the first step is to calculate the slopes of each line. They would be m1 for the slope of the first line and m2 for the slope of the second line.
>m1 = (y2-y1)/(x2-x1)
>m2 = (y4-y3)/(x4-x3)
>Let's call the point of intersection (x5,y5)
>
>x5 = ((m2*x3)-y3-(m1*x1)+y1)/(m2-m1)
>y5 = ((m1*m2*x3)-(m1*y3)-(m2*m1*x1)+(m2*y1))/(m2-m1)
>
>Unless I have a typo, this should work.
>Notice it won't work if x1=x2 or x3=x4, because that would put a 0 in the denominator of the formula.
>If x1 = x2, then x5 = x1 (or x2) and
>y5 = -m2*x3 + y3 + m2*x1
>If x3 = x4, then x5 = x3 (or x4) and
>y5 = -m1*x1 + y1 + m1*x3
>
>Notice it also won't work if m1 = m2(another case of 0 in the denominator).
>If that happens there are 2 possibilities:
>1)the 2 lines are parallel and won't ever intersect, or
>2)the 2 sets of points each lie on the same line as one another, which means infinite intersection points.
>
>I sure hope I didn't mistype anything. Try the formula manually with 2 easy lines where you know the intersection point to test it(as I have done, but to double check me).I won't confuse things with how I derived these formulas unless you want me to. I had to write a program years ago that would determine the center of a circle given 3 points on the circle. It involved the intersection of the perpendicular bisectors of the chords determined by the 3 points, so coming up with this again was a good refresher for me as well.
Roi
'MCP' Visual FoxPro

In Rome, there was a poem.
About a dog, who found two bone.
He lick the one, he lick the other.
He went pyscho, he drop dead!
Previous
Reply
Map
View

Click here to load this message in the networking platform