OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

Missing function: Minkowski

Open larsrc opened this issue 5 years ago • 12 comments

Expected Behavior

minkowski(shape, sphere) => nicely rounded version of shape (well, the real definition is different, but that´s what I use it for:)

Actual Behavior

Uncaught Error: The JSCAD script must return one or more CSG or CAG solids.

(Not the greatest error message, either)

Steps to Reproduce the Problem

  1. Create this model:

function main () { return minkowski([ cube({size: 1, center: true}), sphere({r:1, center:true}) ]); }

  1. Attempt to render

Specifications

  • Version: 1.9.0
  • Platform: Asus Flip C302A
  • Environment: Chrome 74.0.3729.159 (Official Build)

larsrc avatar Jun 29 '19 19:06 larsrc

A good visualization for an algorithm in 2D space: https://www.youtube.com/watch?v=3qMNuoTHNHs

This also works on concave polygons!

jue89 avatar Dec 20 '21 17:12 jue89

@jue89 I am seing your box code and it looks very nicely organized. I am working on different improvements for jscad, and @z3dev is too.

Our time available for jscad varies. I am hoping you could give a try building such feature and contribute, maybe port from somewhere. It is one very big thing missing to be compatible with many OpenScad scripts regarding operations available to users.

hrgdavor avatar Dec 20 '21 19:12 hrgdavor

Our time available for jscad varies. I am hoping you could give a try building such feature and contribute, maybe port from somewhere. It is one very big thing missing to be compatible with many OpenScad scripts regarding operations available to users.

Sure. I stumbled across the video and just wanted to let everybody know how wants to give the implementation a try. It wasn't meant to force anybody to do the implementation ;-)

I could try to come up with an implementation during the upcoming holiday season. I'm still a little bit lost in the code base of JSCAD. (Which doesn't mean its badly organized! It's just a lot of code ...) And I'm not a mathematician, as well :-D But maybe some sketch code wich makes use of the available methods of JSCAD is also a good starting point?!

Are you around on IRC, Discord, Matrix, ...?

jue89 avatar Dec 20 '21 20:12 jue89

@jue89 I am active on discord

there is one on CadHub server https://discord.gg/AaqGskur93 and one on Elmer server https://discord.gg/UXtQcA6

I am currently on both, but I am watching where most users will prefer to be.

hrgdavor avatar Dec 20 '21 20:12 hrgdavor

@jue89

But maybe some sketch code which makes use of the available methods of JSCAD is also a good starting point?!

It does not need to be strictly meant as addition to jscad, I am just watching out for interested users to build-up an active community. Play with jscad, and see maybe what could be missing that is easy for you to implement that you would use yourself and others could too. Feel free to ask whatever on discord too, I am pretty chatty on the channel 😄

hrgdavor avatar Dec 20 '21 21:12 hrgdavor

2D is very easy… 3D is another level, and very difficult.

I don’t think there’s a free version of this exists today.

z3dev avatar Dec 21 '21 10:12 z3dev

Yeah. It may not be worth the hassle. Unless somebody that knows how to make it comes along maybe.

hrgdavor avatar Dec 21 '21 10:12 hrgdavor

When migrating from OpenSCAD, I was facing this issue and came up with the following solution. The following code may serve as inspiration. In essence, this computes a hull over the 'b' shape placed at outline points of the 'a' shape.

const { toOutlines } = require('@jscad/modeling').geometry.geom2;

const minkowski = function (a, b) {
    var points = toOutlines(a)[0];
    var chain = [];
    points.forEach((p) => {
        chain.push(translate([p[0], p[1]], b));
    });

    let hulls = []
    for (let i = 1; i < chain.length; i++) {
        hulls.push(hull(chain[i - 1], chain[i]))
    }

    var result = union(hulls);

    var lastHull = hull(chain[chain.length - 1], chain[0]);

    result = union(result, lastHull); // this line may be broken

    return result;
}

Disclaimer: However, this is at least one year old and not up to date with the repo (maybe broken). It only served as quick workaround and does not follow the correct minkowski procedure. Instead this attempts to reproduce the result. I also remember there were some pretty nasty bugs related to shape handling in JSCAD.

MatzeS avatar Dec 21 '21 10:12 MatzeS

I don’t think there’s a free version of this exists today.

Isn't OpenSCAD open source and they have a 3D version of the minkowski sum?

jue89 avatar Dec 21 '21 11:12 jue89

Isn't OpenSCAD open source and they have a 3D version of the minkowski sum?

I think their engine is SDF(signed distance field) internally that is then converted to mesh Not sure if it can be ported as easily.

hrgdavor avatar Dec 21 '21 11:12 hrgdavor

Nevertheless, I would say a 2D version is a great starting point!

jue89 avatar Dec 21 '21 12:12 jue89

I don’t think there’s a free version of this exists today.

Isn't OpenSCAD open source and they have a 3D version of the minkowski sum?

The underlying library (CGAL) does the heavy logic, and is 100% C++.

z3dev avatar Dec 21 '21 21:12 z3dev