Join curves problem

Hi,

I have two curves as follow figure

In Rhino windows, I used _Join command and it returns successful result.

In my code, I’ve tried:

doc.Objects.UnselectAll();
RhinoApp.RunScript("_Join", false);
// jCrv is my array of curves
for (int i = 0; i < jCrv.Length; ++i)
{
Guid gg = doc.Objects.AddCurve(jCrv[i]);
doc.Objects.Select(gg);
}

I also tried to change

RhinoApp.RunScript("_Join", false);

to

RhinoApp.RunScript("_Join", true);

but there is nothing changed. Curves could not be joined into one curve.

(In my previous topic, I’ve tried

double epsilon = 0.001;
Curve myRetCrvs = Curve.JoinCurves(jCrv, epsilon);

but curves could not be joined into one curve. Is my epsilon too small?)

I expect your help!

Br,

Can you post your geometry?

Yes,
here is my geometry
after projecting a curve to brep, I try to join them.TestJoinCurves.3dm (38.8 KB)

and here is my C# code:

        ObjRef[] targetSrfs;
        Result result = Rhino.Input.RhinoGet.GetMultipleObjects(
            "Please select target meshes:",
            false,
            ObjectType.Surface,
            out targetSrfs);
        if (result != Result.Success)
        {
            return Result.Failure;
        }

        var listTargetBrep = new List<Brep>();
        foreach (var obj in targetSrfs)
        {
            listTargetBrep.Add(obj.Brep());
        }
        ObjRef basicCrvObj;
        result = Rhino.Input.RhinoGet.GetOneObject(
            "Please select basic curve on CPlane:",
            false,
            ObjectType.Curve,
            out basicCrvObj);
        if (result != Result.Success)
        {
            return Result.Failure;
        }
        Curve myCrv = basicCrvObj.Curve();

        // split into some curves
        List<Curve> lstCrv = new List<Curve>();
        Plane workingPlane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
        Curve[] jCrv = Curve.ProjectToBrep(myCrv, listTargetBrep, workingPlane.Normal, 0.001);
        doc.Objects.UnselectAll();
        RhinoApp.RunScript("_Join", true);
        for (int i = 0; i < jCrv.Length; ++i)
        {
            Guid gg = doc.Objects.AddCurve(jCrv[i]);
            doc.Objects.Select(gg);
        }

This is how the project looks like:

If I move the point you see what happens.

Or some are just not connected to eachother and then you get openings:

This probably happens because the surfaces are overlapping and are not connected

Yes, I see. Thank you!

Now, I’m trying to join these curves by using:

PolyCurve pC = new PolyCurve(); for (int i = 0; i < jCrv; ++i) { pC.Append(jCrv[i]); }

It still makes a complex curve and it is an unexpected result.

What you can do is check if the start or end point of a curve is on the same spot with a bit of tollerance. To do this you can use RhinoMath.EpsilonEquals(). If its on the same spot you can join them. If not. You probably have to filter them on their position and move the endpoint or startpoint to another curves start or endpoint. But then you have to know which curve is which and know what start point is which one.

Probably loop through all curves and try to find the closest matches (throw all end points and startpoints in a list and check findclosestpt). If they match move 1 of them to the others point.

Thank you,

I will try your way.

Also check if the endpoint or startpoint are from the same curve. If so. Dont move it :wink: :smiley:

Yes, thank you!