Find discontinuities C#

HI,

I saw this topic C# explode curve like Rhino explode & GH explode component(with recursive true) - #4 by Michael_Pryor
It seems not to replicate the gh Component behaviour:


I tried It too but without luck. I couldnt find the C1 tangency in the rhinocommon, as the gh component uses por default.

 private void RunScript(Curve crv, ref object A)
  {

    double t0 = crv.Domain.Min; double t1 = crv.Domain.Max; double t;

    var tParams = new List<Double>();


    bool disc = crv.GetNextDiscontinuity(Continuity.C1_locus_continuous, t0, t1, out t);

    while (disc == true)
    {


      tParams.Add(t);

    }

    A = tParams;
  }

Maybe someone could help.

Thanks!

disc.gh (4.9 KB)

It is like this here (@DavidRutten code)

It basically works through curve types splitting case by case.

Hi Michael,

thanks.
In the picture above is a difference between peters(davids) code and the native component.

I cant understand why.Do I have to join the segments afterwards?

It works fine with Davids code. You are only using part of it. The full code is:

protected bool CurveSegments(List<Curve> L, Curve crv, bool recursive)
{
if (crv == null) { return false; }

PolyCurve polycurve = crv as PolyCurve;
if (polycurve != null)
{
if (recursive) { polycurve.RemoveNesting(); }

Curve segments = polycurve.Explode();

if (segments == null) { return false; }
if (segments.Length == 0) { return false; }

if (recursive)
{
foreach (Curve S in segments)
{
CurveSegments(L, S, recursive);
}
}
else
{
foreach (Curve S in segments)
{
L.Add(S.DuplicateShallow() as Curve);
}
}

return true;
}

PolylineCurve polyline = crv as PolylineCurve;
if (polyline != null)
{
if (recursive)
{
for (int i = 0; i < (polyline.PointCount - 1); i++)
{
L.Add(new LineCurve(polyline.Point(i), polyline.Point(i + 1)));
}
}
else
{
L.Add(polyline.DuplicateCurve());
}
return true;
}

Polyline p;
if (crv.TryGetPolyline(out p))
{
if (recursive)
{
for (int i = 0; i < (p.Count - 1); i++)
{
L.Add(new LineCurve(p[i], p[i + 1]));
}
}
else
{
L.Add(new PolylineCurve(p));
}
return true;
}

//Maybe it’s a LineCurve?
LineCurve line = crv as LineCurve;
if (line != null)
{
L.Add(line.DuplicateCurve());
return true;
}

//It might still be an ArcCurve…
ArcCurve arc = crv as ArcCurve;
if (arc != null)
{
L.Add(arc.DuplicateCurve());
return true;
}

//Nothing else worked, lets assume it’s a nurbs curve and go from there…
NurbsCurve nurbs = crv.ToNurbsCurve();
if (nurbs == null) { return false; }

double t0 = nurbs.Domain.Min;
double t1 = nurbs.Domain.Max;
double t;

int LN = L.Count;

do
{
if (!nurbs.GetNextDiscontinuity(Continuity.C1_locus_continuous, t0, t1, out t)) { break; }

Interval trim = new Interval(t0, t);
if (trim.Length < 1e-10)
{
t0 = t;
continue;
}

Curve M = nurbs.DuplicateCurve();
M = M.Trim(trim);
if (M.IsValid) { L.Add(M); }

t0 = t;
} while (true);

if (L.Count == LN) { L.Add(nurbs); }

return true;
}

2 Likes

I couldnt find the C1 tangency in the rhinocommon, as the gh component uses por default.

Not every component option is packaged together in rhinocommon. David also makes a lot in code based on math. I believe those options have to do with these:
http://developer.rhino3d.com/5/api/RhinoCommon/html/Overload_Rhino_Geometry_Curve_DerivativeAt.htm
http://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_Geometry_Vector3d_IsParallelTo.htm
http://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_Geometry_Curve_TangentAt.htm

Thanks Michael,

So I need to join them afterwards, by checking if they are paralell etc.
My aim is to get the points,


It seems a lot very a lot of code, I thought I was missing something.

Anyway, thanks!