# Check if point is within a closed brep - Rhino Common or Rhinoscript

Hello All,

How do I check if a point is within a solid brep using python?

I know that grasshopper has a component called “Point in Brep", but I am scripting in Python 3 (Rhino WIP), and I only have access to Rhino Common or Rhinoscript. In rhino script, there is a feature called (Rhino.IsObjectInBox(brick.ObjectId,boundingBox), but this only works with bounding boxes from my understanding, and not with breps that are trapezoidal.

I wrote the following code which also works for plan boxes as the bounding box, but I need to cover a wider range of cases.

``````def isBrickWithinBounds(brick,bounds):

boundsDict = getBoundingBoxMaximumsAndMinumums(boundingBox) #dict

bounds =     [  [boundsDict['minX'],     boundsDict['maxX']],
[boundsDict['minY'],     boundsDict['maxY']],
[boundsDict['minZ'],     boundsDict['maxZ']]     ]

brickCentroid = rg.AreaMassProperties.Compute(brick).Centroid

if (not boundsDict['minX'] < brickCentroid.X < boundsDict['maxX']):
#print('outsideX')
return False
elif (not boundsDict['minY'] < brickCentroid.Y < boundsDict['maxY']):
#print('outsideY')
return False
elif (not boundsDict['minZ'] < brickCentroid.Z < boundsDict['maxZ']):
#print('outsideZ')
return False

return True
``````

Assigned to Scripting category

Brep.IsPointInside method (rhino3d.com)

Note that you need to make two separate checks on the character of the Brep (closed and manifold).

(haven’t used that one yet myself)

1 Like

No way, how did I not find this? I did scour the docs for a few hours…