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

Hi,
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.
Thanks,
-A.

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.

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.

1 Like

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

1 Like

Hi,
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,
-A.

1 Like