Y motor holder has proper shadow stepper now
[clinton/prusa3.git] / inc / functions.scad
1 // PRUSA Mendel
2 // Functions used in many files
3 // GNU GPL v3
4 // Josef Průša
5 // josefprusa@me.com
6 // prusadjs.cz
7 // http://www.reprap.org/wiki/Prusa_Mendel
8 // http://github.com/prusajr/PrusaMendel
9
10
11 module nut(d,h,horizontal=true){
12 cornerdiameter = (d / 2) / cos (180 / 6);
13 cylinder(h = h, r = cornerdiameter, $fn = 6);
14 if(horizontal){
15 for(i = [1:6]){
16 rotate([0,0,60*i]) translate([-cornerdiameter-0.2,0,0]) rotate([0,0,-45]) cube(size = [2,2,h]);
17 }
18 }
19 }
20
21 // Based on nophead research
22 module polyhole(d, h, center=false) {
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
28 // make it interchangeable between this and cylinder
29 module cylinder_poly(r, h, center=false){
30 polyhole(d=r*2, h=h, center=center);
31 }
32
33 module fillet(radius, height=100, $fn=16) {
34 //this creates acutal fillet
35 translate([-radius, -radius, -height/2-0.01])
36 difference() {
37 cube([radius*2, radius*2, height+0.02]);
38 cylinder(r=radius, h=height+0.02, $fn=16);
39 }
40 }
41
42
43 module cube_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], center=false, $fn=0){
44 //
45 if (center) {
46 cube_fillet_inside(size, radius, vertical, top, bottom, $fn);
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 }
52
53 module cube_negative_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
54
55 j=[1,0,1,0];
56
57 for (i=[0:3]) {
58 if (radius > -1) {
59 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(radius, size[2], $fn=$fn);
60 } else {
61 rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(vertical[i], size[2], $fn=$fn);
62 }
63 rotate([90*i, -90, 0]) translate([size[2]/2, size[j[i]]/2, 0 ]) fillet(top[i], size[1-j[i]], $fn=$fn);
64 rotate([90*(4-i), 90, 0]) translate([size[2]/2, size[j[i]]/2, 0]) fillet(bottom[i], size[1-j[i]], $fn=$fn);
65
66 }
67 }
68
69 module cube_fillet_inside(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){
70 //makes CENTERED cube with round corners
71 // if you give it radius, it will fillet vertical corners.
72 //othervise use vertical, top, bottom arrays
73 //when viewed from top, it starts in upper right corner (+x,+y quadrant) , goes counterclockwise
74 //top/bottom fillet starts in dorection of Y axis and goes CCW too
75
76
77 if (radius == 0) {
78 cube(size, center=true);
79 } else {
80 difference() {
81 cube(size, center=true);
82 cube_negative_fillet(size, radius, vertical, top, bottom, $fn);
83 }
84 }
85 }
86
87
88 module nema17(places=[1,1,1,1], size=15.5, h=10, holes=false, shadow=false, $fn=0){
89 for (i=[0:3]) {
90 if (places[i] == 1) {
91 rotate([0, 0, 90*i]) translate([size, size, 0]) {
92 if (holes) {
93 rotate([0, 0, -90*i]) screw(r=1.7, slant=false, head_drop=3, $fn=$fn, h=h+2);
94 } else {
95 rotate([0, 0, -90*i]) cylinder(h=h, r=5.5, $fn=$fn);
96 }
97 }
98 }
99 }
100 if (shadow != false) {
101 %translate ([0, 0, shadow+21+3]) cube(size = [42,42,42], center = true);
102 }
103 }
104
105 module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=true, poly=false, $fn=0){
106 //makes screw with head
107 //for substraction as screw hole
108 if (poly) {
109 cylinder_poly(h=h, r=r, $fn=$fn);
110 } else {
111 cylinder(h=h, r=r, $fn=$fn);
112 }
113 if (slant) {
114 translate([0, 0, head_drop-0.01]) cylinder(h=r_head, r2=0, r1=r_head, $fn=$fn);
115 }
116
117 if (head_drop > 0) {
118 translate([0, 0, -0.01]) cylinder(h=head_drop+0.01, r=r_head, $fn=$fn);
119 }
120 }
121
122 //cube_fillet([10,20,30], vertical=[3,2,0,0], top=[3,2,0,5], bottom=[3,2,0,5]);
123 //cube_fillet([10,20,30], radius=2, top=[7,2,7,2]);