Skip to content

Instantly share code, notes, and snippets.

@thehans
Last active December 30, 2020 21:40
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 thehans/e3530924ed47f37da4055f8a95aa6966 to your computer and use it in GitHub Desktop.
Save thehans/e3530924ed47f37da4055f8a95aa6966 to your computer and use it in GitHub Desktop.
OpenSCAD Rounded poly disk example. Different radii for xy vs z
n = 8;
height = 40;
width = 50; // distance across flats of polygon (when n is even)
rxy = 8;
rz = 3;
width2 = 30;
rxy2 = rxy*width2/width;
rz2 = 0.1; // small but nonzero
$fn=5*n;
module rounded_poly_disk(w, rxy, rz, n) {
R = circumradius(w/2,n)-circumradius(rxy,n);
a = 360/n;
hull() rotate(a/2) for(i=[0:n-1])
rotate(a*i) translate([R,0,0])
rotate(-a/2) rotate_extrude(angle=a) translate([rxy-rz,0])
semicircle(rz);
}
module semicircle(r) {
intersection() {
translate([0,-r*1.5]) square(r*3);
circle(r=r);
}
}
translate([0,0,rz]) hull() {
rounded_poly_disk(width,rxy,rz,n);
translate([0,0,height-rz-rz2]) rounded_poly_disk(width2,rxy2,rz2,n);
}
function circumradius(inradius,n) = inradius/cos(180/n);
function inradius(circumradius,n) = circumradius*cos(180/n);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment