def contains_points(mesh, points):
'''
Check if a mesh contains a set of points, using ray tests.
If the point is on the surface of the mesh, behavior is undefined.
Arguments
---------
mesh: Trimesh object
points: (n,3) points in space
Returns
---------
contains: (n) boolean array, whether point is inside mesh or not
'''
points = np.asanyarray(points)
vector = unitize([0,0,1])
rays = np.column_stack((points,
np.tile(vector,(len(points),1)))).reshape((-1,2,3))
hits = mesh.ray.intersects_location(rays)
hits_count = np.array([len(i) for i in hits])
contains = np.mod(hits_count, 2) == 1
return contains
评论列表
文章目录