1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00

add rands_sphere, rands_disk

This commit is contained in:
Justin Lin
2022-04-05 11:40:16 +08:00
parent 25b61d8ded
commit 21d5638e94
2 changed files with 62 additions and 0 deletions

25
test/util/rands_disk.scad Normal file
View File

@@ -0,0 +1,25 @@
function rands_disk(radius, value_count, seed = undef) =
let(
seed_undef = is_undef(seed),
theta = seed_undef ? rands(0, 360, value_count * 2) : rands(0, 360, value_count * 2, seed),
k = seed_undef ? rands(0, 1, value_count * 2) : rands(0, 1, value_count * 2, seed)
)
[
for(i = [0:value_count - 1])
let(r = sqrt(k[i]) * radius)
[cos(theta[i]), sin(theta[i])] * r
];
/*
number = 10000;
radius = 2;
points = rand_pts_circle(radius, number);
for(p = points) {
translate(p)
circle(.01);
}
%circle(radius, $fn = 96);*/

View File

@@ -0,0 +1,37 @@
use <util/degrees.scad>;
function rands_sphere(radius, value_count, seed = undef) =
let(r_nums = is_undef(seed) ? rands(0, 1, value_count * 2) : rands(0, 1, value_count * 2, seed))
[
for(i = [0:value_count - 1])
let(
theta = degrees(2 * PI * r_nums[i]),
phi = acos(r_nums[i + value_count] * 2 - 1),
sin_phi = sin(phi),
x = sin_phi * cos(theta),
y = sin_phi * sin(theta),
z = cos(phi)
)
[x, y, z]
] * radius;
/*
use <experimental/rand_pts_sphere.scad>;
use <polyhedron_hull.scad>;
number = 20;
radius = 2;
points = rand_pts_sphere(radius, number);
polyhedron_hull(points);
for(p = points) {
translate(p)
sphere(.05);
}
%sphere(radius, $fn = 48);
*/