Minkowski Sum for Mesh, a curiosity

Hi! This is someting to use when there is a need for tolerance in custom direction, and model definition hasn’t proper tolerance adjust.
Example for create socket in plate:

How this works:
According to wiki: “For all non-empty subsets S1 and S2 of a real vector space, the convex hull of their Minkowski sum is the Minkowski sum of their convex hulls”. In other words concave mesh is ‘convex decomposed’ to convex parts using library ‘CoACD’, then convex parts are added together, on result is performed convex hull, and on the last step all parts are Union together using library ‘Manifold3d’.

Note:
Before you run .gh attached example files, disable solver for finish download needed python libraries: "CoACD, Manifold3d, Scipy, Trimesh’. When is all ok, click button ‘Run MinSum’ - its added to prevent ‘Race condition’ when loading file (is likely of c# loading scripts).

Case One:
The creation of XT60E socket, mounted in 3d printed plate:


XT60E_example.gh (51.3 KB)

Case Two:
Perform minkowski sum between planar region and detal, for generic looking cellphone.



MinSum_komorka.gh (106.7 KB)

In my OpenSCAD days, it was an Ace when dealing with assembly parts, and to compansate shrinkage when annealing special PLA material blend. I hope you find it’s interesting.

2 Likes

XT60E_example.gh (51.3 KB)

This doesn’t work on my end. I’m just curious, could you internalise the result or post a separate file which shows the result?

Sure,
xt60_example.3dm (203.1 KB)
komorka_example.3dm (298.2 KB)
I like to add, exact steps to I hope will work on your end.

  1. Open GrassHopper.
  2. Disable Solver.
  3. Load GH file.
  4. Disable component Minkowski.
  5. Enable Solver.
  6. Create empty Python script, open it, go to packet menager and start adding:
    coacd, scipy, trimesh, manifold3d, wait for install, component can be delated.
  7. Enable component Minkowski. click button or hardwired it.

This way Grashopper will cache libraries on fresh start.

1 Like

Thanks. I looked at the simple iphone example you posted before but for the subtraction of this plug I don’t understand the point yet. The geometry in the layer XT60E Result Minkowski appears to be an offset version of the exact geometry.

At least the iphone shape being all convex could be created with a convex hull too.

convex-hull.gh (260.9 KB)

that’s the core behavior of the Minkowski sum, in GH terms it’s like if you translate B on “every possible superposition” over item A (no change of its orientation) and then make the final boolean solid union of all the states of all the Bs together

like here, imagine you translate B in every possible position over A:

you get this:

Thanks @inno I understand it on the iPhone example but on the other object the OP showed I don’t see what it does just yet?

To be able to subtract the overall shape of a plug, something like a multi level convex hull would be needed. There was another topic not long ago about this but I don’t remember which it was.

Depending on the needed resolution, this could be done with Isopod or Shrinkwrap.

minkowski-isopod.gh (100.0 KB)

Shrinkwrap wins this game here:

the result of the operation is similar to a solid offset, but the way you get to the final shape is through applying a solid part (B) over another solid part (A)

OP’s example is nice, but in order to really show the magic of this I think it would be even better to show a part B which does not have axial simmetry, or off center :+1:

when you “slide” the tolerance cube over the surface of the plug (front view) you get a theoretical situation like this:

so it becomes something like:

pretty accurate sketch lol:

but instead of a cube centered on its perfect center you could use something like half a cube half a sphere, and you would get all the rightside of the original object with fillets and all the leftside of the object with sharp edge:

or even using a shape aligned off its center, in order to get more offset on one side and less offset on the other:

3 Likes

minkowski-shrinkwrap.gh (19.5 KB)

This one has 18434 transformed instances…

I don’t see the benefit of clusters with scripts that need fiddling when I can do this with native components.

Version 2:
Added: Component to ensure all Python libs are loaded.
Added: ‘C# Braker’ to pass data inputs A, B when are not null, and input EN must be True.
Added: ‘PMP CHull’ list of cloudpoints are hulled in parallel, using ThreadPoolExecutor.
Added: More robust validation of face mesh.


MinSum_example_v2.gh (103.0 KB)

1 Like

This works but I’m still wondering about the actual use? Your shape for the population is a simple cube so the result is very close if not identical to an offset…

Ok, Martin so as you saw exemples of sweeping shape B along surface of A (thanks to inno), next thing is montion plannig:
Take for example static 3d game level and yours movable actor is inscribe in static box (non rotational - sbox) with point represent centrum of mass.
Now you can use two approches of colision detection (family of C-space):

  1. Per basis, on demand actor and game objects using GJK (minkowski difference), not suitable for checkings colisons with ceilings, walls etc.,
    too much pipeline overload.
  2. Create geodata, volume boundary domain for allowed movment by sweeping all static walls, ceilings, ground etc. - with your actor box representation (minkowski sum): domain XY: -half size xy to + half size xy of this sbox, and for Z: - max heigth of sbox from center of mass (head of an actor close to ceiling) To some positive value for feet above ground. It’s very efficient way of colisions avoidence, because it’s baked and can be updated (add extra boolan union to domain during cut-scene).
    deep dive
    overview

For tweaking Convex decomposition, link to coacd api (in YNCD cluster):
CoACD API documentation
I left everything at default, except PCA alignment, an extrusion post-processing is controled by boolan TORB.

I like this cluster approch it can restrict the preview to core components of function. And I would like to learn more of how to make c-bindings, and use Native-library or PInvoke to implement bindings into C# code, but c’mon I bought Rhino to use Grasshopper, not visual studio, moreover all this libs uses py-binding, python script only send data to C++, performance lost is minimal, anyway it’s weekend project and unique at least on forum :slight_smile:

An example of collision detection, using ‘minkowski difference’, GJK is simplified version of this.
The transparent elements show the detection status. The Minkowski difference result moves, in sync to -B, when B tuches A, then result of op. contains the point [0,0,0] and a collision is found. Video below.


Img of solution:


and gh file:
collision_detection.gh (59.9 KB)