Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enes-oerdek/a3c087c1a93ae17d5f3d8f3594b5d652 to your computer and use it in GitHub Desktop.
Save enes-oerdek/a3c087c1a93ae17d5f3d8f3594b5d652 to your computer and use it in GitHub Desktop.
This gist is used on https://enesordek.com/?p=2515
// Demo found on https://enesordek.com/?p=2515
$fn=200;
width_inner_diff = 23.5;
width_innerhollow_delta = 27-width_inner_diff;
height_innerhollow = 16;
translate([-50,0,0])
rotate([180,0,90])
rotatedform();
translate([-20,0,0])
rotate([180,0,90])
cylinderform();
translate([0,15,0])
rotate([-90,0,0])
form();
module rotatedform() {
for(i = [0 : 60: 360]) {
rotate([0,0,i])
cylinderform();
}
}
module cylinderform() {
cylinder_extrude((width_inner_diff+width_innerhollow_delta)/2, r_delta=-width_innerhollow_delta/2, h=height_innerhollow*2) {
//translate([0,10,0])
form();
}
}
module form() {
rotate([0,180,0]) polygon(points=[
[0,0],
[0,height_innerhollow],
[-3.5,height_innerhollow],
[-3.5,8],
[-6.5, 6],
[-6.5, 7],
[-14.15,4],
[-14.15,0]
]);
}
// Take a 2d shape and extrude outward (or inward with r_delta < 0)
// from a theoretical cylinder of given radius and height (centered).
// Input geometry should fit within the bounds of [-PI*r_cyl, -h/2] and [PI*r_cyl, h/2]
module cylinder_extrude(r_cyl, r_delta, h, eps=0.01) {
frags = fragments(r_cyl);
r_corr = r_cyl * cos (180/frags); // get corrected radial offset of cylinder flats
r_inner = r_delta < 0 ? r_corr + r_delta : r_corr - eps;
r_outer = r_delta < 0 ? r_corr + eps : r_corr + r_delta;
stripw = 2 * r_cyl * sin(180/frags);
prescale = r_inner / r_corr;
scaler = r_outer / r_inner;
//echo(r_inner, r_outer, frags, stripw, scaler);
for(j=[each [0.5:1:frags/2+0.5] ], k=[-1,1]) let(i=j*k) {
rotate([90,0,90+i*360/frags]) translate([0,0,r_inner]) {
linear_extrude(abs(r_delta)+eps, scale=[scaler,1], convexity=4) {
scale([prescale,1]) translate([-i*stripw, 0, 0]) intersection() {
translate([i*stripw, 0]) square([stripw+eps, h], center=true);
children();
}
}
}
}
}
// based on get_fragments_from_r documented on wiki
// https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#$fa,_$fs_and_$fn
function fragments(r=1) = ($fn > 0) ?
($fn >= 3 ? $fn : 3) :
ceil(max(min(360.0 / $fa, r*2*PI / $fs), 5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment