/ key_mold.scad
key_mold.scad
  1  
  2  include <keys.scad>
  3  
  4  platform_width = 30;
  5  platform_height = 4;
  6  // height difference between bottom and top of platform
  7  platform_slant = 3;
  8  
  9  minimum_height = 12;
 10  
 11  //minimum mold thickness
 12  extra = 9;
 13  
 14  //thicknesses of the mold
 15  side_thickness = 2;
 16  bottom_thickness = 2;
 17  
 18  
 19  // computed variables
 20  inner_side = platform_width + extra * 2;
 21  total_side = inner_side + side_thickness * 2;
 22  
 23  
 24  // minimum_height of bottom, non-flared box
 25  bottom_box_height = 5 + bottom_thickness;
 26  
 27  function hypo(num) = sqrt(pow(num,2) / 2);
 28  
 29  
 30  module bottom_box() {
 31    difference(){
 32      //outer box
 33      cube([total_side, total_side, bottom_box_height]);
 34  
 35      //inner box
 36      translate([ side_thickness, side_thickness, bottom_thickness]) {
 37        cube([inner_side, inner_side, bottom_box_height - bottom_thickness + .02]);
 38      }
 39    }
 40  }
 41  
 42  module slanted_box() {
 43    translate([total_side / 2, total_side / 2, bottom_box_height]) rotate([0,0,45]) difference(){
 44      //outer box
 45      cylinder(
 46        h = minimum_height + extra - bottom_box_height + platform_height,
 47        r1 = hypo(total_side),
 48        r2 = hypo(total_side + 3),
 49        $fn=4
 50      );
 51  
 52      //inner box
 53      translate([0,0,-0.01]) cylinder(
 54        minimum_height + extra - bottom_box_height + .02 + platform_height,
 55        hypo(inner_side),
 56        hypo(inner_side + 3),
 57        $fn=4
 58      );
 59    }
 60  }
 61  
 62  module platform() {
 63    //platform
 64    /* translate([
 65      side_thickness + extra,
 66      side_thickness + extra,
 67      bottom_thickness
 68    ]) cube([platform_width, platform_width, platform_height]); */
 69  
 70    translate([
 71      side_thickness + extra + platform_width/2,
 72      side_thickness + extra + platform_width/2,
 73      bottom_thickness
 74    ]) rotate([0,0,45]) cylinder(r1=hypo(platform_width), r2=hypo(platform_width) - platform_slant, h=platform_height, $fn=4);
 75  }
 76  
 77  module registration() {
 78    positions = [
 79      [// bottom left
 80        side_thickness + extra / 2 + 1,
 81        side_thickness + extra / 2 + 1,
 82        bottom_thickness
 83      ],
 84      [// top left
 85        side_thickness +  extra / 2 + 1,
 86        side_thickness + platform_width + extra * 1.5 - 1,
 87        bottom_thickness
 88      ],
 89      [// bottom right
 90        side_thickness + platform_width + extra * 1.5 - 1,
 91        side_thickness +  extra / 2 + 1,
 92        bottom_thickness
 93      ],
 94      [// top right
 95        side_thickness + platform_width + extra * 1.5 - 1,
 96        side_thickness + platform_width + extra * 1.5 - 1,
 97        bottom_thickness
 98      ]
 99    ];
100  
101    for (index = [0:len(positions)-1]) {
102      position = positions[index];
103      translate(position) {
104        // dont mind the math
105        rotate([0,0,45 / (index % 2 * 0.5 + 1)]) {
106          cylinder(platform_height / 2,extra/3, 2, $fn=(index % 2 * 2 + 4));
107        }
108      }
109    }
110  }
111  
112  module key_for_mold(wall_thickness = 20) {
113    translate([
114      total_side / 2,
115      total_side / 2,
116      platform_height + bottom_thickness
117    ]) {
118      $wall_thickness = wall_thickness;
119      $support_type = false;
120      sa_row(1) key();
121    }
122  }
123  
124  module bottom_mold(){
125    bottom_box();
126    slanted_box();
127    platform();
128    registration();
129    /* key_for_mold(); */
130  }
131  
132  module top_mold(){
133    difference(){
134      //outer box
135      cube([
136        total_side,
137        total_side,
138        minimum_height + extra + bottom_thickness,
139      ]);
140  
141      //inner box
142      translate([
143        side_thickness,
144        side_thickness,
145        0
146      ]) {
147        cube([
148          inner_side,
149          inner_side,
150          minimum_height + extra + bottom_thickness,
151        ]);
152      }
153    }
154  }
155  
156  // for calculating how much mold material to use!
157  module difference_box() {
158    scale(.99) union() {
159      cube([total_side, total_side, bottom_box_height + bottom_thickness]);
160      translate([total_side / 2, total_side / 2, bottom_box_height + bottom_thickness]) rotate([0,0,45]){
161        //outer box
162        cylinder(
163          minimum_height + extra - bottom_box_height,
164          hypo(total_side),
165          hypo(total_side + 3),
166          $fn=4
167        );
168      }
169    }
170  }
171  
172  difference() {
173    /* difference_box(); */
174  
175    /* bottom_mold(); */
176  }
177  
178  /* key_for_mold(0); */
179  
180  translate([0,0,0]) top_mold();