Minkowski Sum in python
I'm looking to perform a minkowski sum of two meshes. It seems that in C++ there is a function to do so for a mesh and a curve. Would it be possible to add these to the exposed python functions. I'd like to compute the minkowski sum for every contour coming from slicing the original shape. As a whole I'm looking for the functions to perform the following operations:
- Offset a shape (
shape_a) to the inside - Slice the
offsetted shapeusing a plane to createcontoursat different heights - Per
contourperform a minkowski sum using a tool mesh (shape_b) - Intersect the
shape_bandshape_ato find the collision areas - Computed the closest point for all vertices in
shape_awith respect to theshape_bto find all the areas that could not be reached by the tool.
Hello!
I think function makeMovementBuildBody can be helpful to you (if tool mesh has axial symmetry)
we will expose it to python:
from meshlib import mrmeshpy as mm
inputMesh = mm.makeCube() # shape_a mm.loadMesh("shape_a,stl")
box = inputMesh.computeBoundingBox()
step = (box.max.z - box.min.z)/11
start = box.min.z + step/2
# create tool profile
bodyContours = mm.Contours3f()
bodyContours.resize(1)
bodyContours[0].resize(5)
bodyContours[0][0] = mm.Vector3f(-0.01,-0.01,0)
bodyContours[0][1] = mm.Vector3f(0.01,-0.01,0)
bodyContours[0][2] = mm.Vector3f(0.01,0.01,0)
bodyContours[0][3] = mm.Vector3f(-0.01,0.01,0)
bodyContours[0][4] = bodyContours[0][0] # make sure that profile is closed
sumMesh = mm.Mesh()
while start < box.max.z:
plane = mm.Plane3f()
plane.n = mm.Vector3f(0,0,1)
plane.d = start
plSections = mm.extractPlaneSections(inputMesh, plane)
contours = mm.Contours3f()
contours.resize( plSections.size() )
for i in range(len(plSections)):
contours[i].resize(plSections[i].size())
for j in range(plSections[i].size()):
contours[i][j] = inputMesh.edgePoint( plSections[i][j] )
moveMesh = mm.makeMovementBuildBody(bodyContours,contours)
sumMesh.addPartByMask(moveMesh,moveMesh.topology.getValidFaces())
start = start + step;
pass
mm.saveMesh(sumMesh,"sumMesh.stl")
# offset here to fix possible self-intersections and internal surface parts
sumMesh = mm.offsetMesh(sumMesh,0)
mm.saveMesh(sumMesh,"sumMeshOff.stl")
Will it work for you?
That looks perfect! Thanks for the amazing quick response. I'll test and confirm back here if I run into anything further. So far I'm duly impressed by the speed of the library.