Commit | Line | Data |
---|---|---|
1873788a MR |
1 | // functions.scad |
2 | // all by Prusa | |
3 | ||
4 | module belt(len, side = 0){ | |
5 | //belt. To be substracted from model | |
6 | //len is in +Z, smooth side in +X, Y centered | |
7 | translate([-0.5, 0, 0]) maketeeth(len); | |
8 | translate([0, -4.5, -0.01]) cube([belt_thickness, 9, len + 0.02]); | |
9 | if (side != 0) { | |
10 | translate([0, -4.5 + side, -0.01]) cube_fillet([belt_thickness, 9, len + 0.02], vertical = [3, 0, 0, 0]); | |
11 | } | |
12 | } | |
13 | ||
14 | module maketeeth(len){ | |
15 | //Belt teeth. | |
16 | for (i = [0 : len / belt_tooth_distance]) { | |
17 | translate([0, 0, i * belt_tooth_distance]) cube([2, 9, belt_tooth_distance * belt_tooth_ratio], center = true); | |
18 | } | |
19 | } | |
20 | module plate_screw(long=0) { | |
21 | translate([0, 0, -long]) screw(head_drop=14 + long, h=30 + long, r_head=3.6, r=1.7, $fn=24, slant=false); | |
22 | } | |
23 | module screw(h=20, r=2, r_head=3.5, head_drop=0, slant=0, poly=false, $fn=0){ | |
24 | //makes screw with head | |
25 | //for substraction as screw hole | |
26 | if (poly) { | |
27 | cylinder_poly(h=h, r=r, $fn=$fn); | |
28 | } else { | |
29 | cylinder(h=h, r=r, $fn=$fn); | |
30 | } | |
31 | if (slant) { | |
32 | translate([0, 0, head_drop-0.01]) cylinder(h=r_head, r2=0, r1=r_head, $fn=$fn); | |
33 | } | |
34 | ||
35 | if (head_drop > 0) { | |
36 | translate([0, 0, -0.01]) cylinder(h=head_drop+0.01, r=r_head, $fn=$fn); | |
37 | } | |
38 | } | |
39 | module nut(d,h,horizontal=true){ | |
40 | cornerdiameter = (d / 2) / cos (180 / 6); | |
41 | cylinder(h = h, r = cornerdiameter, $fn = 6); | |
42 | if(horizontal){ | |
43 | for(i = [1:6]){ | |
44 | rotate([0,0,60*i]) translate([-cornerdiameter-0.2,0,0]) rotate([0,0,-45]) cube([2,2,h]); | |
45 | } | |
46 | } | |
47 | } | |
48 | ||
49 | module fillet(radius, height=100, $fn=0) { | |
50 | //this creates acutal fillet | |
51 | translate([-radius, -radius, -height / 2 - 0.02]) difference() { | |
52 | cube([radius * 2, radius * 2, height + 0.04]); | |
53 | if ($fn == 0 && (radius == 2 || radius == 3 || radius == 4)) { | |
54 | cylinder(r=radius, h=height + 0.04, $fn=4 * radius); | |
55 | } else { | |
56 | cylinder(r=radius, h=height + 0.04, $fn=$fn); | |
57 | } | |
58 | ||
59 | } | |
60 | } | |
61 | ||
62 | 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){ | |
63 | // | |
64 | if (use_fillets == 1) { | |
65 | if (center) { | |
66 | cube_fillet_inside(size, radius, vertical, top, bottom, $fn); | |
67 | } else { | |
68 | translate([size[0]/2, size[1]/2, size[2]/2]) | |
69 | cube_fillet_inside(size, radius, vertical, top, bottom, $fn); | |
70 | } | |
71 | } else { | |
72 | if (use_fillets == 2) { | |
73 | if (center) { | |
74 | cube_fillet_inside(size, radius, vertical, top, bottom, 4); | |
75 | } else { | |
76 | translate([size[0]/2, size[1]/2, size[2]/2]) | |
77 | cube_fillet_inside(size, radius, vertical, top, bottom, 4); | |
78 | } | |
79 | ||
80 | } else { | |
81 | cube(size, center); | |
82 | } | |
83 | } | |
84 | ||
85 | } | |
86 | ||
87 | module cube_negative_fillet(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){ | |
88 | ||
89 | j=[1,0,1,0]; | |
90 | ||
91 | for (i=[0:3]) { | |
92 | if (radius > -1) { | |
93 | rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(radius, size[2], $fn=$fn); | |
94 | } else { | |
95 | rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(vertical[i], size[2], $fn=$fn); | |
96 | } | |
97 | rotate([90*i, -90, 0]) translate([size[2]/2, size[j[i]]/2, 0 ]) fillet(top[i], size[1-j[i]], $fn=$fn); | |
98 | rotate([90*(4-i), 90, 0]) translate([size[2]/2, size[j[i]]/2, 0]) fillet(bottom[i], size[1-j[i]], $fn=$fn); | |
99 | ||
100 | } | |
101 | } | |
102 | ||
103 | module cube_fillet_inside(size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0){ | |
104 | //makes CENTERED cube with round corners | |
105 | // if you give it radius, it will fillet vertical corners. | |
106 | //othervise use vertical, top, bottom arrays | |
107 | //when viewed from top, it starts in upper right corner (+x,+y quadrant) , goes counterclockwise | |
108 | //top/bottom fillet starts in direction of Y axis and goes CCW too | |
109 | ||
110 | ||
111 | if (radius == 0) { | |
112 | cube(size, center=true); | |
113 | } else { | |
114 | difference() { | |
115 | cube(size, center=true); | |
116 | cube_negative_fillet(size, radius, vertical, top, bottom, $fn); | |
117 | } | |
118 | } | |
119 | } | |
120 |