calculate spinner shell layer by layer
authordaniel watson <ozzloy@gmail.com>
Sat, 25 Feb 2017 09:37:09 +0000 (01:37 -0800)
committerdaniel watson <ozzloy@gmail.com>
Sat, 25 Feb 2017 09:37:09 +0000 (01:37 -0800)
spin-data.scad
spin.scad

index 0758c78b58f82f52d0c63155ac4f5b16e826723f..9a889dac4882f0771a48bf05b476c872becd2bd4 100644 (file)
@@ -2,13 +2,18 @@
    see bottom for more license info */
 
 /* spin thing that erin likes */
-$fn = 500;
+$fn = 50;
+
+layer_height = 0.15;
 
 weight = "penny";
 // weight = "608zz";
 bearing = "608zz";
-weight_lip_thickness = 1;
-wall_thickness = 2;
+weight_lip_overhang = 0.3;
+bearing_lip_overhang = weight_lip_overhang;
+// TODO: switch wall_thickness -> wall
+wall_thickness = 3;
+wall = 3;
 penny_thickness = 1.52;
 penny_radius = 19.05 / 2;
 
@@ -25,7 +30,7 @@ weight_thickness = (weight == "penny") ?
 bearing_radius = (bearing == "608zz") ? _608zz_radius : 1/0;
 bearing_inner_radius = (bearing == "608zz") ? _608zz_inner_radius : 1/0;
 bearing_cover_radius = (bearing == "608zz")
-                       ? _608zz_cover_radius + wall_thickness
+                       ? _608zz_cover_radius + wall
                        : 1/0;
 bearing_cap_footprint_radius =
      (bearing == "608zz") ? _608zz_cap_footprint_radius : 1/0;
@@ -66,105 +71,56 @@ module ring(outer_radius, inner_radius) {
     circle(outer_radius);
     circle(inner_radius); } }
 
-module spin_2d(weight_radius,
-               arms,
-               wall_thickness,
-               bearing_radius) {
-  bearing_holder_radius = bearing_radius + wall_thickness;
-  weight_holder_radius = weight_radius + wall_thickness;
-
-  ring(bearing_holder_radius, bearing_radius);
-
-  /*
-   * imagine a triangle with one point at the origin, at the
-   * center of the spinning bearing holder, one point in the middle of
-   * the weight holder, and one point at the center of a circle tangent
-   * to the first two, called the joiner circle.
-   * the radius of the joiner circle is the arithmetic average of the
-   * weight holder and bearing holder.
-   */
-  joiner_radius = (bearing_holder_radius + weight_holder_radius) / 2;
-  /* a: goes between the center of the weight holder and the center of
-     the joiner circle. */
-  a = joiner_radius + weight_holder_radius;
-  /* b: length of the base, which goes along the x-axis between
-     the origin and the center of the weight holder. */
-  b = weight_holder_radius + bearing_holder_radius;
-  /* c: goes between origin and joiner circle. */
-  c = bearing_holder_radius + joiner_radius;
-
-  /* A: angle at the origin, between the base and segment from origin
-     to center of joiner circle.
-     it is calculated using law of cosines, given the lengths of
-     all 3 sides of the triangle. */
-  A = acos((pow(b, 2) + pow(c, 2) - pow(a, 2)) / (2 * b * c));
-  /* find the center of the joiner circle */
-  joiner_x = cos(A) * c;
-  joiner_y = sin(A) * c;
-
-  /* find the points where the circles meet */
-  bearing_joiner_point = [cos(A) * bearing_holder_radius,
-                          sin(A) * bearing_holder_radius];
-  bearing_weight_point = [bearing_holder_radius, 0];
-  /* C: angle between x-axis and line-segment between center of weight
-     holder and center of joiner.
-     it is calculated using law of cosines, given the lengths of
-     all 3 sides of the triangle. */
-  C = acos((pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * a * b));
-  weight_joiner_point = [b - cos(C) * weight_holder_radius,
-                         sin(C) * weight_holder_radius];
-  for(arm = [0 : arms - 1]) {
-    rotate(arm * 360.0 / arms) {
-      difference() {
-        polygon([bearing_weight_point,
-                 bearing_joiner_point,
-                 weight_joiner_point]);
-        translate([joiner_x, joiner_y]) {
-          circle(joiner_radius); }
-        translate([weight_holder_radius + bearing_holder_radius, 0]) {
-          circle(weight_holder_radius); } }
-      mirror(v = [0, 1, 0]) {
-        difference() {
-          polygon([bearing_weight_point,
-                   bearing_joiner_point,
-                   weight_joiner_point]);
-          translate([joiner_x, joiner_y]) {
-            circle(joiner_radius); }
-        translate([weight_holder_radius + bearing_holder_radius, 0]) {
-          circle(weight_holder_radius); } } }
-      translate([weight_holder_radius + bearing_holder_radius, 0]) {
-        ring(weight_holder_radius, weight_radius); } } } }
+module fillet(r) {
+  offset(r = -r) { offset(delta = r) { children(); } } }
+
+module spin_footprint(weight_radius,
+                      bearing_radius,
+                      round_extra,
+                      wall,
+                      arms) {
+  thinner_radius = (bearing_radius < weight_radius)?
+    bearing_radius : weight_radius;
+  fillet(thinner_radius) {
+    for(arm = [0 : arms - 1]) {
+      hull() {
+        circle(bearing_radius + round_extra);
+        rotate( (arm / arms) * 360 ) {
+          translate([bearing_radius + wall + weight_radius, 0]) {
+            circle(weight_radius + round_extra); } } } } } }
+
+module mirrored(axis) {
+  children();
+  mirror(axis) children(); }
 
 module spin(weight_radius,
             weight_thickness,
-            weight_lip_thickness,
-            arms,
-            wall_thickness,
             bearing_radius,
-            bearing_thickness) {
-  /* TODO: make window size parameter */
-  /* TODO: rethink how lips are done */
-  /* TODO: right now, weight is assumed to be thicker than bearing*/
-  spinner_height = weight_thickness + 2 * weight_lip_thickness;
-  bearing_lip_thickness = (spinner_height - bearing_thickness) / 2;
-  linear_extrude(height = weight_lip_thickness) {
-    spin_2d(weight_radius - 1,
-            arms,
-            wall_thickness + 1,
-            bearing_radius - 1); }
-  linear_extrude(height = bearing_lip_thickness) {
-    ring(bearing_radius, bearing_radius - 1); }
-  linear_extrude(height = spinner_height) {
-    spin_2d(weight_radius, arms, wall_thickness, bearing_radius); }
-  translate([0, 0, spinner_height - bearing_lip_thickness]) {
-    linear_extrude(height = bearing_lip_thickness) {
-    ring(bearing_radius, bearing_radius - 1); } }
-  translate([0, 0, spinner_height - weight_lip_thickness]) {
-    linear_extrude(height = weight_lip_thickness) {
-      spin_2d(weight_radius - 1,
-              arms,
-              wall_thickness + 1,
-              bearing_radius - 1); } } }
+            bearing_thickness,
+            weight_lip_overhang = 0.3,
+            bearing_lip_overhang = 0.3,
+            wall = 3,
+            arms = 3) {
+  layer_height = 0.15;
+  thicker_thickness = (bearing_thickness > weight_thickness) ?
+    bearing_thickness : weight_thickness;
+  calculated_height = thicker_thickness + 2 * wall;
+  layers = 2 * ceil(ceil(calculated_height / layer_height) / 2);
+  actual_height = layers * layer_height;
+  round_radius = actual_height / 2;
+
+  mirrored([0, 0, 1]) {
+    for(layer = [0 : (layers / 2) - 1]) {
+      translate([0, 0, layer * layer_height - actual_height / 2]) {
+        linear_extrude(height = layer_height) {
+          adjacent = round_radius - (layer * layer_height);
+          angle = acos(adjacent / round_radius);
+          round_extra = adjacent * tan(angle);
+          spin_footprint(weight_radius,
+                         bearing_radius,
+                         round_extra,
+                         wall,
+                         arms); } } } } }
 
 /*
   This file is part of 3d-printables.
index a4b4a14a1a20e9fbac8af681a008ee9ab3aa7a98..23c61b103d9838621f9b2cac70609e5b169e7e04 100644 (file)
--- a/spin.scad
+++ b/spin.scad
@@ -9,11 +9,12 @@ object = "spin";
 if (object == "spin") {
   spin(weight_radius,
        weight_thickness,
-       weight_lip_thickness,
-       arms,
-       wall_thickness,
        bearing_radius,
-       bearing_thickness); }
+       bearing_thickness,
+       weight_lip_overhang,
+       bearing_lip_overhang,
+       wall,
+       arms); }
 else if (object == "cap") {
   cap(bearing_inner_radius,
       bearing_cap_footprint_radius,