+module spin_cosine(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;
+
+ /* rounding the outside edge of the spinner with a semi-circle leads
+ to a shape that an overhang on the second layer several times the
+ thickness of a printed extrusion width.
+
+ rather than using a full semi-circle, this code aims to use just the
+ portion in the middle, where the overhang is less severe */
+ old_start = 0;
+ old_end = (layers / 2) - 1;
+
+ /* add one to have some thickness all around weight holes
+ for first layer */
+ new_start = old_end / 16 + 1;
+ new_end = old_end;
+
+ old_range = old_end - old_start;
+ new_range = new_end - new_start;
+
+ factor = new_range / old_range;
+
+ /* initial adjacent is adjusted to (new start - 1) to allow some
+ thickness all around weight holes on first layer */
+ initial_adjacent = round_radius - ((new_start - 1) * layer_height);
+ initial_angle = acos(initial_adjacent / round_radius);
+ initial_round_extra = initial_adjacent * tan(initial_angle);
+
+ difference() {
+ mirrored([0, 0, 1]) {
+ for(layer = [0 : (layers / 2) - 1]) {
+ translate([0, 0, layer * layer_height - actual_height / 2]) {
+ linear_extrude(height = layer_height) {
+ new_layer = (layer - old_start) * factor + new_start;
+ adjacent = round_radius - (new_layer * layer_height);
+ angle = acos(adjacent / round_radius);
+ round_extra = adjacent * tan(angle) - initial_round_extra;
+ spin_cosine_slice(weight_radius,
+ bearing_radius,
+ round_extra,
+ wall,
+ arms); } } } }
+ cylinder(h = actual_height + 0.1,
+ r = bearing_radius - bearing_lip_overhang,
+ center = true);
+ cylinder(h = bearing_thickness + 0.05,
+ r = bearing_radius + 0.15,
+ center = true);
+ for(arm = [0 : arms - 1]) {
+ rotate(arm * (360 / arms)) {
+ translate([bearing_radius + wall + weight_radius, 0]) {
+ cylinder(h = actual_height + 0.1,
+ r = weight_radius - weight_lip_overhang,
+ center = true);
+ cylinder(h = weight_thickness + 0.05,
+ r = weight_radius + 0.15,
+ center = true); } } } } }
+