Curve Middle Point

Hi,

I wanted to extract a curve middle point in C++ and got a result that I don`t understand. I thought that this makes sense:

ON_3dPoint MidPtCurve( ON_Curve* crv )
{
double t0,t1;
crv->GetDomain( &t0, &t1 );
double middomain = (t1 - t0)/2;
return crv->PointAt( t0 + middomain );
}

But when I tested it, I realized that the point is not at all in the middle of the curve…why? What is the way to do this?

Thanks!

Dont know if this is possible in C++ but this is how I do it in vb.NET

Dim DefLine As Geometry.Curve = Curve //Defined somewhere else.
Dim midPoint As Double = DefLine.GetLength / 2
Dim myMidPoint As Geometry.Point3d = DefLine.PointAtLength(midPoint)

Get the curve length, devide it by 2, get PointAtLength.

Does it help?

return crv->PointAt(middomain); //This should be work

This will return the mid point of a curve:

ON_3dPoint RhinoCurveMidPoint(const ON_Curve* curve)
{
  ON_3dPoint rc = ON_UNSET_POINT;
  if (0 != curve && curve->IsValid())
  {
    double curve_t = 0.0;
    if (curve->GetNormalizedArcLengthPoint(0.5, &curve_t))
      rc = curve->PointAt(curve_t);
  }
  return rc;
}

As for the reason why: a NURBS curve is a parametric curve, so it is a function of the parameter t

f(t) -> (x,y,z)

The “speed” with which the curve is drawn as the parameter t goes from the domain start (T0) to the domain end (T1) depends on a) the knot sequence of the curve and b) the location of the control points. So, evaluating the middle of the parameter domain (T1-T0)/2 is (almost) never equivalent to the middle of the curve in terms of its length. Instead, you need to find the parameter t, for which the curve’s length at that value is half of the length of the complete curve.

This is what the code of @dale and @jordy1989 does.