I have this short script that I have written sometime ago to find intersections between lines, split at the intersection and return the each part of the curve. When using it in a specific instance I found that some curves are ignored by it. I can’t figure out why this is.
if (double.IsNaN(tolerance) || tolerance == 0.0){tolerance = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;}
bool respectTol = true;
var tPoints = new DataTree<Point3d>();
var Crvs = new DataTree<Curve>();
for (int pi = 0; pi < Curves.BranchCount; pi++)
{
var path = Curves.Paths[pi];
var curveList = Curves.Branches[pi];
for (int i = 0; i < curveList.Count; i++){
var path1 = new GH_Path(path);
path1.AppendElement(i);
if (curveList[i] != null){
List<double> T = new List<double>();
Curve curr = curveList[i];
for (int j = 0; j <= curveList.Count - 1; j++){
if (i != j){
if (curveList[j] != null){
var path2 = new GH_Path(path1);
path2.AppendElement(j);
Curve other = curveList[j];
var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curr, other, tolerance, 0.0);
if (events != null){
for (int ev = 0; ev < events.Count; ev++)
{
var ccx_event = events[ev];
if(respectTol)
{
if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon)
{
T.Add(ccx_event.ParameterA);
//path.AppendElement(i,j);
tPoints.Add(curr.PointAt(ccx_event.ParameterA), path2);
}else Print("ccx Event outside tolerance at: {0},{1}", i, j);
}else{
T.Add(ccx_event.ParameterA);
//path.AppendElement(i,j);
tPoints.Add(curr.PointAt(ccx_event.ParameterA), path2);
}
}
}
}
}
}
Curve[] shatteredArray = curr.Split(T);
//path.AppendElement(i,j);
Crvs.AddRange(shatteredArray, path1);
}
}
}
A = Crvs;
B = tPoints;
I have added a gh file with the example. One of the curves is not intersected with the remaining ones.
curvesSplit.gh (5.0 KB)