OK, here is the problem. I am trying to calculate the intersection of two lines by comparing multiple line segments that are read out of a series of csv files. I've already got the x,y coordinate pairs for each line segment into a list of tuples within tuples as follows:
continuousLine = [((x1,y1),(x2,y2)), ...]
crossingLines = [((x1,y1),(x2,y2)), ...]
I am trying to figure out how to iterate along the continuous line and through the crossing lines to find out where along the continuous line each crossing line intersects.
Basically I want (pseudo-code listed below):
for segment in continuousLine:
if segment in crossingLines intersect == True:
return intersection
else:
move on to next crossing line segment and repeat test
I hate asking for help on this because I am too new to coding to help other people, but hopefully someone can work through this with me.
I do have a method that I think will work to calculate the intersection once I've figured out the iterator:
line1 = ()
line2 = ()
def line_intersection(line1, line2):
xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1]) #Typo was here
def det(a, b):
return a[0] * b[1] - a[1] * b[0]
div = det(xdiff, ydiff)
if div == 0:
raise Exception('lines do not intersect')
d = (det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return x, y
print line_intersection((A, B), (C, D))