2 /* All distances are in mm. */
4 /* set output quality */
7 /* Distance between key centers. */
9 row_spacing = column_spacing;
11 /* This number should exceed row_spacing and column_spacing. The
12 default gives a 1mm = (20mm - 19mm) gap between keycaps and cuts in
16 /* rotation angle; the angle between the halves is twice this
20 /* The radius of screw holes. Holes will be slightly bigger due
22 screw_hole_radius = 1.5;
23 /* Each screw hole is a hole in a "washer". How big these "washers"
24 should be depends on the material used: this parameter and the
25 `switch_hole_size` determine the spacer wall thickness. */
26 washer_radius = 4 * screw_hole_radius;
28 /* This constant allows tweaking the location of the screw holes near
29 the USB cable. Only useful with small `angle` values. Try the value
30 of 10 with angle=0. */
31 back_screw_hole_offset = 0;
33 /* Distance between halves. */
36 /* The approximate size of switch holes. Used to determine how
37 thick walls can be, i.e. how much room around each switch hole to
38 leave. See spacer(). */
39 switch_hole_size = 14;
41 /* Sets whether the case should use notched holes. As far as I can
42 tell these notches are not all that useful... */
43 use_notched_holes = true;
45 /* Number of rows and columns in the matrix. You need to update
46 staggering_offsets if you change n_cols. */
50 /* Number of thumb keys (per hand), try 1 or 2. */
53 /* The width of the USB cable hole in the spacer. */
54 cable_hole_width = 12;
56 /* Vertical column staggering offsets. The first element should
58 staggering_offsets = [0, 5, 11, 6, 3];
60 /* Whether or not to split the spacer into quarters. */
61 quarter_spacer = false;
63 /* Where the top/bottom split of a quartered spacer will be. */
64 spacer_quartering_offset = 60;
66 module rz(angle, center=undef) {
67 /* Rotate children `angle` degrees around `center`. */
71 for (i=[0:$children-1])
78 /* Compute coordinates of a point obtained by rotating p angle degrees
79 around center. Used to compute locations of screw holes near the
81 function rz_fun(p, angle, center) = [cos(angle) * (p[0] - center[0]) - sin(angle) * (p[1] - center[1]) + center[0],
82 sin(angle) * (p[0] - center[0]) + cos(angle) * (p[1] - center[1])+ center[1]];
84 module switch_hole(position, notches=use_notched_holes) {
85 /* Cherry MX switch hole with the center at `position`. Sizes come
86 from the ErgoDox design. */
89 notch_offset = 4.2545;
93 square([hole_size, hole_size], center=true);
94 if (notches == true) {
95 translate([0, notch_offset]) {
96 square([hole_size+2*notch_depth, notch_width], center=true);
98 translate([0, -notch_offset]) {
99 square([hole_size+2*notch_depth, notch_width], center=true);
106 module regular_key(position, size) {
107 /* Create a hole for a regular key. */
108 translate(position) {
109 square([size, size], center=true);
113 module thumb_key(position, size) {
114 /* Create a hole for a 1x1.5 unit thumb key. */
115 translate(position) {
117 translate(-position) {
118 regular_key(position, size);
124 module column (bottom_position, switch_holes, key_size=key_hole_size) {
125 /* Create a column of keys. */
126 translate(bottom_position) {
127 for (i = [0:(n_rows-1)]) {
128 if (switch_holes == true) {
129 switch_hole([0, i*column_spacing]);
131 regular_key([0, i*column_spacing], key_size);
137 module rotate_half() {
138 /* Rotate the right half of the keys around the top left corner of
139 the thumb key. Assumes that the thumb key is a 1x1.5 key and that
140 it is shifted 0.5*column_spacing up relative to the nearest column. */
141 rotation_y_offset = 1.75 * column_spacing;
142 for (i=[0:$children-1]) {
143 rz(angle, [hand_separation, rotation_y_offset]) {
149 module add_hand_separation() {
150 /* Shift everything right to get desired hand separation. */
151 for (i=[0:$children-1]) {
152 translate([0.5*hand_separation, /* we get back the full separation
153 because of mirroring */
158 module right_half (switch_holes=true, key_size=key_hole_size) {
159 /* Create switch holes or key holes for the right half of the
160 keyboard. Different key_sizes are used in top_plate() and
162 x_offset = 0.5 * row_spacing;
163 y_offset = 0.5 * column_spacing;
164 thumb_key_offset = y_offset + 0.5 * column_spacing;
166 add_hand_separation() {
167 for (j=[0:(n_thumb_keys-1)]) {
168 if (switch_holes == true) {
169 switch_hole([x_offset + j*row_spacing, thumb_key_offset]);
171 thumb_key([x_offset + j*row_spacing, thumb_key_offset], key_size);
174 for (j=[0:(n_cols-1)]) {
175 column([x_offset + (j+n_thumb_keys)*row_spacing, y_offset + staggering_offsets[j]], switch_holes, key_size);
181 module screw_hole(radius, offset_radius, position, direction) {
182 /* Create a screw hole of radius `radius` at a location
183 `offset_radius` from `position`, (diagonally), in the direction
184 `direction`. Oh, what a mess this is. */
185 /* direction is the 2-element vector specifying to which side of
186 position to move to, [-1, -1] for bottom left, etc. */
188 /* radius_offset is the offset in the x (or y) direction so that
189 we're offset_radius from position */
190 radius_offset = offset_radius / sqrt(2);
191 /* key_hole_offset if the difference between key spacing and key
193 key_hole_offset = 0.5*(row_spacing - key_hole_size);
194 x = position[0] + (radius_offset - key_hole_offset) * direction[0];
195 y = position[1] + (radius_offset - key_hole_offset) * direction[1];
201 module right_screw_holes(hole_radius) {
202 /* coordinates of the back right screw hole before rotation... */
203 back_right = [(n_cols+n_thumb_keys)*row_spacing,
204 staggering_offsets[n_cols-1] + n_rows * column_spacing];
206 tmp = rz_fun(back_right, angle, [0, 2.25*column_spacing]);
211 add_hand_separation() {
212 screw_hole(hole_radius, washer_radius,
215 screw_hole(hole_radius, washer_radius,
216 [(n_cols+n_thumb_keys)*row_spacing, staggering_offsets[n_cols-1]],
218 screw_hole(hole_radius, washer_radius,
224 /* add the screw hole near the cable hole */
225 translate([washer_radius - tmp[0],
226 back_screw_hole_offset]) {
228 add_hand_separation() {
229 screw_hole(hole_radius,
238 module screw_holes(hole_radius) {
239 /* Create all the screw holes. */
240 right_screw_holes(hole_radius);
241 mirror ([1,0,0]) { right_screw_holes(hole_radius); }
244 module left_half(switch_holes=true, key_size=key_hole_size) {
245 mirror ([1,0,0]) { right_half(switch_holes, key_size); }
248 module bottom_plate() {
249 /* bottom layer of the case */
251 hull() { screw_holes(washer_radius); }
252 screw_holes(screw_hole_radius);
257 /* top layer of the case */
265 module switch_plate() {
266 /* the switch plate */
275 /* Create a spacer. */
281 right_half(switch_holes=false, key_size=switch_hole_size + 3);
282 left_half(switch_holes=false, key_size=switch_hole_size + 3);
284 /* add the USB cable hole: */
285 translate([-0.5*cable_hole_width, 2*column_spacing]) {
286 square([cable_hole_width, (2*n_rows) * column_spacing]);
289 screw_holes(washer_radius);
291 screw_holes(screw_hole_radius);
295 module spacer_quadrant(spacer_quadrant_number) {
296 /* Cut a quarter of a spacer. */
297 translate([0, spacer_quartering_offset]) {
299 translate([0, -spacer_quartering_offset]) { spacer(); }
300 rotate([0, 0, spacer_quadrant_number * 90]) { square([1000, 1000]); }
305 module quartered_spacer()
307 /* Assemble all four quarters of a spacer. */
310 translate([-5,-10]) spacer_quadrant(2);
311 translate([5,-10]) spacer_quadrant(3);
314 /* Create all four layers. */
316 translate([300, 0]) { switch_plate(); }
317 translate([0, 150]) { bottom_plate(); }
318 translate([300, 150]) {
319 if (quarter_spacer == true) {