chiark / gitweb /
dcb85680e4a38f867ecaa67d1d84177b365950bf
[moebius3.git] / moebius-demo.scad
1 // -*- C -*-
2
3 include <moebius-core.scad>
4
5 // settings etc.
6
7 pin_stemwidth = 1.5;
8 pin_stemlen = 1.0;
9 pin_headwidth = 3.0;
10 pin_headheight = 0.5;
11 pin_slot_xslop = 0.25;
12
13 pin_yadj_range = [ -0.50, +0.25 ];
14 pin_yslop = 0.25;
15
16 pin_pin_xslop = 0.00;
17 pin_pin_yadj_range = pin_yadj_range + [ 0.00, 0.00 ];
18
19 pin_height = 5;
20
21 // computed
22
23 sliceat = moebiuscore_sliceat * moebiuscore_nomsize;
24
25 module TopSlice(){
26   translate([0,0, 200-sliceat])
27     cube(center=true, 400);
28 }
29
30 module MainBody(){
31   intersection(){
32     MoebiusCore();
33     TopSlice();
34   }
35 }
36
37 module HalfPinHeadProfile(xslop, yadj, lenadj) {
38   sw = pin_stemwidth + xslop*2;
39   tw = pin_headwidth + xslop*2;
40   th = pin_headheight + lenadj - yadj;
41   hull(){
42     translate([ -tw/2,
43                 pin_stemlen/2 + yadj + (pin_headwidth - pin_stemwidth)/2 ])
44       square([ tw, th ]);
45     translate([ -sw/2,
46                 pin_stemlen/2 + yadj ])
47       square([ sw, th ]);
48   }
49 }
50
51 module PinStemProfile(xslop, yadj) {
52   sl = pin_stemlen + pin_headheight/2 + max(yadj * 2, 0);
53   square(center=true,
54          [ pin_stemwidth + xslop*2,
55            sl ]);
56 }
57
58 module PinExtrudePortion(zi,zrange){
59   translate([0,0,zrange[zi]])
60     mirror([0,0,zi])
61     linear_extrude(height=0.1)
62     children(0);
63 }
64
65 module PinExtrude(zrange,
66                   xslop=0,
67                   yadjs=[[0,0], [0,0]], // [top[], bottom[]]
68                   lenadjs=[0,0]){ // in each case: zrange[0],zrange[1]
69   for (topboti=[0,1]) {
70     mirror([0,topboti,0]){
71       hull(){
72         for (zi=[0,1])
73           PinExtrudePortion(zi,zrange)
74             HalfPinHeadProfile(xslop, yadjs[topboti][zi], lenadjs[zi]);
75       }
76     }
77   }
78   hull(){
79     for (zi=[0,1])
80       PinExtrudePortion(zi,zrange)
81         PinStemProfile(xslop, max(yadjs[zi][0], yadjs[zi][1]));
82   }
83 }
84
85 module PinCutout(){
86   PinExtrude([-10,10],
87              xslop= pin_slot_xslop,
88              yadjs = [ [0,0],
89                        [1,1] * -pin_stemlen/2 ],
90              // bigger gap in -ve y direction
91              lenadjs = [1,1] * (pin_yslop + pin_yadj_range[1]) );
92 }
93
94 module Pin(){
95   PinExtrude([-0.5, 0.5] * pin_height,
96              xslop = -pin_pin_xslop,
97              yadjs = [pin_pin_yadj_range, pin_pin_yadj_range],
98              lenadjs = [1,1] * pin_yadj_range[1]
99              );
100 }
101
102 module PlacePins(pins=[0,1]){
103   for (i=pins) {
104     translate( moebius_pin_locns[i] * moebiuscore_nomsize ) {
105       multmatrix(moebius_pin_matrix[i])
106         children(0);
107     }
108   }
109 }
110
111 module PinDemo(){
112   PlacePins()
113     cube([1,4,9]);
114 }
115
116 module Top(){ ////toplevel
117   difference(){
118     intersection(){
119       MoebiusCore();
120       TopSlice();
121     }
122     PlacePins(){
123       PinCutout();
124     }
125   }
126 }
127
128 module Bottom(){ ////toplevel
129   difference(){
130     MoebiusCore();
131     TopSlice();
132     PlacePins()
133       mirror([0,1,0]) PinCutout();
134   }
135 }
136
137 module Demo(){ ////toplevel
138   Bottom();
139   %Top();
140   color("blue") PlacePins([0]) Pin();
141 }
142
143 module Kit(){ ////toplevel
144   off = moebiuscore_nomsize*2.5;
145   translate([0,0,sliceat])
146     Top();
147   translate([ 0, -off, 0 ])
148     rotate([0,180,0])
149     translate([0,0,sliceat])
150     Bottom();
151   for (d = [0,1] * pin_height * 2)
152     translate([ off, d, 0 ])
153     rotate([90,0,0])
154     translate([ 0,0, pin_height/2 ])
155     Pin();
156 }
157
158 module TestKit(){
159   intersection(){
160     Kit();
161     cube([500,500,15], center=true);
162   }
163 }
164
165 //MainBody();
166 //%PinDemo();
167 //PinExtrude([-2,10]);
168 //PinCutout();
169 //Pin();
170 //%PinCutout();
171 //Top();
172 //Bottom();
173 //Kit();
174 //Demo();
175 TestKit();