I want to connect points from sublist of input IN[0] to points of sublist of input IN[1] in the way the combinations of lines generated do not clash between each other, the inputs are a list of sublists of dynamo points. I do not know how to make it work, I ran this script in python node but it eats all memory RAM 50GB and it does not finish because:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "<string>", line 43, in <module>
File "<string>", line 33, in lines_from_points
MemoryError: Array dimensions exceeded supported range.
The code used:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Line, Point
import itertools
def lines_from_points(start_points_lists, end_points_lists):
def is_intersecting(line1, line2):
x1, y1, z1 = line1.StartPoint.X, line1.StartPoint.Y, line1.StartPoint.Z
x2, y2, z2 = line1.EndPoint.X, line1.EndPoint.Y, line1.EndPoint.Z
x3, y3, z3 = line2.StartPoint.X, line2.StartPoint.Y, line2.StartPoint.Z
x4, y4, z4 = line2.EndPoint.X, line2.EndPoint.Y, line2.EndPoint.Z
denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
if denom == 0:
return False
t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denom
u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denom
if 0 < t < 1 and 0 < u < 1:
return True
return False
def is_valid_combination(lines):
for line1, line2 in itertools.combinations(lines, 2):
if is_intersecting(line1, line2):
return False
return True
valid_combinations = []
for start_points, end_points in zip(start_points_lists, end_points_lists):
all_combinations = list(itertools.permutations(end_points, len(start_points)))
for end_points_combination in all_combinations:
lines = [Line.ByStartPointEndPoint(s, e) for s, e in zip(start_points, end_points_combination)]
if is_valid_combination(lines):
valid_combinations.append(lines)
return valid_combinations
start_points_lists = IN[0]
end_points_lists = IN[1]
OUT = lines_from_points(start_points_lists, end_points_lists)