Advertisement
Guest User

Untitled

a guest
May 9th, 2017
5,601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var revision = 'V1.1'
  2. var base_width = 50;
  3. var base_depth = 50;
  4. function getParameterDefinitions(){
  5.   return[{name: 'printer_name', type: 'text', initial: 'Example', caption: 'Printer Name'},
  6. {name: 'print_identification', type: 'text', initial: 'Example', caption: 'Print Identificaiton'}];
  7. }
  8. function text(txt, size, hgt){
  9.   var l = vector_text(0,0,txt);
  10.   var o = [];
  11.   l.forEach(function(pl){
  12.     o.push(rectangular_extrude(pl, {w:2, h: hgt}).scale(size*0.08));
  13.   });
  14.   return union(o);
  15. }
  16. function base(){
  17.     return difference(
  18.        cube({size: [base_width, base_depth,10]}).translate([0,0,-10]),
  19.        cube({size: [base_width, 5, 5]}).translate([0,(base_depth-5)/2,-10]),
  20.        cube({size: [5, base_depth, 5]}).translate([(base_depth-5)/2,0,-10])
  21.     );
  22. }
  23. function bridge(dist){
  24.     return union(
  25.         cube({size: [1,4,4]}),
  26.         cube({size: [1,4,4]}).translate([1+dist, 0, 0]),
  27.         cube({size: [2+dist, 4, 1]}).translate([0,0,4]),
  28.         text(dist.toString(), 1, 20).translate([dist/2, 1, 4])
  29.     );
  30. }
  31. function bridges(){
  32.     return union(
  33.         bridge(3).translate([1,0,0]),
  34.         bridge(4).translate([5,0,0]),
  35.         bridge(5).translate([10,0,0]),
  36.         bridge(6).translate([16,0,0])
  37.     );
  38. }
  39. function wall(width){
  40.   return cube({size: [10, width,5]});
  41. }
  42. function walls(){
  43.   return union(
  44.     wall(0.2),
  45.     wall(0.3).translate([0,2,0]),
  46.     wall(0.4).translate([0,4,0]),
  47.     wall(0.5).translate([0,6,0]),
  48.     wall(0.6).translate([0,8,0])
  49.   );
  50. }
  51. function slots(){
  52.   return union(
  53.     wall(0.5),
  54.     wall(0.6).translate([0,2,0]),
  55.     wall(0.7).translate([0,4,0]),
  56.     wall(0.8).translate([0,6,0]),
  57.     wall(0.9).translate([0,8,0])
  58.   );
  59. }
  60. function wires(){
  61.   return union(
  62.     cylinder({d: 0.4, h: 5}).translate([0,0.025,0]),
  63.     cylinder({d: 0.5, h: 5}).translate([0,2.05,0]),
  64.     cylinder({d: 0.6, h: 5}).translate([0,4.1,0]),
  65.     cylinder({d: 0.7, h: 5}).translate([0,6.15,0]),
  66.     cylinder({d: 0.8, h: 5}).translate([0,8.2,0])
  67.   );
  68. }
  69. function holes(){
  70.   return union(
  71.     cylinder({d: 0.8, h: 5}).translate([0,0.025,0]),
  72.     cylinder({d: 1.0, h: 5}).translate([0,2.05,0]),
  73.     cylinder({d: 1.2, h: 5}).translate([0,4.1,0]),
  74.     cylinder({d: 1.4, h: 5}).translate([0,6.15,0]),
  75.     cylinder({d: 1.6, h: 5}).translate([0,8.2,0])
  76.   );
  77. }
  78. function octagon(){
  79.   return cylinder({h: 5, d: 4/(Math.sin(67.5*(Math.PI / 180))), fn: 8})
  80. }
  81. function m4(){
  82.   return cylinder({h: 3.2, d: 7.66, fn: 6});
  83. }
  84. function gear(res,x){
  85.   var res_txt = parseInt(res*1000);
  86.   return union(
  87.     cylinder({d: 6, h: 2, fn:8}),
  88.     cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]),
  89.     cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(45),
  90.     cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(90),
  91.     cube({size: [7.5, res, 2]}).translate([-3.75,-res/2,0]).rotateZ(135),
  92.     text(res_txt.toString(), 1, 1).rotateZ(180).translate([x,0.8,2])
  93.   );
  94. }
  95. function overhangs(angle){
  96.   return union(
  97.     cube({size: [5,2.5,7.5]}).rotateX(-angle),
  98.     cube({size: [5,2.5,7.5]})
  99.       .rotateX(-angle-15)
  100.       .translate([0,sin(angle)*7.5,cos(angle)*7.5]),
  101.     cube({size: [5,2.5,7.5]})
  102.       .rotateX(-angle-2*15)
  103.       .translate([0,sin(angle)*7.5+sin(angle+15)*7.5,cos(angle)*7.5+cos(angle+15)*7.5])
  104.   );
  105. }
  106. function overhangs_2(angle){
  107.   return union(
  108.     cube({size: [5,2.5,7.5]}).rotateX(-angle),
  109.     cube({size: [5,2.5,7.5]})
  110.       .rotateX(-angle-15)
  111.       .translate([0, sin(angle)*7.5, cos(angle)*7.5])
  112.   );
  113. }
  114. function butterfly_pos(){
  115.   return union(
  116.     linear_extrude({height: 1},polygon({points: [[1.75,0.75],[0.75,1.25],[5.5,3]]})),
  117.     linear_extrude({height: 0.5},polygon({points: [[0.75,1.25],[3.5,5.5],[5.5,3]]})),
  118.     linear_extrude({height: 0.25},polygon({points: [[2,5.5],[4,7],[5.5,3]]}))
  119.   );
  120. }
  121. function butterfly_neg(){
  122.   return union(
  123.     linear_extrude({height: 1},polygon({points: [[11-1.75,0.75],[11-0.75,1.25],[5.5,3]]})).translate([0,0,-1]),
  124.     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]),
  125.     linear_extrude({height: 0.25},polygon({points: [[11-2,5.5],[11-4,7],[5.5,3]]})).translate([0,0,-0.25])
  126.   );
  127. }
  128. function negative_features(printer_name, print_identification){
  129.   return base()
  130.     .subtract(butterfly_neg().translate([base_width/2-5.5,base_depth/2-3,0]))
  131.     .subtract(slots().translate([32,15,-4]))
  132.     .subtract(slots().rotateZ(90).translate([42,25,-4]))
  133.     .subtract(holes().translate([48,26,-4]))
  134.     .subtract(fairbury_hex_bolt(4,4).rotateX(180).translate([38,45,3.5]))
  135.     .union(text(revision, 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-9,0]))
  136.     .union(text(printer_name, 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-5,0]))
  137.     .union(text(print_identification.toString(), 1.5, 2).rotateZ(180).translate([base_width/2+10, base_depth-1,0]))
  138. }
  139. function positive_features(){
  140.   return union(
  141.     butterfly_pos().translate([base_width/2-5.5,base_depth/2-3,0]),
  142.     octagon().translate([base_width/2,33,0]),
  143.     bridges().translate([base_width/2-15,0,0]),
  144.     bridges().rotateZ(90).translate([4,base_width/2-15,0]),
  145.     overhangs(15).rotateZ(270).translate([0,base_depth-5.4,0]),
  146.     overhangs_2(60).rotateZ(270).translate([0,base_depth,0]),
  147.     overhangs(15).translate([base_depth-10.2,0,0]),
  148.     overhangs_2(60).translate([base_depth-5,0,0]),
  149.     walls().translate([8,15,0]),
  150.     walls().rotateZ(90).translate([16,25,0]),
  151.     gear(0.05,1.55).translate([36,10,0]),
  152.     gear(0.1,2.4).translate([28,10,0]),
  153.     gear(0.15,2.4).translate([20,10,0]),
  154.     gear(0.2,2.4).translate([12,10,0]),
  155.     wires().translate([45,26,0]),
  156.     cube({size: [10,10,3]}).translate([base_width-9, base_depth - 9,]),
  157.     fairbury_hex_bolt(4,4).translate([base_width-4,base_depth-4,1]),
  158.     difference(
  159.       cube({size: [10,10,3]}).translate([-1,-2,0]),
  160.       m4().translate([4,3,1])
  161.       //text("M4", 10).rotateZ(180).translate([6,4,-5])
  162.     )
  163.   )
  164. }
  165. function main(params) {
  166.     var w = [negative_features(params.printer_name, params.print_identification), positive_features()];
  167.     return w;
  168. }
  169. function fairbury_hex_bolt(dia, hi){
  170.   var returnArray = [];
  171.   var hhi = fairbury_hex_bolt_hi(dia);
  172.   returnArray.push(cylinder({r: fairbury_hex_bolt_dia(dia)/2, h: hhi, fn: 6}));
  173.   returnArray.push(thread_out(dia,hi+0.1).translate([0,0,hhi-0.1]));
  174.   returnArray.push(thread_out_centre(dia,hi+0.1).translate([0,0,hhi-0.1]));
  175.   return union(returnArray);
  176. }
  177. function fairbury_hex_bolt_hi(dia){
  178.   var lookup_value = [3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36];
  179.   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];
  180.   return return_value[lookup_value.indexOf(dia)];
  181. }
  182. function fairbury_hex_bolt_dia(dia){
  183.   var lookup_value = [3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 30, 36];
  184.   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];
  185.   return return_value[lookup_value.indexOf(dia)];
  186. }
  187. function thread_out(dia, hi, thr=30){
  188.   var p = get_coarse_pitch(dia);
  189.   return thread_out_pitch(dia, hi, p, thr);
  190. }
  191. function thread_out_pitch(dia, hi, p, thr=30){
  192.   var h = (Math.cos(30*(Math.PI / 180))*p)/8;
  193.   var Rmin = (dia/2)-(5*h);
  194.   var s = 360/thr;
  195.   var t1 = (hi-p)/p;
  196.   var r = t1%1.0;
  197.   var t = t1-r;
  198.   var n=r/(p/thr);
  199.   var returnArray = [];
  200.   for(var tn=0; tn < t; tn++){
  201.       returnArray.push(th_out_turn(dia, p, thr).translate([0, 0, tn*p]));
  202.   }
  203.   for(var sg=0; sg < n+1; sg++){
  204.       returnArray.push(th_out_pt(Rmin, p, s, sg+(t*thr),thr,h,p/thr));
  205.   }
  206.   return union(returnArray);
  207. }
  208. function th_out_turn(dia, p, thr=30){
  209.   var h = (Math.cos(30*(Math.PI / 180))*p)/8;
  210.     var Rmin = (dia/2) - (5*h); // as wiki Dmin
  211.     var s = 360/thr;
  212.   var returnArray = [];
  213.   for(var sg = 0; sg < thr; sg++){
  214.     returnArray.push(th_out_pt(Rmin,p,s,sg,thr,h,p/thr));
  215.   }
  216.   return union(returnArray);
  217. }
  218. function th_out_pt(rt, p, s, sg, thr, h, sh){
  219.     var as = (sg % thr) * s;            // angle to start of seg
  220.     var ae = as + s;        // angle to end of seg (with overlap)
  221.     var z = sh*sg;
  222.     return polyhedron({
  223.         points: [
  224.             [Math.cos(as*(Math.PI / 180))*rt,Math.sin(as*(Math.PI / 180))*rt,z],                                // 0
  225.             [Math.cos(as*(Math.PI / 180))*rt,Math.sin(as*(Math.PI / 180))*rt,z+(3/4*p)],                        // 1
  226.             [Math.cos(as*(Math.PI / 180))*(rt+(5*h)),Math.sin(as*(Math.PI / 180))*(rt+(5*h)),z+(3/8*p)],        // 2
  227.             [Math.cos(ae*(Math.PI / 180))*rt,Math.sin(ae*(Math.PI / 180))*rt,z+sh],                         // 3
  228.             [Math.cos(ae*(Math.PI / 180))*rt,Math.sin(ae*(Math.PI / 180))*rt,z+(3/4*p)+sh],                 // 4
  229.             [Math.cos(ae*(Math.PI / 180))*(rt+(5*h)),Math.sin(ae*(Math.PI / 180))*(rt+(5*h)),z+sh+(3/8*p)]],    // 5
  230.         triangles: [
  231.             [0,1,2],            // near face
  232.             [3,5,4],            // far face
  233.             [0,3,4],[0,4,1],    // left face
  234.             [0,5,3],[0,2,5],    // bottom face
  235.             [1,4,5],[1,5,2]]  // top face
  236.     }
  237.   );
  238. }
  239. function thread_out_centre(dia, hi){
  240.   var p = get_coarse_pitch(dia);
  241.   return thread_out_centre_pitch(dia, hi, p);
  242. }
  243. function thread_out_centre_pitch(dia, hi, p){
  244.   var h_min = (Math.cos(30*(Math.PI / 180))*p)/8;
  245.     var Rmin = (dia/2) - (5*h_min); // as wiki Dmin
  246.   return cylinder({r: Rmin, h: hi, fn:30});
  247. }
  248. function get_coarse_pitch(dia){
  249.   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,
  250.     14, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 42, 45, 48, 52, 56, 60, 64, 78];
  251.   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,
  252.     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,
  253.     5, 5, 5.5, 5.5, 6, 5];
  254.   return output_me[find_me.indexOf(dia)];
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement