lockpuzzle/ring.scad

83 lines
2.2 KiB
OpenSCAD

module ring(alphabet_length=26, dia=48, width=3, thick=2, spoke_depth=4.5, spoke_width=9, key_depth=3, key_length=4, tolerance = 0.2, indicator=false, clicker=false, $fn=60) {
difference() { // halfing
union() {
// outer ring
difference() {
cylinder(d=dia, h=width-4*tolerance, center=true);
cylinder(d=dia-2*thick, h=width+1, center=true);
}
// key spokes
difference() {
union() {
for (i = [0:2]) {
rotate([0,0,120*i]) {
intersection() {
translate([-dia/4,0,0]) {
cube([dia/2, spoke_width, width], center=true);
}
cylinder(d=dia, h=width-4*tolerance, center=true);
}
}
}
}
cylinder(d=dia-2*spoke_depth+tolerance, h=width+1, center=true);
}
// keys
for (i = [0:2]) {
rotate([0,0,120*i]) {
translate([-dia/2+spoke_depth+key_depth/2-1,0,0]) {
cube([key_depth+2, key_length, width-4*tolerance], center=true);
}
}
}
// indicator
translate([-dia/2,0,0]) {
cube([2, width, width-4*tolerance], center=true);
}
// clicker
if (clicker) {
echo(floor(alphabet_length/3)*360/alphabet_length-45);
rotate([0,0,floor(alphabet_length/3)*360/alphabet_length-45]) {
translate([-dia/2+3,0,0]) {
cube([3, 4, width-4*tolerance], center=true);
}
translate([-dia/2+3.5,0,width/2-0.5]) {
scale([0.5,1,1]) {
rotate([0,0,45]) {
cylinder($fn=4, h=1, d1=5.6, d2=3);
}
}
}
}
}
}
// Ring cut
translate([-dia/2-0.2, -0.25, -width/2]) {
cube([spoke_depth+key_depth+thick,0.25, width]);
}
translate([-dia/2-0.2, 0, -width/2]) {
#cube([0.25, width/2, width]);
}
}
}
// DEFAULTS FOR COMMAND LINE INVOCATION
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
DIAMETER = 50;
TOLERANCE = 0.2;
FN = 60;
INDICATOR = false;
CLICKER = false;
ring(
alphabet_length=len(ALPHABET),
dia=DIAMETER-2,
indicator=INDICATOR,
clicker=CLICKER,
tolerance=TOLERANCE, $fn=FN);