Python 确定两个三维网格曲面之间的交点,一个在另一个内部
我有两个网格位于轴原点的中心,一个在另一个内。我在vtk中实现了一个简单的函数来缩放内部网格。其思想是在内部网格的表面与外部网格的表面接触时停止此循环。我试图使用vtk库,但什么也没找到。vtk布尔交集工作正常,但似乎没有用 你有办法解决这个问题吗?Python 确定两个三维网格曲面之间的交点,一个在另一个内部,python,3d,mesh,vtk,surface,Python,3d,Mesh,Vtk,Surface,我有两个网格位于轴原点的中心,一个在另一个内。我在vtk中实现了一个简单的函数来缩放内部网格。其思想是在内部网格的表面与外部网格的表面接触时停止此循环。我试图使用vtk库,但什么也没找到。vtk布尔交集工作正常,但似乎没有用 你有办法解决这个问题吗? vtk中是否有可以执行此操作的功能?您可以使用vtkInterface测试交叉口: import numpy as np import vtkInterface as vtki # create a test sphere sphere = vt
vtk中是否有可以执行此操作的功能?您可以使用
vtkInterface
测试交叉口:
import numpy as np
import vtkInterface as vtki
# create a test sphere
sphere = vtki.Sphere(radius=1.0)
# generate a cylinder inside the sphere and change its height
# and test for an intersection
for height in np.linspace(1, 3, 50):
cylinder = vtki.Cylinder([0, 0, 0], [1, 0, 0],
0.2, height).TriFilter()
# test intersection
cut_mesh = cylinder.BooleanCut(sphere)
# cut_mesh will be empty when there's no intersection
if cut_mesh.GetNumberOfPoints():
break
plotter = vtki.PlotClass()
plotter.AddMesh(sphere, style='wireframe')
plotter.AddMesh(cylinder, 'b', opacity=0.2, showedges=False)
plotter.AddMesh(cut_mesh, 'r', showedges=False)
plotter.Plot()
当圆柱体的高度为2.11时,此点相交,并生成以下绘图:
我看到您在为Mac OS安装vtkInterface时遇到问题。我已经更新了源代码并将0.11.3上传到PyPi。请使用以下软件重新安装:
pip install vtkInterface --upgrade
据我所知,VTK没有配备碰撞检测功能。您必须构建自己的工具。一些VTK用户在中讨论了您的问题。有一个实现了碰撞检测过滤器的。我从来没用过,所以说不出它有多好。这个项目看起来有点过时。好的,谢谢你的想法。最后利用距离来解决问题;该代码使用vtk.vtkCellLocator,计算每个单元的点,搜索三个顶点的坐标并计算每个单元的理想中心点。然后,使用FindClosestPoint函数,选择较低的距离,以便将内部网格移动到外部网格的表面。