如何检查单个点是否在 pyvista 中的曲面内?

How to check if a single point is inside a surface in pyvista?

所以我有一个封闭的网格和一个点。如何检查一个是否在另一个里面?

我试过了:

def is_inside(point):
    points = pv.PolyData([point,])  
    point_in_question = points.points[0]
    select = mesh_model.select_enclosed_points(points)
    inside = select.threshold(0.5)
    if len(inside.points) >0:
            print(len(inside.points))
            print(f"inside atom {i}")
    else:
            print("outside")

但我在 len(inside.points) 中得到的不是一分,而是 1000 多分。那么如何检查一个点是否在网格内?

正如我在评论中建议的那样,您应该交换点查询网格和过滤器的封闭曲面:

import pyvista as pv

mesh_model = pv.Sphere()
points = [[0, 0, 0], [10, 10, 10]]
points_poly = pv.PolyData(points)
select = points_poly.select_enclosed_points(mesh_model)

现在 select'SelectedPoints' 点数组,第一个点(内部)为 1,第二个点(外部)为 0:

>>> select['SelectedPoints']
array([1, 0], dtype=uint8)

如果您收到有关曲面未关闭的错误消息(如您​​在评论中所述),则意味着您的 mesh_model 未关闭。您可以查看

mesh_model.n_open_edges

流形网格应该为 0。