Added a license
[Model-M.git] / key-double.scad
blob7469c3907df8f416e5559f60fccfeb32d4c95397
1 //measures are in millimeters
2 //(feel free to cocnvert them to attoparsecs)
3 AY=37.0;
4 AX=19.0;
5 BY=32.0;
6 BLX=14.5;
7 EZ=11.0;
8 FLZ=14.0;
9 H=12.75;
10 SHAFT_OFF_Y=28.0;
11 BLIND_SHAFT_OFF_Y=9.0;
12 CYL_OFF_Z=200;
13 CYL_DEPTH=0.1;
14 CLIP_X=2;
15 CLIP_Y=0.75;
16 CLIP_H=3*CLIP_Y;
17 CORNER_RADIUS=2;
18 INNER_GUARD_RADIUS=6.5;
19 OUTER_GUARD_RADIUS=7.5;
20 BLIND_SHAFT_OUTER_DIAMETER=4.0;
21 BLIND_SHAFT_INNER_DIAMETER=2.0;
22 SHAFT_X=8.0;
23 SHAFT_Y=6.0;
24 SHAFT_LENGTH=9.0;
25 SHAFT_THICKNESS=1.0;
26 SHAFT_CLIP_WIDTH=3.0;
27 SHAFT_CLIP_THICKNESS=0.75;
28 SHAFT_CLIP_HEIGHT=2.0;
29 SHAFT_CLIP_SLOPE_DEPTH=1.0;
30 SHAFT_CLIP_ANGLE=45;
31 SHAFT_END_CUTOUT_HEIGHT=1.5;
32 SHAFT_LARGE_SLOT_TO_BASE=1.5;
33 SHAFT_SMALL_SLOT_LENGTH=7.25;
34 SHAFT_SMALL_SLOT_WIDTH=2.5;
35 SHAFT_SPRING_HOLDER_WIDTH=3.0;
36 SHAFT_SPRING_HOLDER_TO_BASE=4.0;
37 SHAFT_SPRING_GUIDE_WIDTH=1.0;
38 SHAFT_SPRING_GUIDE_SIDES_HEIGHT=3.5;
39 STRUT_THICKNESS=1;
40 STRUT_HEIGHT=3;
41 STRUT_SPACING=1;
42 SHAFT_SPRING_HOLDER_NIPPLE_HEIGHT=1;
43 SHAFT_SPRING_HOLDER_NIPPLE_RADIUS=0.75;
45 SHAFT_SMALL_SLOT_BEVEL=0.5;
47 WallThickness=0.75;
48 ClipWidth=2.2;
49 ClipDepth=0.75;
51 //ascfront=FLZ/sqrt(pow(FLZ,2)-pow(H,2));
52 //asctop=(H-EZ)/sqrt(pow(BLX,2)-pow((H-EZ),2));
54 alpha=asin((H-EZ)/BLX);
55 beta=asin(H/FLZ);
56 gamma=90-asin((0.5*(AY-BY))/EZ);
58 module keycap(){
59         scale([AX/(AX+2*CORNER_RADIUS),AY/(AY+2*CORNER_RADIUS),1])
60         translate([CORNER_RADIUS,CORNER_RADIUS,0.01])
61         minkowski(){
62                 difference(){
63                         cube([AX,AY,H]);
64                         rotate(a=gamma,v=[1,0,0]) cube([100,100,100]);
65                         translate([0,AY,0]) rotate(a=90-gamma,v=[1,0,0]) cube([100,100,100]);
66                         translate([0,0,EZ]) rotate(a=-alpha,v=[0,1,0]) translate([-50,0,0]) cube([100,100,100]);
67                         translate([0,AY/2,EZ+CYL_OFF_Z]) rotate(a=90-alpha,v=[0,1,0]) cylinder(h=100,center=true,r=CYL_OFF_Z+CYL_DEPTH,$fa=1);
68                         translate([AX,0,0]) rotate(a=beta-90,v=[0,1,0]) cube([100,100,100]);
69                 }
70                 cylinder(h=0.01,r=CORNER_RADIUS,$fs=0.6);
71                 //rotate(a=90,v=[1,0,0]) cylinder(h=0.01,r=1,$fs=0.3);
72         }
75 module blind_shaft(){
76         translate([0,0,-SHAFT_LENGTH]) difference(){
77                 cylinder(r=BLIND_SHAFT_OUTER_DIAMETER/2,h=100,$fs=0.3);
78                 cylinder(r=BLIND_SHAFT_INNER_DIAMETER/2,h=100,$fs=0.3);
79         }
82 module shaft(){
83         spring_guide_length = SHAFT_X-SHAFT_THICKNESS-SHAFT_SPRING_HOLDER_WIDTH;
84         spring_guide_height = SHAFT_SPRING_HOLDER_TO_BASE-SHAFT_LARGE_SLOT_TO_BASE;
85         translate([0,0,-SHAFT_LENGTH]) difference(){
86                 union(){
87                         difference(){
88                                 union(){
89                                         difference(){
90                                                 intersection(){
91                                                         cylinder(h=100,r=SHAFT_X/2,$fs=0.3);
92                                                         translate([-SHAFT_X/2,-SHAFT_Y/2,0]) cube([SHAFT_X,SHAFT_Y,100]);
93                                                 }
94                                                 intersection(){
95                                                         cylinder(h=100,r=SHAFT_X/2-SHAFT_THICKNESS,$fs=0.3);
96                                                         translate([-SHAFT_X/2+SHAFT_THICKNESS,-SHAFT_Y/2+SHAFT_THICKNESS,0]) cube([SHAFT_X-2*SHAFT_THICKNESS,SHAFT_Y-2*SHAFT_THICKNESS,100]);
97                                                 }
98                                         }
99                                         translate([-SHAFT_CLIP_WIDTH/2, -SHAFT_CLIP_THICKNESS-SHAFT_Y/2,0]) cube([SHAFT_CLIP_WIDTH/2, SHAFT_CLIP_THICKNESS,SHAFT_CLIP_HEIGHT]);
100                                         translate([-SHAFT_CLIP_WIDTH/2, SHAFT_Y/2,0]) cube([SHAFT_CLIP_WIDTH/2, SHAFT_CLIP_THICKNESS,SHAFT_CLIP_HEIGHT]);
101                                 }
102                                 translate([-SHAFT_CLIP_WIDTH/2, -SHAFT_CLIP_THICKNESS-SHAFT_Y/2+SHAFT_CLIP_SLOPE_DEPTH,0]) rotate(a=90+SHAFT_CLIP_ANGLE,v=[1,0,0]) cube([SHAFT_CLIP_WIDTH/2,100,100]);
103                                 translate([-SHAFT_CLIP_WIDTH/2, SHAFT_Y/2+SHAFT_CLIP_THICKNESS-SHAFT_CLIP_SLOPE_DEPTH,0]) mirror([0,1,0]) rotate(a=90+SHAFT_CLIP_ANGLE,v=[1,0,0]) cube([SHAFT_CLIP_WIDTH/2,100,100]);
104                                 translate([0,-50,0]) cube([100,100,SHAFT_END_CUTOUT_HEIGHT]);
105                                 translate([0,-SHAFT_Y/2+SHAFT_THICKNESS,0]) cube([100,SHAFT_Y-SHAFT_THICKNESS*2,SHAFT_LENGTH+SHAFT_LARGE_SLOT_TO_BASE]);
106                                 //small slot cutout
107                                 translate([0,-SHAFT_SMALL_SLOT_WIDTH/2,0]){
108                                         mirror([1,0,0]) cube([100,SHAFT_SMALL_SLOT_WIDTH,SHAFT_SMALL_SLOT_LENGTH-0.5*SHAFT_SMALL_SLOT_WIDTH]);
109                                 }
110                                 //small slot cutout
111                                 translate([0,0,SHAFT_SMALL_SLOT_LENGTH-0.5*SHAFT_SMALL_SLOT_WIDTH]) rotate(a=-90,v=[0,1,0]) cylinder(r=SHAFT_SMALL_SLOT_WIDTH/2,h=SHAFT_X/2,$fs=0.3);
112                         }
113                         //spring holder
114                         translate([-SHAFT_X/2+SHAFT_SPRING_HOLDER_WIDTH/2+SHAFT_THICKNESS,0,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE]) cylinder(r=SHAFT_SPRING_HOLDER_WIDTH/2,h=100,$fs=0.3);
115                         intersection(){
116                                 translate([-SHAFT_X/2+SHAFT_SPRING_HOLDER_WIDTH/2+SHAFT_THICKNESS,0,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE-SHAFT_SPRING_HOLDER_NIPPLE_HEIGHT]) cylinder(r=SHAFT_SPRING_HOLDER_NIPPLE_RADIUS,h=100,$fs=0.3);
117                                 translate([0,0,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE-SHAFT_SPRING_HOLDER_NIPPLE_HEIGHT*1.5]) rotate(v=[0,1,0], a=atan(SHAFT_SPRING_HOLDER_NIPPLE_HEIGHT/(SHAFT_SPRING_HOLDER_NIPPLE_RADIUS*2))) translate([-50,-50,0]) cube(100,100,100);
118                         }
119                         intersection(){
120                                 difference(){
121                                         translate([SHAFT_X/2-SHAFT_THICKNESS,-0.5*SHAFT_SPRING_GUIDE_WIDTH,SHAFT_LENGTH+SHAFT_LARGE_SLOT_TO_BASE]) mirror([1,0,0]) cube([100,SHAFT_SPRING_GUIDE_WIDTH,100]);
122                                         translate([-SHAFT_X/2+SHAFT_SPRING_HOLDER_WIDTH+SHAFT_THICKNESS,-0.5*SHAFT_SPRING_GUIDE_WIDTH,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE])
123                                         mirror([1,0,0]) rotate(a=90-asin(spring_guide_height/spring_guide_length),v=[0,1,0]) mirror([0,0,1]) translate([0,0,-50]) cube([100,SHAFT_SPRING_GUIDE_WIDTH,100]);
124                                 }
125                                 cube([SHAFT_X-SHAFT_THICKNESS,SHAFT_Y,100],center=true);
126                         }
127                         //side spring guides
128                         difference(){
129                                 translate([-SHAFT_X/2+SHAFT_THICKNESS+(SHAFT_SPRING_HOLDER_WIDTH-SHAFT_SPRING_GUIDE_WIDTH)/2,-SHAFT_Y/2+SHAFT_THICKNESS,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE-SHAFT_SPRING_GUIDE_SIDES_HEIGHT]) cube([SHAFT_SPRING_GUIDE_WIDTH,SHAFT_Y-2*SHAFT_THICKNESS,EZ-SHAFT_SPRING_HOLDER_TO_BASE+SHAFT_SPRING_GUIDE_SIDES_HEIGHT]);
130                                 translate([-SHAFT_X/2+SHAFT_THICKNESS+(SHAFT_SPRING_HOLDER_WIDTH-SHAFT_SPRING_GUIDE_WIDTH)/2,-SHAFT_SPRING_HOLDER_WIDTH/2,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE]) rotate(a=-asin(((SHAFT_Y-SHAFT_SPRING_HOLDER_WIDTH)/2-SHAFT_THICKNESS)/SHAFT_SPRING_GUIDE_SIDES_HEIGHT),v=[1,0,0]) translate([0,0,-50]) cube([SHAFT_SPRING_GUIDE_WIDTH,100,100]);
131                         }
132                         difference(){
133                                 translate([-SHAFT_X/2+SHAFT_THICKNESS+(SHAFT_SPRING_HOLDER_WIDTH-SHAFT_SPRING_GUIDE_WIDTH)/2,-SHAFT_Y/2+SHAFT_THICKNESS,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE-SHAFT_SPRING_GUIDE_SIDES_HEIGHT]) cube([SHAFT_SPRING_GUIDE_WIDTH,SHAFT_Y-2*SHAFT_THICKNESS,EZ-SHAFT_SPRING_HOLDER_TO_BASE+SHAFT_SPRING_GUIDE_SIDES_HEIGHT]);
134                                 mirror([0,1,0]) translate([-SHAFT_X/2+SHAFT_THICKNESS+(SHAFT_SPRING_HOLDER_WIDTH-SHAFT_SPRING_GUIDE_WIDTH)/2,-SHAFT_SPRING_HOLDER_WIDTH/2,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE]) rotate(a=-asin(((SHAFT_Y-SHAFT_SPRING_HOLDER_WIDTH)/2-SHAFT_THICKNESS)/SHAFT_SPRING_GUIDE_SIDES_HEIGHT),v=[1,0,0]) translate([0,0,-50]) cube([SHAFT_SPRING_GUIDE_WIDTH,100,100]);
135                         }
136                 }
137                 translate([-SHAFT_X/2+SHAFT_SPRING_HOLDER_WIDTH+SHAFT_THICKNESS,-SHAFT_Y/2+SHAFT_THICKNESS,SHAFT_LENGTH+SHAFT_SPRING_HOLDER_TO_BASE]) mirror([1,0,0]) rotate(a=90-asin(spring_guide_height/spring_guide_length),v=[0,1,0]) mirror([0,0,1]) cube([SHAFT_THICKNESS,SHAFT_Y-2*SHAFT_THICKNESS,100]);
138         }
141 module guard(){
142         difference(){
143                 union(){
144                         cube([100,STRUT_THICKNESS,100],center=true);
145                         cylinder(r=OUTER_GUARD_RADIUS,h=100);
146                 }
147                 difference(){
148                         cylinder(r=INNER_GUARD_RADIUS,h=100);
149                         translate([-STRUT_SPACING/2-STRUT_THICKNESS,-50,EZ-STRUT_HEIGHT]) cube([STRUT_THICKNESS,100,STRUT_HEIGHT]);
150                         translate([STRUT_SPACING/2,-50,EZ-STRUT_HEIGHT]) cube([STRUT_THICKNESS,100,STRUT_HEIGHT]);
151                         translate([-50,-STRUT_SPACING/2-STRUT_THICKNESS,EZ-STRUT_HEIGHT]) cube([100,STRUT_THICKNESS,STRUT_HEIGHT]);
152                         translate([-50,STRUT_SPACING/2,EZ-STRUT_HEIGHT]) cube([100,STRUT_THICKNESS,STRUT_HEIGHT]);
153                 }
154         }
157 difference(){
158         keycap();
159         difference(){
160                 translate([WallThickness, WallThickness, 0]) scale(v=[1-2*WallThickness/AX, 1-2*WallThickness/AY, 1-WallThickness/H]) keycap();
161                 translate([OUTER_GUARD_RADIUS+WallThickness,0,0]){
162                         translate([0,SHAFT_OFF_Y]) guard();
163                         translate([0,BLIND_SHAFT_OFF_Y]) guard();
164                         difference(){
165                                  cube([STRUT_THICKNESS,100,100],center=true);
166                                  translate([0,SHAFT_OFF_Y]) cube([100,2*OUTER_GUARD_RADIUS-WallThickness,100],center=true);
167                                  translate([0,BLIND_SHAFT_OFF_Y]) cube([100,2*OUTER_GUARD_RADIUS-WallThickness,100],center=true);
168                         }
169                 }
170         }
172 intersection(){
173         union(){
174                 translate([WallThickness, WallThickness, 0]) scale(v=[1-2*WallThickness/AX, 1-2*WallThickness/AY, 1-WallThickness/H]) keycap();
175                 translate([-50,-50,-99.9]) cube([100,100,100]);
176         }
177         translate([OUTER_GUARD_RADIUS+WallThickness,0,0]){
178                 translate([0,SHAFT_OFF_Y]) shaft();
179                 translate([0,BLIND_SHAFT_OFF_Y]) blind_shaft();
180         }