Is Point on Curve?


#1

Hi everyone…
I have some points and curves (edges). How to decide that a point is on a particular curve, is there some function in Rhino SDK?
Thanks


#2

Not sure if there’s a specific function that does what you want, but you could try Curve.ClosestPoint():
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Curve_ClosestPoint_1.htm

Setting the max distance appropriately low should return false if the point is not on the curve.


#3

There is the method on the Curve class class Contains:
http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Curve_Contains.htm

// small example
Curve c;
PointContainment pc = c.Contains(pt);
bool isOnCurve = pc.Equals(PointContainment.Coincident);

(Dale Fugier) #4

How about this:

bool IsPointOnCurve( 
  const ON_Curve* curve,
  const ON_3dPoint& point,
  double tolerance
  )
{
  bool rc = false;
  if (0 != curve)
  {
    if( tolerance < ON_SQRT_EPSILON )
      tolerance = ON_SQRT_EPSILON;

    double t = 0.0;
    if( curve->GetClosestPoint(point, &t) )
    {
      ON_3dPoint pt;
      if( curve->EvPoint(t, pt) )
      {
        if( point.DistanceTo(pt) <= tolerance )
          rc = true;
      }
    }
  }

  return rc;
}