joostn / OpenJsCad

3D solid CAD using only Javascript
313 stars 127 forks source link

fr: minkowski sum #87

Closed salamanders closed 4 years ago

salamanders commented 7 years ago

This project is awesome. I stumbled across it after using OpenSCAD and wondering why I had to learn a new language, why couldn't I just use JS, and lo and behold, here this was. Thank you! forum post here.

I immediately tried to transfer my script, and couldn't do rounded edges, because no minkowski sum. It is the best way I know to round out a cube's edges by summing with a sphere.

/*
Must be printed with support material.  
Best have support extend outwards so you can yank it out.
*/

$fn = 40;
// my badge dimensions
badge = [54, 87.31, 2.4];

module copy_mirror(vec = [0, 1, 0]) {
  children();
  mirror(vec) children();
}

union() {
    difference() {
        // Main structure
        union() {
            // Rounded edges for the main card holder
            minkowski() {
                cube([badge[0], badge[1], badge[2]-2], center = true);
                sphere(r = 2, center = true);
            };
            // Badge clip extension, 13mm wide
            color("green")
            translate([0, badge[1] / 2, 0])
            minkowski() {
                cube([17, 8, badge[2]-2], center = true);
                sphere(r = 2, center = true);
                //cylinder(r=2,h=1, center = true);
            }
        }

        // Bevel cutout replacing badge for angled edges
        color("red")
        cube(badge, center = true);

        // Viewing area cutout
        color("blue")
        cube([badge[0] - 5, badge[1] - 5, 20], center = true);

        // Badge loop cutout
        color("purple")
        translate([0, badge[1] / 2 + 1, 0])
        cube([13, 3, 20], center = true);

        // Top insert badge slot
        color("orange")
        translate([0, badge[1] / 2,0])
        cube([badge[0], 40, badge[2]-0.2], center = true);
    };
}
joostn commented 7 years ago

Hi! There's no generic minkowski sum but you can actually do a minkowski sum with a sphere: csg.expand() does just that.

See http://joostn.github.io/OpenJsCad/ (section Expansion and Contraction)

z3dev commented 7 years ago

@salamanders I think this request would be better as part of the scad-api library of the JSCAD organization. Here https://github.com/jscad/scad-api

I can move this issue to that repository if you want. Please let me know.

salamanders commented 7 years ago

Yes please.

On Feb 25, 2017 16:53, "Z3 Development" notifications@github.com wrote:

@salamanders https://github.com/salamanders I think this request would be better as part of the scad-api library of the JSCAD organization. Here https://github.com/jscad/scad-api

I can move this issue to that repository if you want. Please let me know.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/joostn/OpenJsCad/issues/87#issuecomment-282524035, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFNdpAqwhLL2tGuyWKLJj6QvUjvUQPvks5rgMzrgaJpZM4K2tqw .

z3dev commented 4 years ago

Will not fix.