# 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.

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."
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

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

2 Likes

Hi,
I want to thank you, @Michael_Pryor and @diff-arch 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

Just to add one little caveat to the solution presented here: DistanceTo() also returns 0 if one of the two points is invalid, so it might be required to check that both points are valid.

Requesting help.

I wanted to check with the list of surfaces whether the list points are there on any surfaces. When am running the code; I am getting an error, which is posted below. When am running the code only with one surface and one point, it is working.

It seems like you maybe have the Type Hint set to Surface, which you dont need to do with rhinoscriptsyntax. Set it to ghdoc Object instead, and it should work.

1 Like