From c59fdc5f1d3c876dac2ce42f5f0e6d1d0c2c7ac1 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Wed, 8 Sep 2021 08:36:33 +0800 Subject: [PATCH] provide quick_mode --- src/experimental/geom_icosahedron.scad | 51 ++++++++++++++++++++++---- src/experimental/icosahedron.scad | 4 +- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/experimental/geom_icosahedron.scad b/src/experimental/geom_icosahedron.scad index 3155812e..7ca7502c 100644 --- a/src/experimental/geom_icosahedron.scad +++ b/src/experimental/geom_icosahedron.scad @@ -1,8 +1,47 @@ +use <__comm__/_pt3_hash.scad>; +use ; +use ; +use ; use ; function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r]; -function geom_icosahedron(radius, detail = 0) = +function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail) = + let( + points = detail == 0 ? [for(tri = tris) each tri] : [ + for(tri = tris) + each [for(t = tri_subdivide(tri, detail)) each t] + ], + number_of_buckets = ceil(sqrt(len(points))), + hash = _pt3_hash(number_of_buckets), + deduped_pts = dedup(points, hash = hash, number_of_buckets = number_of_buckets), + pts = [for(p = deduped_pts) p / norm(p) * radius], + m = hashmap([ + for(i = [0:len(deduped_pts) - 1]) + [deduped_pts[i], i] + ], hash = hash, number_of_buckets = number_of_buckets), + faces = [ + for(i = [0:3:len(points) - 3]) + [ + hashmap_get(m, points[i], hash = hash), + hashmap_get(m, points[i + 1], hash = hash), + hashmap_get(m, points[i + 2], hash = hash) + ] + ] + ) + [pts, faces]; + +function _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) = + let( + points = detail == 0 ? [for(tri = tris) each _prj2sphere(tri, radius)] : [ + for(tri = tris) + each [for(t = tri_subdivide(tri, detail)) each _prj2sphere(t, radius)] + ], + faces = [for(i = [0:3:len(points) - 3]) [i, i + 1, i + 2]] + ) + [points, faces]; + +function geom_icosahedron(radius, detail = 0, quick_mode = true) = let( t = (1 + sqrt(5)) / 2 , icosahedron_points = [ @@ -19,12 +58,8 @@ function geom_icosahedron(radius, detail = 0) = tris = [ for(face = icosahedron_faces) [for(i = face) icosahedron_points[i]] - ], - points = detail == 0 ? [for(tri = tris) each _prj2sphere(tri, radius)] : [ - for(tri = tris) - each [for(t = tri_subdivide(tri, detail)) each _prj2sphere(t, radius)] - ], - faces = [for(i = [0:3:len(points) - 3]) [i, i + 1, i + 2]] + ] ) - [points, faces]; + quick_mode ? _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) : + _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail); \ No newline at end of file diff --git a/src/experimental/icosahedron.scad b/src/experimental/icosahedron.scad index 22cc9fc1..c81ada48 100644 --- a/src/experimental/icosahedron.scad +++ b/src/experimental/icosahedron.scad @@ -1,6 +1,6 @@ use ; -module icosahedron(radius, detail = 0) { - points_faces = geom_icosahedron(radius, detail); +module icosahedron(radius, detail = 0, quick_mode = true) { + points_faces = geom_icosahedron(radius, detail, quick_mode); polyhedron(points_faces[0], points_faces[1]); } \ No newline at end of file