chiark / gitweb /
sealing-box, bike-lipo-box: $-ise cnrrad
[reprap-play.git] / sealing-box.scad.m4
1 // -*- C -*-
2
3 // This file can be used in two ways:
4 //
5 // A. Rectangular boxes
6 //      1. include <sealing-box.scad>
7 //      2. assign() values to (xxx these should be $ variables)
8 //           $sealingbox_wallth
9 //           $sealingbox_xbox (outer dimension)
10 //           $sealingbox_ybox (outer dimension)
11 //           $sealingbox_zbox (inner dimension)
12 //           $sealingbox_ceilth
13 //           $sealingbox_floorth
14 //           $sealingbox_wallth
15 //      3. use the modules
16 //           SealingBox_RectBox
17 //           SealingBox_RectLid
18 //
19 // B. Complicated shapes, but harder work
20 //      1. Be a .m4 file and m4_include sealing-box.scad.m4
21 //      2. Define your own BoxDoShapeSomething like BoxDoShapeRect
22 //      3. Invoke BoxUseShape
23 //      4. Use the Box and Lid modules generated
24 //
25 // Other settings
26 //  $sealingbox_cnrrad
27
28 $sealingbox_cnrrad = 10;
29
30 m4_define(`BoxLocals',`
31   wall = $sealingbox_wallth;
32   floorth = $sealingbox_floorth;
33   ceilth = $sealingbox_ceilth;
34   xbox = $sealingbox_xbox;
35   ybox = $sealingbox_ybox;
36   zbox = $sealingbox_zbox;
37   cnrrad = $sealingbox_cnrrad;
38
39   ts_cidoff = (cnrrad * (1-.7) + wall * .8) * [1,1];
40
41   xbox_lin = xbox - cnrrad*2;
42   ybox_lin = ybox - cnrrad*2;
43 ')
44
45 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
46 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
47 m4_define(`Box_Part',`
48   translate([($1),($2)])
49     rotate([0,0,($3)])
50     mirror([($4),0,0])
51     BoxPart_Extrude_$5($6, $7)') m4_dnl
52
53 boxpart_d = 0.01;
54
55 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
56 m4_define(`BoxPart_Extrude_Linear',`
57   rotate([90,0,0])
58     translate([0,0, -($1)])
59     linear_extrude(height= boxpart_d + ($1)) {
60       $2
61     }
62 ')
63
64 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
65 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
66 m4_dnl  y at first and then bending towards negative x, until
67 m4_dnl  use negative x0_radius to inciate bending towards positive x
68 m4_dnl  swept_angle is reached
69 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
70 m4_define(`BoxPart_Extrude_Arc',`
71   translate([-($1),0,0])
72     intersection(){
73       translate([0,0,-500])
74         linear_extrude(height=1000)
75         scale(500)
76         mirror([($1)<0, 0,0])
77         FArcSegment_mask($2);
78       rotate_extrude(convexity=10, $fs=1, $fn=36)
79         mirror([($1)<0, 0,0])
80         translate([+($1),0,0]){
81           $3
82         }
83     }
84 ')
85
86 m4_dnl BoxDoShapeRect(`profile(profileargs)');
87 m4_define(`BoxDoShapeRect',`
88   Box_Part(0,           cnrrad,         0,0, Linear,`ybox_lin', `$1' )
89   Box_Part(0,           ybox-cnrrad,    0,0, Arc,`-cnrrad,90' , `$1' )
90   Box_Part(cnrrad,      ybox,         -90,0, Linear,`xbox_lin', `$1' )
91   Box_Part(xbox-cnrrad, ybox,         -90,0, Arc,`-cnrrad,90' , `$1' )
92   Box_Part(xbox,        ybox-cnrrad, -180,0, Linear,`ybox_lin', `$1' )
93   Box_Part(xbox,        cnrrad,      -180,0, Arc,`-cnrrad,90' , `$1' )
94   Box_Part(xbox-cnrrad, 0,           -270,0, Linear,`xbox_lin', `$1' )
95   Box_Part(cnrrad,      0,           -270,0, Arc,`-cnrrad,90' , `$1' )
96 ')
97
98 m4_dnl '
99
100 module SealingBox_WallProfile(){
101   BoxLocals
102   z = zbox - innertube - tubesealrad;
103   translate([0, -0.1]) square([wall, z]);
104   translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
105 }
106
107 module SealingBox_FloorProfile(){
108   BoxLocals
109   mirror([0,1]) square([wall, floorth]);
110 }
111
112 module SealingBox_LidProfile(){
113   BoxLocals
114   rad = tubesealrad + innertube;
115   morex = wall;
116   difference(){
117     translate([-lidoverlap - innertube,
118                zbox - lidoverhang - innertube])
119       square([lidoverlap + innertube + wall,
120               lidoverhang + innertube + ceilth]);
121     hull(){
122       translate([tubesealrad,
123                  zbox - innertube - tubesealrad])
124         for (t=[ [0,0],
125                  [morex*2, 0],
126                  [0, -zbox]
127                  ]) {
128           translate(t)
129             circle(r= tubesealrad + innertube, $fn=20);
130         }
131     }
132   }
133 }
134
135 module SealingBox_CeilProfile(){
136   BoxLocals
137   translate([0, zbox])
138     square([wall*2, ceilth]);
139 }
140
141 // BoxDoShape(Basename,BoxDoShapeSomething)
142 // generates modules BasenameBox and BasenameLid
143 m4_define(`BoxUseShape',`
144   module $1Box(){
145     BoxLocals
146     $2(SealingBox_WallProfile(););
147     hull(){ $2(SealingBox_FloorProfile();); }
148   }
149
150   module $1Lid(){
151     BoxLocals
152     $2(SealingBox_LidProfile(););
153     hull(){ $2(SealingBox_CeilProfile();); }
154   }
155 ')
156
157 BoxUseShape(`TestSealBox',`BoxDoShapeRect')