1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-09 00:06:42 +02:00
This commit is contained in:
Justin Lin
2022-03-12 18:31:09 +08:00
parent 987bc3be5b
commit 57914a8245

View File

@@ -8,20 +8,20 @@
* *
**/ **/
use <util/degrees.scad>;
function fibonacci_lattice(n, radius = 1, dir = "CT_CLK") = function fibonacci_lattice(n, radius = 1, dir = "CT_CLK") =
let( let(
toDegrees = 180 / PI,
phi = PI * (3 - sqrt(5)), phi = PI * (3 - sqrt(5)),
clk = dir == "CT_CLK" ? 1 : -1 clk = dir == "CT_CLK" ? 1 : -1
) )
[ [
for(i = [0:n - 1]) for(i = [0:n - 1])
let( let(
z = 1 - (2* i + 1) / n, z = 1 - (2 * i + 1) / n,
r = sqrt(1 - z * z), r = sqrt(1 - z ^ 2),
theta = phi * i * clk, theta = phi * i * clk,
x = cos(theta * toDegrees) * r, deg = degrees(theta)
y = sin(theta * toDegrees) * r
) )
[x, y, z] * radius [cos(deg) * r, sin(deg) * r, z] * radius
]; ];