Hi, there, lately I been trying to script a component that calculates the intersection of a set closed curves, its a pretty simple iterative method, but I can’t figure out how to make it run faster. Any Ideas…???.
Here I’m leaving the method for both C# and Python(and the example file). I know that you can make faster recursive functions with memoization, but according to @AndersDeleuran, it’s probably slower than an iterative function and in C# by using linq but I’m not sure, linq still is a little bit cryptic to me. Thanks !!! https://discourse.mcneel.com/t/seldup-equivalent-in-python/42520/8
public Curve AllIntersection(List<Curve> set_list)
{
Curve result = set_list[0];
foreach(Curve s in set_list.Skip(1)){
result = Rhino.Geometry.Curve.CreateBooleanIntersection(result, s)[0];
}
return result;
}
import Rhino
def allIntersection(set_list):
result = set_list[0]
for s in set_list[1:]:
result = Rhino.Geometry.Curve.CreateBooleanIntersection(result,s)[0]
return result
You won’t see the Python recursion cost with only three iterations. Also, the performance looks pretty much as expected on my system (i.e. on par with the standard compiled components):
If you’re going for performance, writing a compiled C# component is probably the way to go. Especially with many curves/iterations. In this particular case (i.e. intersecting circles), you could probably also speed things up by going with a purely mathematical approach instead (I’d think).
Antonio,
Sorry for the late response. I was hoping you could tell me a little more about your problem. Is this a performance problem because you are intersecting many small sets of curves ( like the model shown that has 3 circles), or are you thinking of cases trying to intersect many ( say hundreds to thousands) curves?
Hi, Yes the second one, I’m attempting to intersect many curves, looking back I was able to reduce solution time by using PolylineCurves instead of Circle or NurbsCurves. I’m thinking of at least 1000 curves because the number of rooms in a big building tend to be around that number.