Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var revision = 'V1.1'
- var base_width = 50;
- var base_depth = 50;
- function getParameterDefinitions(){
- return[{name: 'printer_name', type: 'text', initial: 'Example', caption: 'Printer Name'},
- {name: 'print_identification', type: 'text', initial: 'Example', caption: 'Print Identificaiton'}];
- }
- function text(txt, size, hgt){
- var l = vector_text(0,0,txt);
- var o = [];
- l.forEach(function(pl){
- o.push(rectangular_extrude(pl, {w:2, h: hgt}).scale(size*0.08));
- });
- return union(o);
- }
- function base(){
- return difference(
- cube({size: [base_width, base_depth,10]}).translate([0,0,-10]),
- cube({size: [base_width, 5, 5]}).translate([0,(base_depth-5)/2,-10]),
- cube({size: [5, base_depth, 5]}).translate([(base_depth-5)/2,0,-10])
- );
- }
- function bridge(dist){
- return union(
- cube({size: [1,4,4]}),
- cube({size: [1,4,4]}).translate([1+dist, 0, 0]),
- cube({size: [2+dist, 4, 1]}).translate([0,0,4]),
- text(dist.toString(), 1, 20).translate([dist/2, 1, 4])
- );
- }
- function bridges(){
- return union(
- bridge(3).translate([1,0,0]),
- bridge(4).translate([5,0,0]),
- bridge(5).translate([10,0,0]),
- bridge(6).translate([16,0,0])
- );
- }
- function wall(width){
- return cube({size: [10, width,5]});
- }
- function walls(){
- return union(
- wall(0.2),
- wall(0.3).translate([0,2,0]),
- wall(0.4).translate([0,4,0]),
- wall(0.5).translate([0,6,0]),
- wall(0.6).translate([0,8,0])
- );
- }
- function slots(){
- return union(
- wall(0.5),
- wall(0.6).translate([0,2,0]),
- wall(0.7).translate([0,4,0]),
- wall(0.8).translate([0,6,0]),
- wall(0.9).translate([0,8,0])
- );
- }
- function wires(){
- return union(
- cylinder({d: 0.4, h: 5}).translate([0,0.025,0]),
- cylinder({d: 0.5, h: 5}).translate([0,2.05,0]),
- cylinder({d: 0.6, h: 5}).translate([0,4.1,0]),
- cylinder({d: 0.7, h: 5}).translate([0,6.15,0]),
- cylinder({d: 0.8, h: 5}).translate([0,8.2,0])
- );
- }
- function holes(){
- return union(
- cylinder({d: 0.8, h: 5}).translate([0,0.025,0]),
- cylinder({d: 1.0, h: 5}).translate([0,2.05,0]),
- cylinder({d: 1.2, h: 5}).translate([0,4.1,0]),
- cylinder({d: 1.4, h: 5}).translate([0,6.15,0]),
- cylinder({d: 1.6, h: 5}).translate([0,8.2,0])
- );
- }
- function octagon(){
- return cylinder({h: 5, d: 4/(Math.sin(67.5*(Math.PI / 180))), fn: 8})
- }
- function m4(){
- return cylinder({h: 3.2, d: 7.66, fn: 6});
- }
- function gear(res,x){
- var res_txt = parseInt(res*1000);
- return union(
- cylinder({d: 6, h: 2, fn:8}),
- cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]),
- cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(45),
- cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(90),
- cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(135),
- text(res_txt.toString(), 1, 1).rotateZ(180).translate([x,0.8,2])
- );
- }
- function overhangs(angle){
- return union(
- cube({size: [5,2.5,7.5]}).rotateX(-angle),
- cube({size: [5,2.5,7.5]})
- .rotateX(-angle-15)
- .translate([0,sin(angle)*7.5,cos(angle)*7.5]),
- cube({size: [5,2.5,7.5]})
- .rotateX(-angle-2*15)
- .translate([0,sin(angle)*7.5+sin(angle+15)*7.5,cos(angle)*7.5+cos(angle+15)*7.5])
- );
- }
- function overhangs_2(angle){
- return union(
- cube({size: [5,2.5,7.5]}).rotateX(-angle),
- cube({size: [5,2.5,7.5]})
- .rotateX(-angle-15)
- .translate([0, sin(angle)*7.5, cos(angle)*7.5])
- );
- }
- function butterfly_pos(){
- return union(
- linear_extrude({height: 1},polygon({points: [[1.75,0.75],[0.75,1.25],[5.5,3]]})),
- linear_extrude({height: 0.5},polygon({points: [[0.75,1.25],[3.5,5.5],[5.5,3]]})),
- linear_extrude({height: 0.25},polygon({points: [[2,5.5],[4,7],[5.5,3]]}))
- );
- }
- function butterfly_neg(){
- return union(
- linear_extrude({height: 1},polygon({points: [[11-1.75,0.75],[11-0.75,1.25],[5.5,3]]})).translate([0,0,-1]),
- linear_extrude({height: 0.5},polygon({points: [[11-0.75,1.25],[11-3.5,5.5],[5.5,3]]})).translate([0,0,-0.5]),
- linear_extrude({height: 0.25},polygon({points: [[11-2,5.5],[11-4,7],[5.5,3]]})).translate([0,0,-0.25])
- );
- }
- function negative_features(printer_name, print_identification){
- return base()
- .subtract(butterfly_neg().translate([base_width/2-5.5,base_depth/2-3,0]))
- .subtract(slots().translate([32,15,-4]))
- .subtract(slots().rotateZ(90).translate([42,25,-4]))
- .subtract(holes().translate([48,26,-4]))
- .subtract(fairbury_hex_bolt(4,4).rotateX(180).translate([38,45,3.5]))
- .union(text(revision, 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-9,0]))
- .union(text(printer_name, 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-5,0]))
- .union(text(print_identification.toString(), 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-1,0]))
- }
- function positive_features(){
- return union(
- butterfly_pos().translate([base_width/2-5.5,base_depth/2-3,0]),
- octagon().translate([base_width/2,33,0]),
- bridges().translate([base_width/2-15,0,0]),
- bridges().rotateZ(90).translate([4,base_width/2-15,0]),
- overhangs(15).rotateZ(270).translate([0,base_depth-5.4,0]),
- overhangs_2(60).rotateZ(270).translate([0,base_depth,0]),
- overhangs(15).translate([base_depth-10.2,0,0]),
- overhangs_2(60).translate([base_depth-5,0,0]),
- walls().translate([8,15,0]),
- walls().rotateZ(90).translate([16,25,0]),
- gear(0.05,1.55).translate([36,10,0]),
- gear(0.1,2.4).translate([28,10,0]),
- gear(0.15,2.4).translate([20,10,0]),
- gear(0.2,2.4).translate([12,10,0]),
- wires().translate([45,26,0]),
- cube({size: [10,10,3]}).translate([base_width-9, base_depth - 9,]),
- fairbury_hex_bolt(4,4).translate([base_width-4,base_depth-4,1]),
- difference(
- cube({size: [10,10,3]}).translate([-1,-2,0]),
- m4().translate([4,3,1])
- //text("M4", 10).rotateZ(180).translate([6,4,-5])
- )
- )
- }
- function main(params) {
- var w = [negative_features(params.printer_name, params.print_identification), positive_features()];
- return w;
- }
- function fairbury_hex_bolt(dia, hi){
- var returnArray = [];
- var hhi = fairbury_hex_bolt_hi(dia);
- returnArray.push(cylinder({r: fairbury_hex_bolt_dia(dia)/2, h: hhi, fn: 6}));
- returnArray.push(thread_out(dia,hi+0.1).translate([0,0,hhi-0.1]));
- returnArray.push(thread_out_centre(dia,hi+0.1).translate([0,0,hhi-0.1]));
- return union(returnArray);
- }
- function fairbury_hex_bolt_hi(dia){
- var lookup_value = [3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36];
- var return_value = [2.4, 3.2, 3.4, 3.9, 5.1, 6.2, 7.3, 9.7, 12.2, 14.6, 17.9, 21.7];
- return return_value[lookup_value.indexOf(dia)];
- }
- function fairbury_hex_bolt_dia(dia){
- var lookup_value = [3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36];
- var return_value = [6.4, 8.1, 8.8, 11.1, 14.4, 17.8, 20.1, 26.9, 33, 39.6, 50.9, 60.8];
- return return_value[lookup_value.indexOf(dia)];
- }
- function thread_out(dia, hi, thr=30){
- var p = get_coarse_pitch(dia);
- return thread_out_pitch(dia, hi, p, thr);
- }
- function thread_out_pitch(dia, hi, p, thr=30){
- var h = (Math.cos(30*(Math.PI / 180))*p)/8;
- var Rmin = (dia/2)-(5*h);
- var s = 360/thr;
- var t1 = (hi-p)/p;
- var r = t1%1.0;
- var t = t1-r;
- var n=r/(p/thr);
- var returnArray = [];
- for(var tn=0; tn < t; tn++){
- returnArray.push(th_out_turn(dia, p, thr).translate([0, 0, tn*p]));
- }
- for(var sg=0; sg < n+1; sg++){
- returnArray.push(th_out_pt(Rmin, p, s, sg+(t*thr),thr,h,p/thr));
- }
- return union(returnArray);
- }
- function th_out_turn(dia, p, thr=30){
- var h = (Math.cos(30*(Math.PI / 180))*p)/8;
- var Rmin = (dia/2) - (5*h); // as wiki Dmin
- var s = 360/thr;
- var returnArray = [];
- for(var sg = 0; sg < thr; sg++){
- returnArray.push(th_out_pt(Rmin,p,s,sg,thr,h,p/thr));
- }
- return union(returnArray);
- }
- function th_out_pt(rt, p, s, sg, thr, h, sh){
- var as = (sg % thr) * s; // angle to start of seg
- var ae = as + s; // angle to end of seg (with overlap)
- var z = sh*sg;
- return polyhedron({
- points: [
- [Math.cos(as*(Math.PI / 180))*rt,Math.sin(as*(Math.PI / 180))*rt,z], // 0
- [Math.cos(as*(Math.PI / 180))*rt,Math.sin(as*(Math.PI / 180))*rt,z+(3/4*p)], // 1
- [Math.cos(as*(Math.PI / 180))*(rt+(5*h)),Math.sin(as*(Math.PI / 180))*(rt+(5*h)),z+(3/8*p)], // 2
- [Math.cos(ae*(Math.PI / 180))*rt,Math.sin(ae*(Math.PI / 180))*rt,z+sh], // 3
- [Math.cos(ae*(Math.PI / 180))*rt,Math.sin(ae*(Math.PI / 180))*rt,z+(3/4*p)+sh], // 4
- [Math.cos(ae*(Math.PI / 180))*(rt+(5*h)),Math.sin(ae*(Math.PI / 180))*(rt+(5*h)),z+sh+(3/8*p)]], // 5
- triangles: [
- [0,1,2], // near face
- [3,5,4], // far face
- [0,3,4],[0,4,1], // left face
- [0,5,3],[0,2,5], // bottom face
- [1,4,5],[1,5,2]] // top face
- }
- );
- }
- function thread_out_centre(dia, hi){
- var p = get_coarse_pitch(dia);
- return thread_out_centre_pitch(dia, hi, p);
- }
- function thread_out_centre_pitch(dia, hi, p){
- var h_min = (Math.cos(30*(Math.PI / 180))*p)/8;
- var Rmin = (dia/2) - (5*h_min); // as wiki Dmin
- return cylinder({r: Rmin, h: hi, fn:30});
- }
- function get_coarse_pitch(dia){
- var find_me = [1, 1.2, 1.4, 1.6, 1.8, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 10, 12,
- 14, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 42, 45, 48, 52, 56, 60, 64, 78];
- var output_me = [0.25, 0.25, 0.3, 0.35, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8,
- 1, 1, 1.25, 1.5, 1.75, 2, 2, 2.5, 2.5, 2.5, 3, 3, 3.5, 3.5, 4, 4, 4.5, 4.5,
- 5, 5, 5.5, 5.5, 6, 5];
- return output_me[find_me.indexOf(dia)];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement