About RhinoOffsetCurveOnSrf

Hi~

I want to use RhinoOffsetCurveOnSrf to offset the edge on the brep.
On the left edge has problem.

Attached 3dm belt.3dm (372.3 KB)

My Code as following

    const ON_Brep* Brep = NULL;
    {
      CRhinoGetObject get;
      unsigned int geometry_type_filter = 0;
      geometry_type_filter |= CRhinoGetObject::polysrf_object;
      geometry_type_filter |= CRhinoGetObject::surface_object;
      get.SetGeometryFilter(geometry_type_filter);
      get.AcceptNothing(true);
      get.SetCommandPrompt(L"Select Surface Object");
      for (;;)
      {
        context.m_doc.UnselectAll();
        context.m_doc.Redraw();

        CRhinoGet::result res = get.GetObjects(1, 0);
        if (res == CRhinoGet::object)
        {
          CRhinoObject* obj = const_cast<CRhinoObject*>(get.Object(0).Object());
          Brep = ON_Brep::Cast(obj->Geometry());
          break;
        }
        else if (res == CRhinoGet::cancel)
          return CRhinoCommand::cancel;

      }
    }

    // Select Edge
    const ON_Curve* Crv = NULL;
    {
      CRhinoGetObject get;
      unsigned int geometry_type_filter = 0;
      get.SetGeometryFilter(CRhinoGetObject::edge_object);
      get.SetGeometryAttributeFilter(CRhinoGetObject::surface_boundary_edge);
      get.AcceptNothing(true);
      get.SetCommandPrompt(L"Select Edge");
       for (;;)
      {
        context.m_doc.UnselectAll();
        context.m_doc.Redraw();

        CRhinoGet::result res = get.GetObjects(1, 0);
        if (res == CRhinoGet::object)
        {
          CRhinoObjRef objref = get.Object(0);
          const ON_BrepEdge* e = objref.Edge();
          if (e)
            Crv = ON_Curve::Cast(e);
          break;
        }
        else if (res == CRhinoGet::cancel)
          return CRhinoCommand::cancel;
      }
    }
    if (Brep && Crv)
    {
      ON_SimpleArray<ON_Curve*> result_curves;
      RhinoOffsetCurveOnSrf(Crv, Brep, 0, 1.5, CUtilitys::ConvertTol(0.05), result_curves); 
      ON_Curve* tmpCrv = NULL;
      if (result_curves.Count() > 0)
        tmpCrv = *result_curves.First();
      result_curves.Zero();
      if (tmpCrv)
        ::RhinoApp().ActiveDoc()->AddCurveObject(*tmpCrv);
    }

Did you try it in plain Rhino, did it fail there too?
I use the command in Rhino often but it also fails often so if possible I’d try to avoid that in your code

Hi @angelwang,

Please review the following sample and let me know if you have any questions.

cmdSampleOffsetCrvOnSrf.cpp

– Dale

@dale
Thank you very much.

I try camSampleOffsetCrvOnSrf.cpp and set offset value 1.5mm
The offset result

Offset value 3mm and 4mm

Do you have any suggestion to make the result is no problem when it offset 1.5, 3 or 4?

Hi @angelwang,

Did you try the Rhino command OffserCrvOnSrf? See how it has the same problem?

If you zoom in on the model, where I’ve added text dots, you’ll see that the surface does overlap but not exactly. This “offset” for lack of better works is what is causing the problem.

If you take my sample code and comment out the call to RhinoExtendCrvOnSrf you should get what you want.

belt_df.3dm (417.2 KB)

– Dale

Hi @dale
Thank you very much.

Because we have a function “Belt”, we may have the overlap surface on the inner side.
And we need the offset curve to create “Stitch”.

Yes, I tried to run Rhino command “OffserCrvOnSrf”, and see the same problem, It likes as below picutre.

The above picture is the result that I run your code cmdSampleOffsetCrvOnSrf.cpp on SampleCommands project, it has the same problem.

So, I don’t know why your result is good on belt_df.3dm.

my
Rhino6 version is 6.15.19164.21011
Rhino6 SDK version is 6.15.19164.21011

Hi @angelwang,

Use the CreateUVCrv command to unwrap the surface boundary. Then offset the boundary curves how you like. Then use ApplyCrv to wrap the offset curves back onto the surface. Does this produce results that work for you?

– Dale

@angelwang I was thinking about another possible solution to avoid using OffsetCrvOnSrf . Since your surface has constant width, you could also extract isocurves from it instead.

Hi @dale

Thank you for your reply.

The produce result is good, but I can’t find “CreateUVCrv” and “ApplyCrv” on Rhino_SDK_Function.

@Gijs

Thank you for your reply.

I think I can try to extract isocurves.

Thanks~