问题描述
我搜索过类似的问题,With OpenCascade,how to do a collision detection of 2 shapes fast?。
另外,这里是示例源代码:core_geometry_minimal_distance(上面的代码)
这里有一个简单的方法可以通过pythonocc获得点和形状之间的距离吗?
如果没有,有没有人可以告诉任何关于获得距离的想法?
其实我是在做一个Adaptively Sampled distance Fields
。按照我的理解,在做的过程中需要得到点和形状之间的距离。
另外,有人能告诉我如何制作 Adaptively Sampled distance Fields
的任何想法吗?
如果我没有解释清楚或使用了不正确的措辞,请告诉我,我会修复它。
解决方法
一个多星期过去了。
作者展示的例子是:
https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_minimal_distance.py
只需使用 BRepBuilderAPI_MakeVertex
制作一个形状,它只是一个点来替换示例代码中的框。例如:
from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.SimpleGui import init_display
from OCC.Core.gp import gp_Pnt,gp_Ax2,gp_Circ
from OCC.Extend.ShapeFactory import make_edge,make_vertex
def compute_minimal_distance_between_cubes(b1,b2):
display.DisplayShape([b1,b2])
dss = BRepExtrema_DistShapeShape()
dss.LoadS1(b1)
dss.LoadS2(b2)
dss.Perform()
assert dss.IsDone()
return dss.Value()
和
_point_pnt = gp_Pnt(x,y,z)
vtx = BRepBuilderAPI_MakeVertex(_point_pnt).Shape() # shape type