How to get the distance between a point and a shape in pythonocc-core?

800 views Asked by At

I had searched similar questions, With OpenCascade, how to do a collision detection of 2 shapes fast?.

Also ,here is the example srcipts: core_geometry_minimal_distance (code above)

But,It is hard for me to get any idea about : get the distance between a point and a shape.

Dose here have a easy way to get the distance between point and shape by pythonocc?

If it dose not, could anyane tell any idea about to get the distance?

In fact, I am trying to make a Adaptively Sampled Distance Fields.In my understanding,it is necessary to get a distance between point and shape during makeing it.

Also,Could anyone tell any idea about how to make a Adaptively Sampled Distance Fields?

If I do not explain clearly or use incorrect wording, tell me and I will fix it.

1

There are 1 answers

0
lanhao945 On BEST ANSWER

More than one week had gone.

The example ,author showed is :

https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_minimal_distance.py

Just use BRepBuilderAPI_MakeVertex to make a shape which is just a point to replace the box in the example's code.such as :


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()

and


_point_pnt = gp_Pnt(x, y, z)

vtx = BRepBuilderAPI_MakeVertex(_point_pnt).Shape() # shape type