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

I calculated multiple ray intersection on several surfaces.
Now i want to identify the surfaces/faces where those intersections happened and cull the others that don’t intersect.
For that purpose I’m trying to find the equivalent of rs.isPointOnSurface in Rhinocommon … with no success quite several hours,
I’ll appreciate any help to find this command or other options to achieve the goal.

You can use https://developer.rhino3d.com/5/api/RhinoCommon/html/M_Rhino_Geometry_Surface_ClosestPoint.htm

then test distance from closest point to test point. If it is 0.0 (or might be better to test via tolerance, like if (distance <= tolerance)) then it is on surface.


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
      object_id: the object's identifier
      point: list of three numbers or Point3d. The test, or sampling point
      True if successful, otherwise False
      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."
      print "The point is not on the surface."
    See Also:
    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
            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.

1 Like

Well yes, it’s saying the method I mentioned above. :grinning: Surface closest point and measure distance against tolerance.

1 Like

I want to thank you, @Michael_Pryor and @p1r4t3b0y for your quick responses.
Problem solved and works fine.
The INSPECT library is a nice finding. Can save a lot of time.

Thanks again,

1 Like