138 lines
3.1 KiB
OpenSCAD
138 lines
3.1 KiB
OpenSCAD
include <detail-config.scad>;
|
|
|
|
|
|
|
|
function _scale(sv,vec2)=scale_vec(sv,vec2);
|
|
|
|
|
|
|
|
function default(val,comp) = val != undef ? val : comp;
|
|
function ycircle(x,r,cx=0,cy=0) = (2*cy + sqrt(8*cx*x-4*cx*cx-4*(x)*(x)+4*r*r))/2;
|
|
|
|
|
|
function scale_vec(sv,vec2)= let(l=len(sv))
|
|
[ for(v = vec2)
|
|
[for(i = [0:1:l-1]) v[i]*sv[i] ]];
|
|
|
|
function flatten_vec(list) = [ for (i = list, v = i) v ];
|
|
|
|
|
|
|
|
module move(x=0,y=0,z=0) {
|
|
translate([x,y,z]) children();
|
|
}
|
|
|
|
module flip_x() {
|
|
mirror([1,0,0]) children();
|
|
}
|
|
module flip_y() {
|
|
mirror([0,1,0]) children();
|
|
}
|
|
|
|
module flip_z() {
|
|
mirror([0,0,1]) children();
|
|
}
|
|
|
|
|
|
module dcircle_cutout(r,angle) {
|
|
difference() {
|
|
dcircle(r);
|
|
rotate([0,0,180]) move(y=-r) square(2*(r));
|
|
rotate([0,0, -(angle)]) move(x=-r) square(2*(r));
|
|
}
|
|
}
|
|
module ring(rs,rl) {
|
|
difference() {
|
|
rcircle(max(rs,rl));
|
|
rcircle(min(rs,rl));
|
|
}
|
|
}
|
|
/**
|
|
* FIXME: Find better name & document this
|
|
*/
|
|
module semiegg(rc,rf,xcf, ycf) {
|
|
echo("rc,rf,xcf,ycf",rc,rf,xcf, ycf);
|
|
function _rc(rf,dcf,rc) = (pow(rf,2)-pow(rc,2)-pow(dcf,2))/(2*(rf-rc));
|
|
lrcb= _rc(rf,ycf,rc+xcf);
|
|
|
|
lccb=ycf*(lrcb/(lrcb-rf));
|
|
rrcb= _rc(rf,ycf,rc-xcf);
|
|
rccb=ycf*(rrcb/(rrcb-rf));
|
|
union() {
|
|
move(y=ycf,x=xcf) rcircle(rf);
|
|
intersection() {
|
|
move(x=lrcb-rc) rcircle(lrcb);
|
|
move(x=-rc) square([rc,lccb]);
|
|
}
|
|
intersection() {
|
|
move(x=-rrcb+rc) rcircle(rrcb);
|
|
square([rc,rccb]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* FIXME: Find better name & document this
|
|
**/
|
|
module curved(h,w_bottom,w_top) {
|
|
curve_h=h;
|
|
curve_w=w_top-w_bottom;
|
|
circle_y=curve_w>0 ? 0 : curve_h;
|
|
curve_r = curve_r(curve_h,curve_w);
|
|
echo(curve_w, curve_r);
|
|
move(x=-min(w_bottom,w_top)) difference() {
|
|
move(x=-abs(curve_w)) square([max(w_top,w_bottom),curve_h]);
|
|
move(x=-curve_r,y = circle_y) rcircle(curve_r);
|
|
}
|
|
}
|
|
|
|
function curve_r(curve_h,curve_w)=(pow(curve_h,2)+pow(curve_w,2))/(2*abs(curve_w));
|
|
|
|
|
|
module dring_s_cutout(l,h,hf,hb) {
|
|
ct = curve_r(l,h-hb);
|
|
cb = curve_r(l,h-hf);
|
|
intersection() {
|
|
move(x=-h) square([h,l]);
|
|
difference() {
|
|
move(x=-cb) dcircle(cb);
|
|
move(x=-ct-hb) dcircle(ct);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
module concave_extrude(height,s=2,steps=20,angle=90) {
|
|
ad=angle/steps;
|
|
function z(i)=1-cos(ad*i);
|
|
function s(i)=(s-1)*sin(ad*i)+1;
|
|
|
|
h=height/z(steps);
|
|
for(i=[0:1:steps-1]) {
|
|
_extrude_step(h*z(i),h*z(i+1),s(i),s(i+1)) children();
|
|
}
|
|
}
|
|
|
|
module convex_extrude(height,s=2,steps=10,angle=90) {
|
|
ad=angle/steps;
|
|
function z(i)=sin(ad*i);
|
|
function s(i)=s-(s-1)*cos(ad*i);
|
|
|
|
h=height/z(steps);
|
|
for(i=[0:1:steps-1]) {
|
|
_extrude_step(h*z(i),h*z(i+1),s(i),s(i+1)) children();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
function shell_layers(layers)=
|
|
let(p=len(layers[0]))
|
|
let(l=len(layers))
|
|
flatten(
|
|
[for (i = [0:1:l-2])
|
|
[for (j = [0:1:p-1]) p*[i,i,i+1,i+1]+[j,(j+1)%p,(j+1)%p,j] ]
|
|
]
|
|
);
|