summaryrefslogtreecommitdiff
path: root/multiswitch.scad
Unidiff
Diffstat (limited to 'multiswitch.scad') (more/less context) (ignore whitespace changes)
-rw-r--r--multiswitch.scad105
1 files changed, 105 insertions, 0 deletions
diff --git a/multiswitch.scad b/multiswitch.scad
new file mode 100644
index 0000000..75d95e4
--- a/dev/null
+++ b/multiswitch.scad
@@ -0,0 +1,105 @@
1layer_height=.2; extrusion_width=.5;
2epsilon=.01;
3
4use <pushfittery.scad>;
5include <pushfit_data.scad>;
6
7module multiswitch(
8 liner_od = 4, liner_id = 2,
9 angle = 15, // to the vertical (output) axis
10 inputs = 4,
11 minshell = 2*extrusion_width,
12 shell = 5*extrusion_width,
13 pf = pushfit_embeddest,
14 debug = 0, // how many inputs -1 the debug cutout spans
15 print = true,
16
17 liner_d_tolerance=.2
18) {
19 fnd = 4*PI; fnr = 2*fnd;
20
21 pushfit_d = pf_d(pf);
22 pushfit_h = pf_h(pf);
23
24 angular_step = 360/inputs;
25 lod = liner_od+liner_d_tolerance; // effective liner diameter
26
27 sinsin = sin(angle)*sin(angular_step/2);
28 function l_to(d) = d*cos(asin(sinsin))/sinsin;
29 l_output = lod;
30 l_input = l_to(pushfit_d/2+minshell);
31 l_fork = l_to(liner_id/2);
32 l_narrow = l_to(lod/2+minshell);
33
34 module forinputs() {
35 for(zr=[0:angular_step:359]) rotate([0,0,zr]) rotate([0,angle,0]) children();
36 }//forinputs module
37 module foroutput() {
38 rotate([180,0,0]) children();
39 }
40
41 module laydown() {
42 r = pushfit_d/2+shell;
43 h_bottom = l_output+pushfit_h;
44 /* The top point on the cylinder that will touch the bed */
45 x0 = r*cos(angular_step/2);
46 y0 = r*sin(angular_step/2);
47 z0 = l_input+pushfit_h;
48 /* The same point after rotation by "angle" around Y axis */
49 x1 = z0*sin(angle)+x0*cos(angle);
50 y1 = y0;
51 z1 = z0*cos(angle)-x0*sin(angle);
52 ax1 = atan(y1/x1);
53 /* And its x-coordinate after final "angular_step/2" Z-rotation */
54 ax2 = ax1-angular_step/2;
55 x2 = x1*cos(ax2)/cos(ax1);
56 laydown_angle = atan((x2-r)/(z1+h_bottom));
57 rotate([90-laydown_angle,0,0])
58 translate([0,r,h_bottom])
59 rotate([0,0,angular_step/2-90])
60 children();
61 }
62 module finalize() {
63 if(print) laydown() children();
64 else children();
65 }
66
67 finalize() difference() {
68 hull() {
69 forinputs()
70 translate([0,0,l_input+pushfit_h]) mirror([0,0,1])
71 cylinder(d=pushfit_d+shell*2,h=epsilon,$fn=pushfit_d*fnd);
72 foroutput()
73 translate([0,0,l_output+pushfit_h]) {
74 cylinder(d=pushfit_d+shell*2,h=epsilon,$fn=pushfit_d*fnd);
75 }
76 }
77 forinputs() {
78 translate([0,0,l_input]) pushfit(pf);
79 translate([0,0,l_narrow]) {
80 cylinder(d=lod,h=l_input+1-l_narrow,$fn=lod*fnd);
81 mirror([0,0,1]) translate([0,0,-epsilon])
82 cylinder(d1=(liner_id+lod)/2,d2=liner_id,h=liner_id,$fn=lod*fnd);
83 }
84 cylinder(d=liner_id,h=l_input+epsilon,$fn=liner_id*fnd);
85 }
86 foroutput() {
87 translate([0,0,l_output]) pushfit(pf);
88 cylinder(d=lod,h=l_output+1,$fn=lod*fnd);
89 }
90 hull() {
91 forinputs()
92 translate([0,0,l_fork]) cylinder(d=liner_id,h=epsilon,$fn=liner_id*fnd);
93 foroutput()
94 cylinder(d=liner_id,h=epsilon,$fn=liner_id*fnd);
95 }
96 if(debug) {
97 translate([0,0,-20/*TODO:*/])
98 rotate_extrude(angle=angular_step*debug)
99 square([50,100]/*TODO:*/);
100 }
101 }
102
103}
104
105multiswitch(debug=2,print=false);