1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00
dotSCAD/examples/spiral/spiral_math_constants.scad

57 lines
1.5 KiB
OpenSCAD
Raw Normal View History

2022-06-06 13:11:46 +08:00
use <fibonacci_lattice.scad>
use <polyline_join.scad>
use <polyhedron_hull.scad>
2020-12-15 11:33:16 +08:00
n = 150;
radius = 12;
constants = [
"π3.141592653589793238462643383279502884197169399375105820974944592307816406286",
"τ6.2831853071795864769252867665590057683943387987502116419498891846156328",
"φ1.6180339887498948482045868343656381177203091798057628621354486227052604",
"e2.7182818284590452353602874713526624977572470936999595749669676277240766303535"
];
font_name = "Arial Black";
font_size = 2.5;
txt_extrude = radius * 0.5;
txt_scale = 1.5;
2020-12-16 11:04:07 +08:00
spiral_math_constants(n, radius, constants, font_name, font_size, txt_extrude, txt_scale);
2020-12-15 11:33:16 +08:00
2020-12-16 11:04:07 +08:00
module spiral_math_constants(n, radius, constants, font_name, font_size, txt_extrude, txt_scale) {
2020-12-15 11:33:16 +08:00
pts = fibonacci_lattice(n, radius);
polyhedron_hull(pts * 0.9);
2020-12-15 11:57:48 +08:00
spirals = [for(j = [0:7])
2020-12-15 11:33:16 +08:00
[for(i = j; i < len(pts); i = i + 8) pts[i]]
];
module constant_on_spiral(constant, spiral) {
for(i = [0:len(spiral) - 1]) {
2022-04-04 18:58:32 +08:00
x = spiral[i].x;
y = spiral[i].y;
z = spiral[i].z;
2020-12-15 11:33:16 +08:00
ya = atan2(z, sqrt(x * x + y * y));
za = atan2(y, x);
render()
translate(spiral[i])
rotate([0, -ya, za])
rotate([90, 0, -90])
linear_extrude(txt_extrude, scale = txt_scale)
mirror([-1, 0, 0])
text(constant[i], size = font_size, font = font_name, valign = "center", halign = "center");
}
}
2020-12-15 11:57:48 +08:00
for(i = [0:2:6]) {
2020-12-15 11:33:16 +08:00
constant_on_spiral(constants[i / 2], spirals[i + 1]);
}
2020-12-15 11:57:48 +08:00
for(i = [0:2:6]) {
2021-10-08 09:36:01 +08:00
polyline_join(spirals[i] * 0.9)
sphere(.5, $fn = 4);
2020-12-15 11:33:16 +08:00
}
}