c#_Brep Brep Intersection_nested for loops

Hello,
I am trying create simple waffle structure using c#. I am always getting a intersection curve at last index and no points in the output. Attached script and image.
Any help would be great!

Tuple<Curve[],Point3d[]> waf = Waffel(x, y, mtrThk);
A = waf.Item1;
B = waf.Item2;

}

//
public Tuple<Curve,Point3d> Waffel(List srfA, List srfB, double thk)
{
double tolr = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

Curve[] crv = null;
Point3d[] iPts = null;
////////////////////////////////////
for(int i = 0; i < srfA.Count; i++)
{
  for(int j = 0; j < srfB.Count;j++)
  {
     Rhino.Geometry.Intersect.Intersection.BrepBrep(srfA[i], srfB[j], tolr, out crv, out iPts);
  }
}
return Tuple.Create(crv, iPts);

}

w1

That’s normal, each time you call the intersection method the results in the out parameter arrays will be replaced and you will only return the result of the last intersection (of srfA[srfA.Count-1] and srfB[srfB.Count-1]). And I guess the intersection between the breps is a line segment, so no intersection points.

You will have to handle the results of the intersection method each time you call it, e.g. by shifting the results from the array in a new list.

List<Curve> outputCurves = new List<Curve>();
for(int i = 0; i < srfA.Count; i++)
{
  for(int j = 0; j < srfB.Count;j++)
  {
    Curve[] crvs;
    Point3d[] pts;
    if (!Rhino.Geometry.Intersect.Intersection.BrepBrep(srfA[i], srfB[j], tolr, out crvs, out pts))
    {
       // handle this case
    }

    if (crvs != null && crvs.Length > 0)
    {
       outputCurves.AddRange(crvs); 
    }
  }
}

Also you had srfA[0] (instead of srfA[i]) and srfB[0] (instead of srfB[j])

1 Like