1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-16 21:58:26 +01:00

add circle_packing2

This commit is contained in:
Justin Lin 2022-05-31 15:50:45 +08:00
parent 6affac09a7
commit 89790d50ae

View File

@ -0,0 +1,34 @@
use <experimental/tri_subdivide.scad>;
use <triangle/tri_delaunay.scad>;
use <triangle/tri_incenter.scad>;
function circle_packing2(points, density = 1) =
[
for(t = tri_delaunay(points, ret = "TRI_SHAPES"))
each circle_packing_triangle(t, density)
];
function circle_packing_triangle(t, density) =
[
for(st = tri_subdivide(t, density))
let(
s1 = st[1] - st[0],
s2 = st[2] - st[1],
s3 = st[0] - st[2],
leng_s1 = norm(s1),
leng_s2 = norm(s2),
leng_s3 = norm(s3)
)
[tri_incenter(st), abs(cross(s1, s2)) / (leng_s1 + leng_s2 + leng_s3)]
];
$fn = 24;
density = 4;
points = [for(i = [0:100]) rands(-100, 100, 2)];
for(c = circle_packing2(points, density)) {
translate(c[0])
sphere(c[1]);
}