C#_Curve.Split Mathod_Unnecessary multiple Curve splits

Hello,
I am using curve.Split method(IE t) method to split closed curve into 2 segments… List “t” contains only 2 parameters when i call that method it is giving me 3 splits instead of 2 splits.

It would be a great help if anyone can tell me where I am going wrong.

here is the code. Also find attached Rhino and GH_file

List<double> t = new List<double>();

//Input for this method has to be List for further process.
splitCrvs = SplitBoundaries(bdCrv, paths, out t);
tParams = t;

//////////////////////////////
public List SplitBoundaries(List boundaries, List paths, out List tP)
{
List newBoundary = new List();

List<double> tPara = new List<double>();

for(int i = 0; i < boundaries.Count; i++)
{
  Curve cB = boundaries[i];
  Curve[] cS = null;

  if(cB.IsClosed){

    cB.Domain = new Interval(0, 1);

    for(int j = 0; j < paths.Count; j++)
    {
      Curve cP = paths[j];
      cP.Domain = new Interval(0, 1);

      double t1,t2;

      Point3d cP_Start = cP.PointAtStart; Point3d cP_End = cP.PointAtEnd;

      cB.ClosestPoint(cP_Start, out t1);
      cB.ClosestPoint(cP_End, out t2);

      Point3d p1 = cB.PointAt(t1); Point3d p2 = cB.PointAt(t2);

      double dist_t1 = cP_Start.DistanceTo(p1);
      double dist_t2 = cP_End.DistanceTo(p2);

      if(dist_t1 < 0.1 && dist_t2 < 0.1)
      {
        tPara.Add(t1); tPara.Add(t2);
        break;
      }
    }
    cS = cB.Split(tPara);

    if(cS != null)
       newBoundary.AddRange(cS);
  }
}
tP = tPara;
return newBoundary;

}
/////////////////////////////////


SplitMethod.3dm (305.4 KB)
SplitMethod.gh (7.5 KB)

Even a closed curve will have a start and end point, it’s just that these points are the same. In other words, if your curve is a function of t, c(t), and the domain of the curve is [t0,t1], then c(t0) == c(t1). Apart from that, there is nothing special about a closed curve.

Now when you split at ta and tb that are inside the domain [t0,t1], and you get three segments:

  • [t0,ta]
  • [ta,tb]
  • [tb,t1]

If you join the first and last segment, you have your two parts.

1 Like