diff --git a/README.md b/README.md index 8378399..7681626 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # keygen -OpenSCAD tools for generating physical keys +Tools for generating physical keys. + +![152698](doc/key.png "Key in OpenSCAD") + +## How it Works +1. Get some nice pictures of the side and tip of your key. +I recommend a flatbed scanner. +2. Trace the key outline, warding, and embossing in Inkscape +3. Use the provided Inkscape plugin to convert the paths to OpenSCAD polygons. +4. Look up online the various parameters of your key, such as plug diameter, +cut depths and locations. +5. Use the provided OpenSCAD functions `key_code_to_heights`, +`key_blank` and `key_bitting` to generate a 3D model of your key. +6. Send the key to be 3D printed. diff --git a/doc/key.png b/doc/key.png new file mode 100644 index 0000000..ab7716d Binary files /dev/null and b/doc/key.png differ diff --git a/keygen.scad b/keygen.scad index b88c827..5b11fe5 100644 --- a/keygen.scad +++ b/keygen.scad @@ -129,4 +129,33 @@ module key_blank(outline_points, key_emboss(emboss_right_adj, emboss_depth, false, thickness, emboss_right_paths); key_emboss(emboss_left_adj, emboss_depth, true, thickness, emboss_left_paths); } +} + +function key_code_to_heights(code, depth_table) = [for(i=[0:len(code)-1]) depth_table[search(code[i], "0123456789")[0]]]; + +module key_bitting_cutter(flat, angle, tool_height) { + polygon([[-0.5 * flat, 0], + [0.5 * flat, 0], + [0.5 * flat + tan(0.5 * angle) * tool_height, tool_height], + [0.5 * flat - tan(0.5 * angle) * tool_height, tool_height]]); +} + +module key_bitting(heights, + locations, + flat, + angle=100, + cutter_width=5, + cutter_height=5) { + // Rotate the cutting tool to the proper orientation + rotate(-90, [0, 0, 1]) rotate(90, [1, 0, 0]) + // Union together a handful of trapezoids + // that comprise the cuts + union() { + for(i=[0:len(heights)-1]) { + // Move to the proper location and height + translate([locations[i], heights[i]]) + linear_extrude(height=cutter_width, center=true) + key_bitting_cutter(flat, angle, cutter_height); + } + } } \ No newline at end of file diff --git a/sc4.scad b/sc4.scad index 8f6140c..2b190e5 100644 --- a/sc4.scad +++ b/sc4.scad @@ -1,11 +1,22 @@ use include -key_blank(outline_points, - warding_points, - outline_paths=outline_paths, - emboss_right_points=emboss_points, - emboss_right_paths=emboss_paths, - emboss_left_points=emboss_points, - emboss_left_paths=emboss_paths, - offset=-outline_points[187]); +bitting_code = "024689"; + +cut_locations = [for(i=[.231, .3872, .5434, .6996, .8558, 1.012]) i*25.4]; +depth_table = [for(i=[0.335:-0.015:0.199]) i*25.4]; + +heights = key_code_to_heights(bitting_code, depth_table); + +difference() { + key_blank(outline_points, + warding_points, + outline_paths=outline_paths, + emboss_right_points=emboss_points, + emboss_right_paths=emboss_paths, + emboss_left_points=emboss_points, + emboss_left_paths=emboss_paths, + offset=-outline_points[187], + plug_diameter=12.7); + key_bitting(heights, cut_locations, .7874); +} \ No newline at end of file