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