Skip to content

Instantly share code, notes, and snippets.

@arnholm
Last active February 9, 2020 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnholm/e5df0a3edbe9d4aa65400a9308637861 to your computer and use it in GitHub Desktop.
Save arnholm/e5df0a3edbe9d4aa65400a9308637861 to your computer and use it in GitHub Desktop.
minkowski3d_3.as - Demonstrates 3d filetting using minkowski
// AngelCAD sample: minkowski3d_3.as
// Demonstrates 3d filetting using minkowski3d

solid@ object(double sz)
{
   // cuboids extending in 3 axis directions
   return   translate(-sz,0,0) * cuboid(2*sz,sz,sz)
          + translate(0,-sz,0) * cuboid(sz,2*sz,sz)
          + cuboid(sz,sz,2*sz);
}

solid@ erode(solid@ obj, double r)
{
   // create a cube enclosing the object completely
   // with an internal void shaped by the object
   double diag = obj.box().diagonal();
   solid@ d1 = cube(diag*2,center:true) - obj;
   
   // make the void smooth
   solid@ m1 = minkowski3d(d1,sphere(r));
   return obj - m1;
}

shape@ main_shape()
{
   return erode(object(sz:100),20.0);
}

void main()
{
   shape@ obj = main_shape();
   
   // export as .xcsg 
   obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.01);
   
   // export as OpenScad .csg
   obj.write_csg(GetInputFullPath());
}
// This file was created using AngelCAD (as_csg) v1.3-02
// Copyright(C) 2015-2018 Carsten Arnholm, http://arnholm.org/
// Open it with OpenSCAD for display or further processing
$fn = 60;
$fa = 6.0;
$fs = 1.0;
group() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
difference() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
union() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
union() {
multmatrix([[1,0,0,-100],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
cube( size=[200, 100, 100] , center=false );
}
multmatrix([[1,0,0,0],[0,1,0,-100],[0,0,1,0],[0,0,0,1]]) {
cube( size=[100, 200, 100] , center=false );
}
}
}
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
cube( size=[100, 100, 200] , center=false );
}
}
}
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
minkowski() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
difference() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
cube( size=[692.820323028, 692.820323028, 692.820323028], center=true );
}
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
union() {
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
union() {
multmatrix([[1,0,0,-100],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
cube( size=[200, 100, 100] , center=false );
}
multmatrix([[1,0,0,0],[0,1,0,-100],[0,0,1,0],[0,0,0,1]]) {
cube( size=[100, 200, 100] , center=false );
}
}
}
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
cube( size=[100, 100, 200] , center=false );
}
}
}
}
}
multmatrix([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) {
sphere( r=20 );
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment