Hello dynamo wizards, I am trying to determine if there is a way to take a list of line segments and a list of points and find all locations where the points are contained in the lines. Is there a solution where this is possible? Thank you for any assistance you can provide.
Hi @dweber12 how about some intersection, if i understand right here is a fast example…can probably be done many ways and more elegant
Using a distance calculation is a fast way to determine if points are on lines.
Iteration over the whole data set is costly though, so some pre-filtering to determine approximate spacial relationships would before processing would be beneficial.
Py - Group Points on Lines
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import math
from math import sqrt
def close_point(p1, p2, p3):
x1, y1, z1 = p1
x2, y2, z2 = p2
x3, y3, z3 = p3
dx, dy, dz = x2 - x1, y2 - y1, z2 - z1
det = dx * dx + dy * dy + dz * dz
a = (dx * (x3 - x1) + dy * (y3 - y1) + dz * (z3 - z1)) / det
return x1 + a * dx, y1 + a * dy, z1 + a * dz
points = IN[0]
lines = IN[1]
tolerance = 0.001
result = []
for l in lines:
# If points occur on the line add to its group
group = []
line_start = [l.StartPoint.X,l.StartPoint.Y,l.StartPoint.Z]
line_end = [l.EndPoint.X,l.EndPoint.Y,l.EndPoint.Z]
# Iterate points
for p in points:
coord = [p.X,p.Y,p.Z]
lineP = close_point(line_start,line_end,coord)
dist = sqrt( (lineP[0] - coord[0])**2 + (lineP[1] - coord[1])**2 + (lineP[2] - coord[2])**2 )
if dist < tolerance:
group.append(p)
result.append(group)
OUT = result