Interpolating Points

Hi guys,

Could anyone please tell me what I did wrong here:

ON_SimpleArray<ON_3dPoint> pnts;
pnts.Append(ON_3dPoint(0, 0, 0));
pnts.Append(ON_3dPoint(1, 2, 0));
pnts.Append(ON_3dPoint(2, 3, 0));
pnts.Append(ON_3dPoint(3, 1, 0));

ON_NurbsCurve* qq = NULL;
bool rt = RhinoInterpCurve(3,
    pnts,          // Array of points to interpolate
    NULL,
    NULL,               // Degree of the curve (cubic spline)
    knotStyle,       // Knot style (e.g., ON::uniform_knots, ON::chord_length_knots)
    qq);

It is very simple test case, I should get the curve returned.

thank you very much.
Regards
John

Always check the docs :slight_smile:

The return value is not a boolean, but a pointer to the interpolated curve.
You basically have 2 options: 1) give a pointer to a curve, this will then be returned if successful. Or 2) do not give a pointer to a curve, a new curve will be allocated and returned if successful. You are then responsible to free its memory if you are finished with it.

Option 1 (I personally prefer this, no need to deallocate the result):

ON_NurbsCurve result;
if (RhinoInterpCurve(pnts, NULL, NULL, knotStyle, &result) && result.IsValid())
{
  // yay, your interpolated curve is ready to use
}

Option 2:

ON_NurbsCurve* result = RhinoInterpCurve(pnts, NULL, NULL, knotStyle, NULL);
if (result)
{
  if (result->IsValid()) 
  {
    // yay, your interpolated curve is ready to use
  }
  delete result;
}

thank you very much, Menno Dij.