 # Curves Curve Intersections foregoes some curves

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)
{
//path.AppendElement(i,j);
}else Print("ccx Event outside tolerance at: {0},{1}", i, j);
}else{
//path.AppendElement(i,j);
}

}
}
}
}
}
Curve[] shatteredArray = curr.Split(T);
//path.AppendElement(i,j);
}

}
}

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)

Ok. I got it. It is related with the tolerance check, it seems point A and point B are overlapping for some reason. `ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon`

Yup you are right.
I fixed the code and also added proper data structure so that the output make sense in terms of correlation with input. See attached.
curvesSplit_RI_06102020.gh (11.3 KB)

1 Like

Brilliant! I was trying to fix that now! Thanks!