calculate spinner shell layer by layer
[ozzloy@gmail.com/3d-printables] / spin-data.scad
index ae9c89e198d22bbcb5d470a78d66a5ee231bb044..9a889dac4882f0771a48bf05b476c872becd2bd4 100644 (file)
 /* spin thing that erin likes */
 $fn = 50;
 
+layer_height = 0.15;
+
 weight = "penny";
 // weight = "608zz";
-wall_thickness = 2;
-_608zz_radius = 22;
-penny_radius = 19.05 / 2;
+bearing = "608zz";
+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;
+
+_608zz_radius = 22 / 2;
+_608zz_inner_radius = 8.1 / 2;
+_608zz_cover_radius = 19.4 / 2;
+_608zz_cap_footprint_radius = 12 / 2;
+_608zz_thickness = 7;
+
 weight_radius = (weight == "penny") ? penny_radius : _608zz_radius;
+weight_thickness = (weight == "penny") ?
+     penny_thickness * 5 : _608zz_thickness;
+
+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
+                       : 1/0;
+bearing_cap_footprint_radius =
+     (bearing == "608zz") ? _608zz_cap_footprint_radius : 1/0;
+bearing_thickness = (bearing == "608zz") ? _608zz_thickness : 1/0;
+
+spinner_height = penny_thickness * 5 + 2;
 arms = 3;
 
-module spin(weight_radius, arms, wall_thickness) {
-  _608zz_holder_radius = _608zz_radius + wall_thickness;
-  circle(_608zz_holder_radius);
-  weight_holder_radius = weight_radius + wall_thickness;
-  for(arm = [0 : arms - 1]) {
-    rotate(arm * 360.0 / arms) {
-      translate([weight_holder_radius + _608zz_holder_radius, 0]) {
-        circle(weight_holder_radius); } } } }
+module cap(bearing_inner_radius,
+           bearing_cap_footprint_radius,
+           bearing_cover_radius,
+           bearing_thickness) {
+  footprint_height = 1.6;
+  footprint_radius_safety = 0.25;
+  cap_height = 3;
+  bearing_cover_radius_safety = 0.75;
+  bearing_thickness_safety = 0.2;
+
+  difference() {
+    union() {
+      cylinder(r1 = bearing_cover_radius - tan(30) * cap_height,
+               r2 = bearing_cover_radius,
+               h = cap_height);
+      linear_extrude(height = cap_height + footprint_height) {
+        circle(bearing_cap_footprint_radius - footprint_radius_safety); }
+      linear_extrude(height = cap_height
+                              + footprint_height
+                              + bearing_thickness / 2
+                              - bearing_thickness_safety) {
+        circle(bearing_inner_radius); } }
+    translate([0, 0, -0.01]) {
+      cylinder(r1 = bearing_inner_radius + tan(30) * (cap_height - 1),
+               r2 = bearing_inner_radius,
+               h = cap_height - 1); } } }
+
+module ring(outer_radius, inner_radius) {
+  difference() {
+    circle(outer_radius);
+    circle(inner_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,
+            bearing_radius,
+            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.