tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.38k stars 380 forks source link

Determining the midpoint of surface / point on surface #966

Open ghost opened 3 years ago

ghost commented 3 years ago

I would like to have a point "inside" a surface, not just on the boundary of the surface. Up till now, I have been unable to get it.

So I would like to have a point like this: image

The closest I got so far is this: image

which is based on the center of gravity, but there is still a distance between the point/vertex and the shape.

I was trying to achieve it with something like this:

def uv_from_projected_point_on_face(face, pt):
    # returns the uv coordinate from a projected point on a face

    srf = BRep_Tool().Surface(face)

    sas = ShapeAnalysis_Surface(srf)

    uv = sas.ValueOfUV(pt, 1e-2)

    print('distance ', sas.Value(uv).Distance(pt))

    return uv.Coord()

which is from https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_geometry_geomplate.py#L177 but the problem is that it only projects the point on the xz-plane, it does not seem to care about the distance in the x-direction. Probably this is intended, but how do I get around this?

Note: ValueOfUV is based on GeomAPI_ProjectPointOnSurface, so that routine has the same problem (https://liuxinwin_admin.gitee.io/pythonocc-docs/OCC.ShapeAnalysis.html#OCC.ShapeAnalysis.ShapeAnalysis_Surface.ValueOfUV)

So the goal is really to have a point on the surface, but not on the edge(s) of the surface.

tpaviot commented 3 years ago

Did you try the GeomAPI_ProjectPointOnSurf class?