diff --git a/src/experimental/note.md b/src/experimental/note.md index 237dfb84..9f8056ec 100644 --- a/src/experimental/note.md +++ b/src/experimental/note.md @@ -6,4 +6,5 @@ new: - maze/mz_wang_tiles? - surface/sf_cylinder? -- noise/worley_sphere? \ No newline at end of file +- noise/worley_sphere? +- voronoi/vrn_sphere? \ No newline at end of file diff --git a/src/voronoi/_impl/_vrn_sphere_impl.scad b/src/voronoi/_impl/_vrn_sphere_impl.scad new file mode 100644 index 00000000..6897797e --- /dev/null +++ b/src/voronoi/_impl/_vrn_sphere_impl.scad @@ -0,0 +1,7 @@ +function stereographic_proj_to_plane(point) = + let(n = 1 - point.z) + [point.x / n, point.y / n]; + +function stereographic_proj_to_sphere(point) = + let(n = 1 + point.x ^ 2 + point.y ^ 2) + [2 * point.x / n, 2 * point.y / n, (-1 + point.x ^ 2 + point.y ^ 2) / n]; \ No newline at end of file diff --git a/src/voronoi/vrn_sphere.scad b/src/voronoi/vrn_sphere.scad new file mode 100644 index 00000000..30fb541c --- /dev/null +++ b/src/voronoi/vrn_sphere.scad @@ -0,0 +1,38 @@ +use <_impl/_vrn_sphere_impl.scad>; +use ; + +function vrn_sphere(points) = + let( + r = norm(points[0]), + plane_pts = [for(p = points) stereographic_proj_to_plane(p / r)], + inifinity = [4.5e8, 0], + vrn2_cells = vrn2_cells_from(concat(plane_pts, [inifinity])) + ) + [ + for(i = [0:len(vrn2_cells) - 2]) + [for(p = vrn2_cells[i]) stereographic_proj_to_sphere(p) * r] + ]; + +/* +use ; +use ; +use ; + +n = 60; +radius = 2; + +pts = fibonacci_lattice(n, radius); +#for(p = pts) { + translate(p) + sphere(.05); +} + +cells = vrn_sphere(pts); +for(i = [0:len(cells) - 1]) { + cell = cells[i]; + + polyline_join(concat(cell, [cell[0]])) + sphere(.05); + +} +*/ \ No newline at end of file