1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-22 14:23:23 +02:00

extract fast fib

This commit is contained in:
Justin Lin
2019-10-03 15:06:55 +08:00
parent 9556f60050
commit 7e71667694
2 changed files with 19 additions and 2 deletions

View File

@@ -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];

View File

@@ -8,6 +8,8 @@
* *
**/ **/
include <__comm__/__fast_fibonacci.scad>;
function _fast_fibonacci_sub(nth) = function _fast_fibonacci_sub(nth) =
let( let(
_f = _fast_fibonacci_2_elems(floor(nth / 2)), _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) = function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) =
let( let(
f1 = _fast_fibonacci(from), f1 = __fast_fibonacci(from),
f2 = _fast_fibonacci(from + 1), f2 = __fast_fibonacci(from + 1),
fn = floor(f1 * 6.28312 / point_distance), fn = floor(f1 * 6.28312 / point_distance),
$fn = fn + 4 - (fn % 4), $fn = fn + 4 - (fn % 4),
circle_pts = circle_path(radius = f1, n = $fn / 4 + 1), circle_pts = circle_path(radius = f1, n = $fn / 4 + 1),