Grow Y axis corners up when needed
[clinton/prusa3.git] / box_frame / inc / functions.scad
CommitLineData
2159eed1 1// PRUSA iteration3
d3618a65
NZ
2// Functions used in many files
3// GNU GPL v3
2159eed1
VAH
4// Josef Průša <josefprusa@me.com>
5// Václav 'ax' Hůla <axtheb@gmail.com>
4d2a954d 6// Vlnofka <>
d3618a65
NZ
7// http://www.reprap.org/wiki/Prusa_Mendel
8// http://github.com/prusajr/PrusaMendel
9
10
11module nut(d,h,horizontal=true){
c94c2662
VAH
12 cornerdiameter = (d / 2) / cos (180 / 6);
13 cylinder(h = h, r = cornerdiameter, $fn = 6);
14 if(horizontal){
15 for(i = [1:6]){
51fd106d 16 rotate([0,0,60*i]) translate([-cornerdiameter-0.2,0,0]) rotate([0,0,-45]) cube([2,2,h]);
c94c2662
VAH
17 }
18 }
d3618a65
NZ
19}
20
21// Based on nophead research
c94c2662 22module polyhole(d, h, center=false) {
d3618a65
NZ
23 n = max(round(2 * d),3);
24 rotate([0,0,180])
25 cylinder(h = h, r = (d / 2) / cos (180 / n), $fn = n);
26}
27
c94c2662
VAH
28// make it interchangeable between this and cylinder
29module cylinder_poly(r, h, center=false){
30 polyhole(d=r*2, h=h, center=center);
31}
32
1280d035 33module fillet(radius, height=100, $fn=0) {
c94c2662
VAH
34 //this creates acutal fillet
35 translate([-radius, -radius, -height/2-0.01])
36 difference() {
37 cube([radius*2, radius*2, height+0.02]);
1280d035 38 cylinder(r=radius, h=height+0.02, $fn=$fn);
c94c2662
VAH
39 }
40}
41
c94c2662
VAH
42module cube_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], center=false, $fn=0){
43 //
c6265fc0
VAH
44 if (use_fillets) {
45 if (center) {
c94c2662 46 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
c6265fc0
VAH
47 } else {
48 translate([size[0]/2, size[1]/2, size[2]/2])
49 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
50 }
51 } else {
52 cube(size, center);
c94c2662 53 }
c6265fc0 54
c94c2662
VAH
55}
56
57module cube_negative_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
58
59 j=[1,0,1,0];
d3618a65 60
c94c2662
VAH
61 for (i=[0:3]) {
62 if (radius > -1) {
63 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(radius, size[2], $fn=$fn);
64 } else {
65 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(vertical[i], size[2], $fn=$fn);
66 }
67 rotate([90*i, -90, 0]) translate([size[2]/2, size[j[i]]/2, 0 ]) fillet(top[i], size[1-j[i]], $fn=$fn);
68 rotate([90*(4-i), 90, 0]) translate([size[2]/2, size[j[i]]/2, 0]) fillet(bottom[i], size[1-j[i]], $fn=$fn);
69
70 }
71}
d3618a65 72
c94c2662
VAH
73module cube_fillet_inside(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
74 //makes CENTERED cube with round corners
75 // if you give it radius, it will fillet vertical corners.
76 //othervise use vertical, top, bottom arrays
77 //when viewed from top, it starts in upper right corner (+x,+y quadrant) , goes counterclockwise
1280d035 78 //top/bottom fillet starts in direction of Y axis and goes CCW too
c94c2662
VAH
79
80
81 if (radius == 0) {
82 cube(size, center=true);
83 } else {
84 difference() {
85 cube(size, center=true);
86 cube_negative_fillet(size, radius, vertical, top, bottom, $fn);
87 }
88 }
89}
90
91
0b2e9c87 92module nema17(places=[1,1,1,1], size=15.5, h=10, holes=false, shadow=false, $fn=24){
c94c2662 93 for (i=[0:3]) {
4bdd854d 94 if (places[i] == 1) {
c94c2662
VAH
95 rotate([0, 0, 90*i]) translate([size, size, 0]) {
96 if (holes) {
380e3cfb 97 rotate([0, 0, -90*i]) translate([0,0,-10]) screw(r=1.7, slant=false, head_drop=13, $fn=$fn, h=h+12);
c94c2662
VAH
98 } else {
99 rotate([0, 0, -90*i]) cylinder(h=h, r=5.5, $fn=$fn);
100 }
101 }
102 }
103 }
86222e6a 104 if (shadow != false) {
51fd106d 105 %translate ([0, 0, shadow+21+3]) cube([42,42,42], center = true);
1280d035 106 //flange
28c8b084 107 %translate ([0, 0, shadow+21+3-21-1]) cylinder(r=11,h=2, center = true, $fn=20);
1280d035 108 //shaft
28c8b084 109 %translate ([0, 0, shadow+21+3-21-7]) cylinder(r=2.5,h=14, center = true);
c94c2662
VAH
110 }
111}
112
fdc7f8d6 113module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=i_am_box, poly=false, $fn=0){
c94c2662
VAH
114 //makes screw with head
115 //for substraction as screw hole
116 if (poly) {
117 cylinder_poly(h=h, r=r, $fn=$fn);
118 } else {
119 cylinder(h=h, r=r, $fn=$fn);
120 }
121 if (slant) {
122 translate([0, 0, head_drop-0.01]) cylinder(h=r_head, r2=0, r1=r_head, $fn=$fn);
123 }
124
125 if (head_drop > 0) {
126 translate([0, 0, -0.01]) cylinder(h=head_drop+0.01, r=r_head, $fn=$fn);
127 }
128}
d3618a65 129
c94c2662
VAH
130//cube_fillet([10,20,30], vertical=[3,2,0,0], top=[3,2,0,5], bottom=[3,2,0,5]);
131//cube_fillet([10,20,30], radius=2, top=[7,2,7,2]);