chiark / gitweb /
svg-prep-dxf: do Ungroup too
[reprap-play.git] / simplephone-case.scad
1 // -*- C -*-
2
3 psz = [
4        120,
5        56 + 5 - 3.75,
6        15 + 3,
7        ];
8
9 thick = [
10          2,
11          2,
12          1.5,
13          ];
14
15 btn_x = 59.6;
16 btn_dia = 13;
17 btn_y = 14.03;
18
19 abtn_x = 46.85;
20 abtn_sz = [ 11, 13 ];
21
22 screen_xbot = 79;
23 screen_sz = [ 35, 46 ];
24
25 thumb_xbot = 90;
26 thumb_dia = 25;
27
28 vol_xbot = 86.5;
29 vol_xtop = 107.5;
30 vol_depth = 1.0;
31 vol_zsz = 9;
32 vol_zoff = 0;
33
34 rail_ysz = 2.5;
35 rail_zsz = 2.5;
36
37 stay_height = 1.49;
38
39 case_x_less = 0; //case_x_less = 10;
40
41 inner_cnr_rad = 4.0;
42
43 // calculated
44
45 btn_yprop = btn_y / psz[1];
46 echo(btn_yprop);
47
48 ym = psz[1]/2;
49 outer_cnr_rad = inner_cnr_rad + thick[2];
50
51 x_sliced = outer_cnr_rad * (1-sin(45));
52
53 $screen = true;
54
55 module RoundedProfile(sz, cnr_rad){
56   hull(){
57     for (x=[ cnr_rad, sz[0]-cnr_rad ])
58       for (y=[ cnr_rad, sz[1]-cnr_rad ])
59         translate([x,y])
60           circle(r= cnr_rad, $fn=20);
61   }
62 }
63
64 module RoundedCube(sz, cnr_rad){
65   if ($test)
66     cube(sz);
67   else hull(){
68     for (x=[ cnr_rad, sz[0]-cnr_rad ])
69       for (y=[ cnr_rad, sz[1]-cnr_rad ])
70         for (z=[ cnr_rad, sz[2]-cnr_rad ])
71           translate([x,y,z])
72             sphere(r= cnr_rad, $fn=40);
73   }
74 }
75
76 module Stay(xbot, xtop, width, midgap_width) {
77   translate([ (xbot+xtop)/2, psz[1]/2, psz[2] ]){
78     difference(){
79       cube([ xtop-xbot, width, stay_height*2 ], center=true);
80       if (midgap_width > 0)
81         cube([ 200, midgap_width, 10 ], center=true);
82     }
83   }
84 }
85
86 module Stays(){
87   Stay(  76, 82, 10, 0);
88   Stay(-0.1, 55, 10, 0);
89   Stay( 113,125, 70, 15);
90 }
91
92 module Case(){
93   difference(){
94     mirror([1,0,0])
95       translate(-thick +
96                 - [1,0,0] * x_sliced)
97       RoundedCube(psz
98                   + 2*thick
99                   - [1,0,0] * (thick[0])
100                   + [1,0,0] * (x_sliced)
101                   - [case_x_less, 0, 0],
102                   outer_cnr_rad);
103
104     for (yp= [ btn_yprop, 1-btn_yprop ])
105       translate([ -btn_x,
106                   yp * psz[1],
107                   0.5 * psz[2] ])
108         cylinder(r= btn_dia/2, h=20);
109
110     translate([ -abtn_x,
111                 btn_yprop * psz[1],
112                 psz[2] ])
113       cube(concat(abtn_sz, [ thick[2]*3 ]), center=true);
114
115     if ($screen)
116       mirror([1,0,0])
117       translate([ screen_xbot,
118                   (psz[1] - screen_sz[1])/2,
119                   psz[2]-3 ])
120       cube(concat(screen_sz, [ thick[2]+6 ]));
121
122     hull(){
123       for (x=[ thumb_xbot+thumb_dia/2, psz[0]+10 ])
124         translate([ -x,
125                     ym,
126                     -thick[2]-1 ])
127           cylinder(r= thumb_dia/2,
128                    h= thick[2] + 2,
129                    $fn= 20);
130     }
131
132     mirror([1,0,0])
133       translate([ (vol_xbot+vol_xtop)/2, 0, psz[2]/2 + vol_zoff ])
134       cube([ vol_xtop-vol_xbot, vol_depth*2, vol_zsz ], center=true);
135
136     translate([ thick[0], -10, -10 ])
137       cube([ 10, psz[1]+20, psz[2]+20 ]);
138
139     //translate([-50,-50,10]) cube([100,100,100]);
140
141     mirror([1,0,0])
142       difference(){
143         RoundedCube(psz + [1,0,0],
144                     inner_cnr_rad);
145
146         Stays();
147
148         if (0) for (m=[0,1]) {
149           translate([0,ym,0]) mirror([0,m,0]) translate([0,-ym,0])
150             translate([-1,-1, psz[2]-rail_zsz])
151             cube([psz[0]+1, rail_ysz+1, rail_zsz+1]);
152         }
153       }
154   }
155 }
156
157 module TestLoop(){
158   intersection(){
159     Case($screen=false);
160     translate([ -vol_xbot, 0,0 ])
161       cube([ 4, 200,200 ], center=true);
162   }
163 }
164
165 Case();
166 //TestLoop();
167 //RoundedCube(psz, inner_cnr_rad);