RhinoOffsetCurve

Is it possible to use the paramters bothside and Cap in RhinoOffsetCurve command? How?
Thanks

Hi @ceruti,

Sorry no, you’ll need to do this yourself.

– Dale

Hi @dale

I run Rhino SDK funnction “RhinoOffsetCurve” by C++ to offset my Crv1, but the result has problem.


Crv1.3dm (230.4 KB)

my code as following

// Select Crv
const ON_Curve* Crv1 = NULL;
ON_Curve* OffsetBoundaryCrv = NULL;
CRhinoGetObject get;
unsigned int geometry_type_filter = 0;
geometry_type_filter |= CRhinoGetObject::curve_object;
get.SetGeometryFilter(geometry_type_filter);
get.AcceptNothing(true);
get.SetCommandPrompt(L"Select Crv1");
for (;;)
{
  context.m_doc.UnselectAll();
  context.m_doc.Redraw();

  CRhinoGet::result res = get.GetObjects(1, 1);
  if (res == CRhinoGet::object)
  {
    Crv1 = ON_Curve::Cast(const_cast<CRhinoObject*>(get.Object(0).Object())->Geometry())->DuplicateCurve();
    ON_SimpleArray<ON_Curve*> offCuvs;
    ON_3dPoint pnt = Crv1->PointAt(Crv1->Domain().Mid());
    RhinoOffsetCurve(*Crv1, -ON_zaxis, pnt, -10., offCuvs, 0.02,0, 1);
    ON_PolyCurve* poly = new ON_PolyCurve;
    for (int j = 0; j < offCuvs.Count(); j++)
      poly->AppendAndMatch(*offCuvs.At(j));
    OffsetBoundaryCrv = poly;
    ::RhinoApp().ActiveDoc()->AddCurveObject(*OffsetBoundaryCrv);
    RhinoApp().ActiveDoc()->Redraw();
    break;
  }
  else if (res == CRhinoGet::cancel)
    return CRhinoCommand::cancel;
}
return CRhinoCommand::success;

Could you help me to check the problem?

my Rhino6 sdk version is 6.19.19295.01001
Rhino6 version is 6.19.19295.01001

Thanks~

Hi @angelwang,

I see you are using the deprecated version of RhinoOffsetCuve. Please try using the version that is not deprecated.

/*
Description:
  Offsets a curve.
Parameters:
  curve_in        - [in] the curve to offset.
  distance        - [in] the distance to offset the curve.
  direction_point - [in] a point that indicates the direction of the offset.
  normal          - [in] a vector that indicates the normal of the plane in which the offset will occur.
  corner_style    - [in] the corner style, where:
                           no_corner = 0, sharp = 1, round = 2, smooth = 3, chamfer = 4
  tolerance       - [in] the offset tolerance.
  curves_out      - [out] the offset curves.
Returns:
  Returns number of curves that are appended to array.
Remarks:
  The caller is responsible for deleting these curves when finished.
*/
int RhinoOffsetCurve(
        const ON_Curve& curve_in,
        double distance,
        ON_3dPoint direction_point,
        ON_3dVector normal,
        int corner_style,
        double tolerance,
        ON_SimpleArray<ON_Curve*>& curves_out
        );

– Dale

Hi @dale
Thank you for your reply.

I try RhinoOffsetCurve by your suggestion, but it has same problem.


Crv1.3dm (184.6 KB)

// Select Crv
const ON_Curve* Crv1 = NULL;
ON_Curve* OffsetBoundaryCrv = NULL;
CRhinoGetObject get;
unsigned int geometry_type_filter = 0;
geometry_type_filter |= CRhinoGetObject::curve_object;
get.SetGeometryFilter(geometry_type_filter);
get.AcceptNothing(true);
get.SetCommandPrompt(L"Select Crv1");
for (;;)
{
  context.m_doc.UnselectAll();
  context.m_doc.Redraw();

  CRhinoGet::result res = get.GetObjects(1, 1);
  if (res == CRhinoGet::object)
  {
    Crv1 = ON_Curve::Cast(const_cast<CRhinoObject*>(get.Object(0).Object())->Geometry())->DuplicateCurve();
    ON_SimpleArray<ON_Curve*> offCuvs;
    ON_3dPoint pnt = Crv1->PointAt(Crv1->Domain().Mid());
    ON_3dVector Tan = Crv1->TangentAt(Crv1->Domain().Mid());
    ON_3dVector Vec = ON_CrossProduct(Tan,ON_zaxis); Vec.Unitize();
    double offsetValue = -10.;
    pnt = pnt + Vec;
    RhinoOffsetCurve(*Crv1, offsetValue, pnt, ON_zaxis, 1, 0.02, offCuvs);
    ON_PolyCurve* poly = new ON_PolyCurve;
    for (int j = 0; j < offCuvs.Count(); j++)
      poly->AppendAndMatch(*offCuvs.At(j));
    OffsetBoundaryCrv = poly;
    ::RhinoApp().ActiveDoc()->AddCurveObject(*OffsetBoundaryCrv);
    RhinoApp().ActiveDoc()->Redraw();
    break;
  }
  else if (res == CRhinoGet::cancel)
    return CRhinoCommand::cancel;
}
return CRhinoCommand::success; 

Could you help me to check the problem?
Thanks~

Hi @angelwang,

This seems to work on your curve:

CRhinoCommand::result CCommandTestAngel::RunCommand(const CRhinoCommandContext& context)
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select curve to offset");
  go.SetGeometryFilter(CRhinoGetObject::curve_object);
  go.GetObjects(1, 1);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  const ON_Curve* curve = go.Object(0).Curve();
  if (nullptr == curve)
    return CRhinoCommand::failure;

  CRhinoView* view = go.View();
  if (nullptr == view)
    return CRhinoCommand::failure;
  
  const double distance = 10.0;
  ON_3dPoint direction_point = ON_3dPoint::Origin;
  ON_3dVector normal = view->ActiveViewport().ConstructionPlane().m_plane.Normal();
  const int corner_style = 1; // sharp
  const double tolerance = context.m_doc.AbsoluteTolerance();

  ON_SimpleArray<ON_Curve*> out_curves;
  RhinoOffsetCurve(*curve, distance, direction_point, normal, corner_style, tolerance, out_curves);
  RhinoOffsetCurve(*curve, -distance, direction_point, normal, corner_style, tolerance, out_curves);

  for (int i = 0; i < out_curves.Count(); i++)
  {
    context.m_doc.AddCurveObject(*out_curves[i]);
    delete out_curves[i]; // Don't leak...
  }

  context.m_doc.Redraw();

  return CRhinoCommand::success;
}

Does this help?

– Dale

Hi @dale

Thank you very much.
It works fine.