Rhinocommon - Ghpython - How to find if a point lies on a surface

Hi,

Today, I learned that you can actually look up the source code of rhinoscriptsyntax functions, which are basically only “wrappers” for rhinocommon. It can be done like this:

import rhinoscriptsyntax as rs
import inspect

print inspect.getsource(rs.IsPointOnSurface)

In your case, it would be useful to look at the rs.IsPointOnSurface function, and re-engineer it for your own goals.

Here’s what the print statement puts out:

def IsPointOnSurface(object_id, point):
    """Verifies that a point lies on a surface
    Parameters:
      object_id: the object's identifier
      point: list of three numbers or Point3d. The test, or sampling point
    Returns:
      True if successful, otherwise False
    Example:
      import rhinoscriptsyntax as rs
      surf = rs.GetObject("Select a surface")
      if rs.IsSurface(surf):
      point = rs.GetPoint("Pick a test point")
      if point:
      if rs.IsPointOnSurface(surf, point):
      print "The point is on the surface."
      else:
      print "The point is not on the surface."
    See Also:
      IsPointInSurface
    """
    surf = rhutil.coercesurface(object_id, True)
    point = rhutil.coerce3dpoint(point, True)
    rc, u, v = surf.ClosestPoint(point)
    if rc:
        srf_pt = surf.PointAt(u,v)
        if srf_pt.DistanceTo(point)>scriptcontext.doc.ModelAbsoluteTolerance:
            rc = False
        else:
            rc = surf.IsPointOnFace(u,v) != Rhino.Geometry.PointFaceRelation.Exterior
    return rc

I hope this helps!

A big thanks, should go out to @Dancergraham, for pointing this out today.

2 Likes