From 9829c5c20148e97de1f6f38543bbb5f08cbfebc6 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 16 Aug 2021 18:22:02 +0800 Subject: [PATCH] add kogan_sphere --- src/experimental/kogan_sphere.scad | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/experimental/kogan_sphere.scad diff --git a/src/experimental/kogan_sphere.scad b/src/experimental/kogan_sphere.scad new file mode 100644 index 00000000..14411a74 --- /dev/null +++ b/src/experimental/kogan_sphere.scad @@ -0,0 +1,28 @@ +/* + A New Computationally Efficient Method for Spacing n Points on a Sphere + Jonathan Kogan + https://www.youtube.com/watch?v=c-6DV4ZyCdo +*/ +function kogan_sphere(n, radius = 1, dir = "CT_CLK") = + let( + HALF_PI = PI / 2, + toDegrees = 180 / PI, + clk = dir == "CT_CLK" ? 1 : -1, + az_unit = (0.1 + 1.2 * n) * clk, + n_1 = n - 1, + step = 2 / n_1 - 2 / (n_1 ^ 2), + from = -1 + 1 / n_1, + to = from + n_1 * step + ) + [ + for(sf = [from:step:to]) + let( + ay = HALF_PI * sign(sf) * (1 - sqrt(1 - abs(sf))) * toDegrees, + az = (sf * az_unit) * toDegrees + ) + radius * [ + cos(az) * cos(ay), + sin(az) * cos(ay), + sin(ay) + ] + ]; \ No newline at end of file