> Suppose you have two straight lines, defined by two points: > > Let's say > > point(x1, y1) and point(x2, y2) for line 1 > > and > > point(x3, y3) and point(x4, y4) for line 2. > > What's the algorithm for calculating the point where these two lines > intersect?
Convert them both into the form y = mx + c where m is the slope of the line and c is a constant ie. m1 = ((y2 - y1)/(x2 - x1)) and c1 = y2/(m1 * x2) and m2 = ((y4 - y3)/(x4 - x3)) and c2 = y4/(m2 * x4) then if m1 == m2 and they don't share a common point at eg. x = 0, then they're parallel and don't intersect; otherwise x = (c2 - c1)/(m1 - m2) is the x value at the point of intersection and you can solve either original equation for the y value x = (c2 - c1)/(m1 - m2) re-arranges to: num = y3 - y1 + (x1 * (float((y2 - y1))/(x2 - x1))) - (x3 * (float((y4 - y3))/(x4 - x3))) denom = float(y2 - y1)/(x2 - x1) - float(y4 - y3)/(x4 - x3) x = num/denom -- x-value at the i-sect point HTH, -Sean. [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]