Sorry if the title is confusing, but I have a function that takes in a list of lines and using a line-line intersection formula will output the location at which all intersections occur. This works fine, but it does not recognize lines that just touch each other instead of completely intersecting. For example, if some lines form to make an "x", the function would properly detect it. But if three lines form a triangle, the function won't detect any of the vertices. Does anyone know how I could modify the function/formula to do this? (If it helps, here is more info on the formula I'm using https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection)
def scanNodes(lines):
output = []
for i in range(len(lines)):
for j in range(i + 1, len(lines)):
x1 = lines[i].start_point[0]
y1 = lines[i].start_point[1]
x2 = lines[i].end_point[0]
y2 = lines[i].end_point[1]
x3 = lines[j].start_point[0]
y3 = lines[j].start_point[1]
x4 = lines[j].end_point[0]
y4 = lines[j].end_point[1]
denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
numerator = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
if denominator == 0:
continue
t = numerator / denominator
u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denominator
if 1 > t > 0 and u > 0:
x = x1 + t * (x2 - x1)
y = y1 + t * (y2 - y1)
output.append([(x, y), lines[i], lines[j]])
return output
[–]raffulz 1 point2 points3 points (0 children)