kogan_sphere.scad
1 /* 2 A New Computationally Efficient Method for Spacing n Points on a Sphere 3 Jonathan Kogan 4 https://www.youtube.com/watch?v=c-6DV4ZyCdo 5 */ 6 function kogan_sphere(n, radius = 1, dir = "CT_CLK") = 7 let( 8 HALF_PI = PI / 2, 9 toDegrees = 180 / PI, 10 clk = dir == "CT_CLK" ? 1 : -1, 11 az_unit = (0.1 + 1.2 * n) * clk, 12 n_1 = n - 1, 13 step = 2 / n_1 - 2 / (n_1 ^ 2), 14 from = -1 + 1 / n_1, 15 to = from + n_1 * step 16 ) 17 [ 18 for(sf = [from:step:to]) 19 let( 20 ay = HALF_PI * sign(sf) * (1 - sqrt(1 - abs(sf))) * toDegrees, 21 az = (sf * az_unit) * toDegrees 22 ) 23 radius * [ 24 cos(az) * cos(ay), 25 sin(az) * cos(ay), 26 sin(ay) 27 ] 28 ];