Skip to content

Instantly share code, notes, and snippets.

@kelvie
Created July 30, 2020 02:52
Show Gist options
  • Save kelvie/e196aa61d4b06c5e1c81e48e34e46b0b to your computer and use it in GitHub Desktop.
Save kelvie/e196aa61d4b06c5e1c81e48e34e46b0b to your computer and use it in GitHub Desktop.
Add a chamfered base to an arbitrary shape in openscad
$eps=0.01;
// min feature size
$fs=0.025;
// angle to render as a single feature in a circle
$fa=3;
// Adds a base to avoid elephant's foot on SLA prints
// when printing Z=0 face downward
// inset defaults to height, layers create a graduation
// Optionally take a 2d base as the second child to avoid a
// projection to figure out the shape of the base
module addBase(height, inset=-1, layers=1) {
// epsilon to make sure layers merge without coplanar surfaces
$eps = height / layers / 100;
for (i = [0:layers-1])
translate([0, 0, i*height/layers])
linear_extrude(height/layers + $eps)
offset(delta=-(inset -i*inset/layers), chamfer=true)
if ($children > 1)
children(1);
else
projection(cut=true)
children(0);
translate([0, 0, height])
children(0);
}
module shape() {
difference() {
square(10);
translate([4, 4]) circle(d=2);
}
}
addBase(height=0.2, inset=0.4, layers=20) {
linear_extrude(10) shape();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment