Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lego Cherry MX Keycap
// dimensions Cherry MX connector
var c_corr = 0.4 // tolerance
var c_horiz = 1.1 // horizontal bar width
var c_vert = 1.0 // vertical bar width
var c_dia = 4 // cross width
var c_depth = 7 // connector depth
var c_space = 7 // height of hollow inside
var c_inset = 0.75 // distance connector start to keycap base
// stuff
var $fn = 64
function connector() {
return difference(
support(),
plus()
).translate([0, 0, 0])
}
function plus() {
return union(
cube({ size: [c_vert+c_corr, c_dia+c_corr, c_depth-3], center: true }),
cube({ size: [c_dia+c_corr, c_horiz+c_corr, c_depth-3], center: true })
).translate([0, 0, (c_depth-3)/2])
}
function support() {
var width = top_y-2
var depth = c_dia+c_corr
return cube({ size: [width, depth-1, c_space+c_corr] })
.subtract([
rotate([0, 50, 0],
cube({size: [depth+5, depth, depth]})
).translate([-5, 0, 4]),
mirror([1, 0, 0], rotate([0, 50, 0],
cube({size: [depth+5, depth, depth]})
).translate([-19, 0, 4]))
])
.translate([-width/2, -(depth-1)/2, 0])
}
var base_w = 18
var top_y = 16
var dx = 2 // top sides are pushed to center
var dy = 1 // top is pushed back this far
var z_front = 6+2 // height at front edge
var z_back = 6+2 // height at back edge
var angle = Math.atan((z_front-z_back) / top_y)
/*
______
/7 6/|
/4___5/ |
| |___|_|
| /3 |2/
|/0___1|/
*/
function shell() {
return polyhedron({
points: [
[ 0, 0, 0 ],
[ base_w, 0, 0 ],
[ base_w, base_w, 0 ],
[ 0, base_w, 0 ],
[ dx, dy, z_front ],
[ base_w-dx, dy, z_front ],
[ base_w-dx, dy+top_y, z_back ],
[ dx, dy+top_y, z_back ]
],
triangles: [
[0,5,1], [0,4,5],
[1,6,2], [1,5,6],
[2,7,3], [2,6,7],
[3,4,0], [3,7,4],
[4,6,5], [4,7,6],
[0,1,3], [1,2,3]
]
}).translate([-base_w/2, -base_w/2, 0])
}
var FLU = 1.6 // Fundamental Lego Unit = 1.6 mm
var brick_width = 5*FLU
var brick_half = 2.5*FLU
var brick_height = 6*FLU
var wall_thickness = FLU
var stud_radius = 1.5 * FLU
var stud_height = FLU
var correction = 0.1
function stud() {
return cylinder({ h: stud_height + correction, r: stud_radius })
}
function studs() {
return union(
stud().translate([brick_half, brick_half, -correction]),
stud().translate([brick_half, -brick_half, -correction]),
stud().translate([-brick_half, brick_half, -correction]),
stud().translate([-brick_half, -brick_half, -correction])
)
}
function cap() {
return difference(
shell(),
shell().scale(0.88)
)
}
function main() {
return [
cap(),
connector(),
studs().translate([0, 0, z_front])
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment