diff --git a/src/__comm__/__fast_fibonacci.scad b/src/__comm__/__fast_fibonacci.scad new file mode 100644 index 00000000..61ec0071 --- /dev/null +++ b/src/__comm__/__fast_fibonacci.scad @@ -0,0 +1,15 @@ +function __fast_fibonacci_sub(nth) = + let( + _f = __fast_fibonacci_2_elems(floor(nth / 2)), + a = _f[0], + b = _f[1], + c = a * (b * 2 - a), + d = a * a + b * b + ) + nth % 2 == 0 ? [c, d] : [d, c + d]; + +function __fast_fibonacci_2_elems(nth) = + nth == 0 ? [0, 1] : __fast_fibonacci_sub(nth); + +function __fast_fibonacci(nth) = + __fast_fibonacci_2_elems(nth)[0]; \ No newline at end of file diff --git a/src/golden_spiral.scad b/src/golden_spiral.scad index 28aa20cc..2b8ac5dd 100644 --- a/src/golden_spiral.scad +++ b/src/golden_spiral.scad @@ -8,6 +8,8 @@ * **/ +include <__comm__/__fast_fibonacci.scad>; + function _fast_fibonacci_sub(nth) = let( _f = _fast_fibonacci_2_elems(floor(nth / 2)), @@ -31,8 +33,8 @@ function _remove_same_pts(pts1, pts2) = function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) = let( - f1 = _fast_fibonacci(from), - f2 = _fast_fibonacci(from + 1), + f1 = __fast_fibonacci(from), + f2 = __fast_fibonacci(from + 1), fn = floor(f1 * 6.28312 / point_distance), $fn = fn + 4 - (fn % 4), circle_pts = circle_path(radius = f1, n = $fn / 4 + 1),