//Title: mhlib Matthieu's verzameling handige modules //Author: Matthieu Hendriks //Date: 10-9-2021 //License: Creative Commons use //*********************** // copieer child object en spiegel //copy_mirror() mv(5,5) cube(3); //*********************** module copy_mirror(vec=[0,1,0]) { union() { children(); mirror(vec) children(); } }; module cR() { color("Red") children(); } //*********************** // plaats 3 d text , start op 0,0 langs de x-as //txt("dit is een test",s=5); //*********************** module txt(str="",s=3,h=2,color="Blue") { size=(s<3) ? 3: s; color(color) linear_extrude(2) { text(str,size=size); } } //*********************** // plaatst een 3-d lineaal , met per mm 1 streepje en per 10mm een grote streep, met cijfers. // het kann afgedrukt worden maar is niet ideaal. //liniaal(); //*********************** module liniaal(lng=50) { d=0.4; union() { linear_extrude(2) union() { for(i=[0:lng] ) { mvx(i-d/2) square([d,2.5]); } for(i=[0:5:lng] ) { mvx(i-d/2) square([d,3.5]); } for(i=[0:10:lng] ) { mvx(i-d/2) square([d,5]); } } for(i=[10:10:lng]) { mv([i-3.5,2.4,0]) txt(str(i/10),s=4); } } } //*********************** // iets met ronde hoeken ?? //rounded_corner(rot=90,$fn=100); //*********************** module rounded_corner(vec=[10,0,0],rot=0,r=6.5,h=5,r2=1.5) { translate(vec) rotate([0,0,rot]) difference(){ // intersection(){ cylinder(r=r,h=h+.5); translate([-r,0,0]) cube([r,r,h]); }; mvz(-0.01) cylinder(r=r2,h=h+0.015); }; //*************************** // is normale cylinder functie met de optie om hem hol te maken // ************************** //pipe(d1=5,d2=6,iD1=3,iD2=4); module pipe(h=10,d=5,d1=0,d2=0,iD=0,iD1=0,iD2=0,fn=128) { d1=(d1==0) ? d: d1; d2=(d2==0) ? d: d2; iD1=(iD1==0) ? iD: iD1; iD2=(iD2==0) ? iD: iD2; difference() { cylinder(h=h,d1=d,d2=d,$fn=fn); mvz(-0.001) cylinder(h=h+0.002,d1=iD1,d2=iD2,$fn=fn); } } module draaiKnop(type="M18",h=10,arc=5,extra=-5, schroef=1){ douter = thread_specs(str(type, "-int"))[2]; r=douter+extra; w=douter/2; if(schroef == 1) color("Green") nut(type, getTurns(type,h-2.5), douter/2, higbee_arc=arc); color("Red") difference(){ hull(){ union(){ translate([0,0,0]) cylinder(r=0.7878*r,h=0.1250*h); //Top for(i=[0:60:360]) rotate(i){translate([0.5455*r,0,0.1250*h]) color("Blue") cylinder(r=0.4545*r,h=(0.7500)*h);} //Center translate([0,0,(7/8)*h]) cylinder(r=0.7878*r,0.125*h); //Bottom } //union } //hull union(){ for(i=[0:60:360]) rotate(i+30) translate([1.2828*r,0,0]) cylinder(r=0.4393*r,h=h); //Knob Grip Grooves Removal translate([0,0,-0.01]) cylinder(r=w,h=h+0.02); //Lid Room Subtraction } //union } //difference } module donut(r=10,w=1,fn=128) { translate([0,0,w/2]) union() { rotate_extrude(convexity = 10,$fn=fn) translate([r, 0, w]) circle(d = w,$fn=fn); } } module openBox(w=10,d=10,h=10,wall=1) { union() { difference() { cube([w,d,h]); translate([wall,wall,wall]) cube([w-wall*2,d-wall*2,h+0.01]); } } } module openCube(w=10,d=10,h=10,wall=1) { union() { difference() { cube([w,d,h]); translate([wall,wall,-0.01]) cube([w-wall*2,d-wall*2,h+0.02]); } } } module groundPin(lengte=100,b=10,w=2) { translate([0,0,w]) union() { hull() { translate([0,0,lengte]) sphere(w); translate([-b,-b,0]) sphere(w); translate([b,b,0]) sphere(w); } hull() { translate([0,0,lengte]) sphere(w); translate([b,-b,0]) sphere(w); translate([-b,b,0]) sphere(w); } } } module potDeksel(dia=71.3,dH=9.2, fn=128, wall=1) { idia=dia-3.4; kdia=(idia-1)/2; difference() { cylinder(d=dia,h=dH,$fn=fn); mvz(wall) color("Green") cylinder(d=idia,h=dH,$fn=fn); } h=1.5; offs=dH-h-0.6; mv([getX(kdia,315),getY(kdia,315),offs]) color("Red") klem(rot=45,h=h); mv([getX(kdia,225),getY(kdia,225),offs]) color("Red") klem(rot=135,h=h); mv([getX(kdia,135),getY(kdia,135),offs]) color("Red") klem(rot=45,h=h); mv([getX(kdia,45),getY(kdia,45),offs]) color("Red") klem(rot=135,h=h); donut(dia/2,w=2); module klem(d=3,l=10,h=1,rot=45) { rotz(rot) hull() { color("Red") mvx(-l/2 ) cylinder(d=3,h=h); color("Red") mvx(l/2) cylinder(d=3,h=h); } } } module roundedPlate(r=1,w=20,b=30,h=2,fn=128) { linear_extrude(h) hull() { translate([0+r,r,0]) circle(r=r,$fn=fn); translate([b-r,r,0]) circle(r=r,$fn=fn); translate([r,w-r,0]) circle(r=r,$fn=fn); translate([b-r,w-r,0]) circle(r=r,$fn=fn); } } module roundedBox(r=1,w=20,b=30,h=2,fn=128) { // linear_extrude(h) mvz(r) hull() { translate([0+r,r,0]) sphere(r=r,$fn=fn); translate([b-r,r,0]) sphere(r=r,$fn=fn); translate([r,w-r,0]) sphere(r=r,$fn=fn); translate([b-r,w-r,0]) sphere(r=r,$fn=fn); translate([0+r,r,h]) sphere(r=r,$fn=fn); translate([b-r,r,h]) sphere(r=r,$fn=fn); translate([r,w-r,h]) sphere(r=r,$fn=fn); translate([b-r,w-r,h]) sphere(r=r,$fn=fn); } } module pinhole(h=10, r=4, lh=3, lt=1, t=0.3, tight=false) { // h = shaft height // r = shaft radius // lh = lip height // lt = lip thickness // t = tolerance // tight = set to true if you want a joint that won't spin easily union() { pin_solid(h, r+(t/2), lh, lt); cylinder(h=h+0.2, r=r); // widen the cylinder slightly // cylinder(h=h+0.2, r=r+(t-0.2/2)); if (tight == false) { cylinder(h=h+0.2, r=r+(t/2)+0.25); } // widen the entrance hole to make insertion easier translate([0, 0, -0.1]) cylinder(h=lh/3, r2=r, r1=r+(t/2)+(lt/2)); } } module pin(h=10, r=4, lh=3, lt=1, side=false) { // h = shaft height // r = shaft radius // lh = lip height // lt = lip thickness // side = set to true if you want it printed horizontally if (side) { pin_horizontal(h, r, lh, lt); } else { pin_vertical(h, r, lh, lt); } } module pintack(h=10, r=4, lh=3, lt=1, bh=3, br=8.75) { // bh = base_height // br = base_radius union() { cylinder(h=bh, r=br); translate([0, 0, bh]) pin(h, r, lh, lt); } } module pinpeg(h=20, r=4, lh=3, lt=1) { union() { translate([0, -h/4+0.05, 0]) pin(h/2+0.1, r, lh, lt, side=true); translate([0, h/4-0.05, 0]) rotate([0, 0, 180]) pin(h/2+0.1, r, lh, lt, side=true); } } // just call pin instead, I made this module because it was easier to do the rotation option this way // since openscad complains of recursion if I did it all in one module module pin_vertical(h=10, r=4, lh=3, lt=1) { // h = shaft height // r = shaft radius // lh = lip height // lt = lip thickness difference() { pin_solid(h, r, lh, lt); // center cut translate([-r*0.5/2, -(r*2+lt*2)/2, h/4]) cube([r*0.5, r*2+lt*2, h]); translate([0, 0, h/4]) cylinder(h=h+lh, r=r/2.5, $fn=20); // center curve // translate([0, 0, h/4]) rotate([90, 0, 0]) cylinder(h=r*2, r=r*0.5/2, center=true, $fn=20); // side cuts translate([-r*2, -lt-r*1.125, -1]) cube([r*4, lt*2, h+2]); translate([-r*2, -lt+r*1.125, -1]) cube([r*4, lt*2, h+2]); } } // call pin with side=true instead of this module pin_horizontal(h=10, r=4, lh=3, lt=1) { // h = shaft height // r = shaft radius // lh = lip height // lt = lip thickness translate([0, h/2, r*1.125-lt]) rotate([90, 0, 0]) pin_vertical(h, r, lh, lt); } // this is mainly to make the pinhole module easier module pin_solid(h=10, r=4, lh=3, lt=1) { union() { // shaft cylinder(h=h-lh, r=r, $fn=30); // lip // translate([0, 0, h-lh]) cylinder(h=lh*0.25, r1=r, r2=r+(lt/2), $fn=30); // translate([0, 0, h-lh+lh*0.25]) cylinder(h=lh*0.25, r2=r, r1=r+(lt/2), $fn=30); // translate([0, 0, h-lh+lh*0.50]) cylinder(h=lh*0.50, r1=r, r2=r-(lt/2), $fn=30); // translate([0, 0, h-lh]) cylinder(h=lh*0.50, r1=r, r2=r+(lt/2), $fn=30); // translate([0, 0, h-lh+lh*0.50]) cylinder(h=lh*0.50, r1=r+(lt/2), r2=r-(lt/3), $fn=30); translate([0, 0, h-lh]) cylinder(h=lh*0.25, r1=r, r2=r+(lt/2), $fn=30); translate([0, 0, h-lh+lh*0.25]) cylinder(h=lh*0.25, r=r+(lt/2), $fn=30); translate([0, 0, h-lh+lh*0.50]) cylinder(h=lh*0.50, r1=r+(lt/2), r2=r-(lt/2), $fn=30); // translate([0, 0, h-lh]) cylinder(h=lh, r1=r+(lt/2), r2=1, $fn=30); // translate([0, 0, h-lh-lt/2]) cylinder(h=lt/2, r1=r, r2=r+(lt/2), $fn=30); } } module water_connector(bodem=19) { riA = 14/2; riB = 9/2-0.25; // rimthickness trouble vert0 = 64; vert1 = 32; t1 = 1.75; // minimum wallthickness r1 = bodem; // 38/2; // bodem ring // initial standoff t2 = 4; r2 = 20/2; // torodial reduction t3 = 8; r3= 14/2; // trapezoidal t4 = 0.75; t5 = 1.50; r5 = 17/2; t6 = 0.75; s6 = t1+t2+t3+t4+t5+t6; // tip t7 = 2.50; t8 = 3.00; t9 = 3.5; r7 = 16/2; r8 = 11.5/2; // critical //echo("rimthickness: ",r8-riB); r9 = r7; //echo("length=24? ",s6-t1 +t7+t8+t9); // not correct yet ############################# difference() { union() { cylinder(r=r1,h=t1,$fn=vert0); translate([0,0,t1]) { cylinder(r=r2,h=t2,$fn=vert0); translate([0,0,t2]) difference() { cylinder(r=r2,h=t3,$fn=vert0); translate([0,0,t3]) scale([1,1,t3/(r2-r3)]) rotate_extrude(convexity=3, $fn=vert0) translate([r2,0,0]) #circle(r=r2-r3,$fn=vert1); } } // trapezoidal part translate([0,0,t1+t2+t3]) rotate_extrude(convexity=3, $fn=vert0) polygon(points=[[0,0],[r3,0],[r5,t4],[r5,t4+t5],[r7,t4+t5+t6],[0,t4+t5+t6]],paths=[[0,1,2,3,4,5]]); //TIP translate([0,0,s6]) { cylinder(r = r7, h=t7+t8,$fn=vert0) ; translate([0,0,t7+t8+0.5]) torus(2.5,r7-2.5,vert1,vert0); // maybe add cylinder here ################### "t_8_1/2" } } // minus: // too low in z translate([0,0,s6+t7+t8/2]) torus(t8/2*sqrt(2), (r7+r8)/2 + (r7-r8)/2*sqrt(2),4,vert0); // test translate([0,0,s6+t7+t8/2]) torus(t8/2, r8+t8/2,vert1,vert0); // test cylinder(r=riB,h= (t1+24)*1.1,$fn=vert0); // to see 24 mm translate([0,0,-0.05]) //cylinder(r1=riA,r2=riB,h=10,$fn=vert0); //cylinder(r1=riA,r2=riB,h=10,$fn=vert0); // h=10 just looks good cylinder(r1=riA+1.0,r2=riB,h=12,$fn=vert0); // h=10 just looks good // DEBUGGING CUT // translate([30,0,0]) cube([60,60,60],center=true); } // translate([0,0,t1]) #cylinder(r=2,h=24,$fn=16); // to see 24 mm module torus(ra,rb,va,vb) { rotate_extrude(convexity=3, $fn=vb) translate([rb,0,0]) rotate(45,[0,0,1]) #circle(r=ra,$fn=va);//off=diaDoorvoer/2; } } module gradenBoog(dia=10,z=20) { for(x=[5:5:360]) { mv([getX(dia,x),getY(dia,x),z]) color("Green") text(str(x), size = 1); } } module klem(d=3,l=10,h=1,rot=45) { rotz(rot) hull() { color("Red") mvx(-l/2) cylinder(d=d,h=h); color("Red") mvx(l/2) cylinder(d=d,h=h); } } module lip(cirkel,graden,d=3,l=10,h=1) { mv(getXYZ(cirkel/2,graden,height-0.9)) klem(d=d,l=l,h=h,rot=90+graden); } // mv([5,5,5]) openBox(); //mv(10,10,10) openBox(); module mv(x=0, y=0, z=0) { p=is_list(x) ? x : [x,y,z]; translate(p) children(); } module mvx(x=0) translate([x,0,0]) children(); module mvy(y=0) translate([0,y,0]) children(); module mvz(z=0) translate([0,0,z]) children(); module rot(x=0, y=0, z=0) { p=is_list(x) ? x : [x,y,z]; rotate(p) children(); } module rotx(x=0) rotate([x,0,0]) children(); module roty(y=0) rotate([0,y,0]) children(); module rotz(z=0) rotate([0,0,z]) children(); function ellipse(r1, r2,van=0,naar=180) = [for (theta = [van : 1 : naar]) [r1 * cos(theta), r2 * sin(theta) ]]; function getTurns(type,height)=(height / (thread_specs(str(type,"-int")))[0]); function getX (d=10,graden=45)=cos(graden)*d; function getY (d=10,graden=45)=sin(graden)*d; function getXY(d=10,graden=45)=[getX(d=d,graden=graden),getY(d=d,graden=graden)]; function getXYZ(d=10,graden=45,z=1)=[getX(d=d,graden=graden),getY(d=d,graden=graden),z]; function mvXYZ(rot=0,mvs=0)=(rot == 0 ) ? [0,0,0] : (rot == 90) ? [0,-mvs,0] : (rot == 180) ? [-mvs,-mvs,0] : (rot==270) ? [-mvs,0,0] : [0,0,0]; module hoek_verbinding(h=20,b=5,tol=0.1,rot=360) { if(rot== 0) { _hoek();} if(rot==90) { mvx(b) _hoek();} if(rot==180) { mv([b,b,0]) _hoek();} if(rot==270) { mv([0,b,0]) _hoek();} module _hoek() { rotz(rot) difference() { cube([b,b,h]); mvx(b/3) color("Red") mvz(-0.05) cube([tol+b/3,tol+b*2/3,h+0.1]); mvx(b/3) color("Red") mvz(-0.05) cube([tol+b*2/3,tol+b/3,h+0.1]); } } } module femaleProfile(height=10,size=10,tol=0,sides=[1,1,1,1]) { w1=size; w2=w1/1.5; linear_extrude(height) offset(0.05) difference() { square(w1,center=true); _holes(sides); circle(2.2,$fn=16); } module _holes(sides) { if(sides[0] == 1) mvy(-w1/2) maleProfile(size,tol); if(sides[3] == 1) mvx(w1/2) rotz(90) maleProfile(size,tol); if(sides[2] == 1) mvy(w1/2) rotz(180) maleProfile(size,tol); if(sides[1] == 1) mvx(-w1/2) rotz(270) maleProfile(size,tol); } } module maleProfile(size=10,tol=0,half=0) { $fn=100; sze=size/1.5; t1=1.5-tol; // sze/14-tol; t2=2.5+tol; // sze/7+tol; t3=3+tol; // +tol; s1=1+tol; // sze/3/2+tol; s2=2.5+tol; //sze/3.5+tol; s3=1.5+tol; // sze/8+tol; if(half == 0) { mvy(0.55) offset(0.55) polygon(points=[[-s1,-0.5],[-s1,t1],[-s2,t1],[-s2,t2],[-s3,t3],[s3,t3],[s2,t2],[s2,t1],[s1,t1],[s1,-0.5]]); } else { mvy(0.55) offset(0.55) polygon(points= [[-s1,-0.5],[-s1,t3-1],[s3,t3-1],[s2,t2],[s2,t1],[s1,t1],[s1,-0.5]]); } } //femaleProfile(size=15); module helix( profile, radius=5, pitch=2, height=10, fn=($fn==0?36:$fn) ){ //echo(profile); echo(height); if(profile==undef||len(profile)<3) echo(str( "ERROR: profile is missing!" )); points=[ for(a=[0:360/fn:height/pitch*360])( for(p=[0:len(profile)-1])( let(x=0,y=x,z=1)[ (profile[p][x]+radius)*cos(a), (profile[p][y]+radius)*sin(a), profile[p][z]+a/360*pitch ] ) ) ]; n=len(profile); p=len(points); faces=[ [for(point=[0:1:n-1]) point ], for(point=[0:n:p-n-1])( for(side=[0:n-1])( let(offset1=point+side,offset2=n)[ offset1, offset1+offset2, (side==n-1? offset1+1 : offset1+offset2+1 ), (side==n-1? offset1-offset2+1 : offset1+1 ) ] ) ), [for(point=[p-1:-1:p-n]) point, ] ]; polyhedron(points,faces,10); } module femaleConnect(draad=0.3, radius=5,pitch=1.5,h=4) { p= [for ( angle = [0 :10: 360]) [draad*sin(angle), draad*cos(angle)] ]; translate([0,0,-draad]) helix(profile=p,radius=radius,pitch=pitch,height=h+2*draad); cylinder(h=h,r=radius); } module maleConnect(draad=0.3, radius=5,pitch=1.5,h=4,offset=2) { o=offset; for(angle=[90:90:360]) translate([(radius)*sin(angle), (radius)*cos(angle),o-angle*(pitch/360)]) sphere(draad); // echo(h); cylinder(h=h,r=radius); } module maleConnectWired(draad=0.3, radius=5,pitch=1.5,height=4) { p= [for ( angle = [0 :10: 360]) [draad*sin(angle), draad*cos(angle)] ]; translate([0,0,draad]) helix(profile=p,radius=radius,pitch=pitch,height-2*draad); cylinder(h=height,r=radius); } module baseSupport(top=5,bottom=10,height=8) { polygon(points=[[0,0], [bottom,0], [top,height], [-top,height], [-bottom,0],[0,0] ]); } module wall2D(thickness) { if(thickness>0) { difference() { offset(thickness) children(0); children(0); } } else { children(0); } } module elbowinator(angle, bendRadius, clipBounds=100, convexity=4) intersection() { rotate_extrude(convexity=convexity) translate([bendRadius,0,0]) children(0); linear_extrude(height=clipBounds, slices=2, center=true) wedge2D(angle, clipBounds); } module wedge2D(angle, r, nSides=3) polygon(points=concat([[0,0]], [for(i=[0:nSides]) r*[cos(i/nSides*angle), sin(i/nSides*angle)]]), convexity=4); module bend2D(angle=90,bendRadius=33,thickness=3,$fn=128) { elbowinator(angle=angle, bendRadius=bendRadius) wall2D(thickness=thickness) children(); } //bend2D(angle=300,bendRadius=30) circle(3); //translate([0,0,- 20])bend(bendRadius=50) circle(3); //translate([0,0,20]) bend(thickness=0,$fn=128) square(8);