2 * Draw a support to tie Tetramag spheres to a bike wheel.
4 * Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
5 * SPDX-License-Identifier: GPL-3.0-or-later
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Using a formula from:
23 * https://math.stackexchange.com/questions/12166/numbers-of-circles-around-a-circle
26 function calc_inner_radius(sphere_radius, number_of_spheres) = (
27 let(ratio = sin(180 / number_of_spheres) / (1 - sin(180 / number_of_spheres)))
31 module draw_spheres(sphere_radius, number_of_spheres) {
32 if (sphere_radius <= 0) {
33 echo("Radius of outer spheres cannot be zero");
36 if (number_of_spheres < 3) {
37 echo("Number of outer spheres cannot be smaller than 3");
40 inner_radius = calc_inner_radius(sphere_radius, number_of_spheres);
42 for (i = [0:number_of_spheres]) {
43 theta = i * 360 / number_of_spheres;
46 cx = sin(theta) * (inner_radius + sphere_radius);
47 cy = cos(theta) * (inner_radius + sphere_radius);
48 translate([cx, cy, 0]) {
49 sphere(sphere_radius, $fn=2);
53 /* A better version which also rotates the objects radially. */
54 rotate ([0, 0, theta]) {
55 translate([0, inner_radius + sphere_radius, 0]) {
56 sphere(sphere_radius, $fn=40);
62 module draw_cylinder(sphere_radius, number_of_spheres) {
63 radius = calc_inner_radius(sphere_radius, number_of_spheres) + sphere_radius / 2;
64 cylinder(sphere_radius * 2, r = radius, center=true, $fn=100);
67 module draw_mounting_holes(hole_radius) {
68 /* 9 is the number of the bike spokes to attach the holder to. */
73 for (i = [0:mounting_holes]) {
74 theta = i * 360 / mounting_holes;
75 rotate ([0, 0, theta]) {
76 translate([-cube_spacing, hole_radius + cube_size, 0]) {
77 cube([cube_size, cube_size, cube_size * 10], true);
78 }translate([cube_spacing, hole_radius + cube_size, 0]) {
79 cube([cube_size, cube_size, cube_size * 10], true);
86 module draw_holes(height, hole_radius) {
87 cylinder(height, r = hole_radius, center=true, $fn=100);
92 draw_mounting_holes(hole_radius);
95 /* The actual parameters */
97 number_of_spheres = 38;
98 hole_radius = 47 / 2; // 47mm is the hole diameter
101 draw_cylinder(sphere_radius, number_of_spheres);
102 draw_spheres(sphere_radius, number_of_spheres);
103 draw_holes(sphere_radius * 3, hole_radius);