1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00
This commit is contained in:
Justin Lin
2021-09-07 10:12:29 +08:00
parent 9c532acce4
commit e5af7b3027
2 changed files with 33 additions and 32 deletions

View File

@@ -0,0 +1,30 @@
use <experimental/tri_subdivide.scad>;
function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r];
function geom_isosphere(radius, detail = 0) =
let(
t = (1 + sqrt(5)) / 2 ,
icosahedron_points = [
[- 1, t, 0], [1, t, 0], [- 1, - t, 0], [1, - t, 0],
[0, - 1, t], [0, 1, t], [0, - 1, - t], [0, 1, - t],
[t, 0, - 1], [t, 0, 1], [- t, 0, - 1], [- t, 0, 1]
],
icosahedron_faces = [
[5, 11, 0], [1, 5, 0], [7, 1, 0], [10, 7, 0], [11, 10, 0],
[9, 5, 1], [4, 11, 5], [2, 10, 11], [6, 7, 10], [8, 1, 7],
[4, 9, 3], [2, 4, 3], [6, 2, 3], [8, 6, 3], [9, 8, 3],
[5, 9, 4], [11, 4, 2], [10, 2, 6], [7, 6, 8], [1, 8, 9]
],
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];

View File

@@ -1,35 +1,6 @@
use <experimental/tri_subdivide.scad>;
use <experimental/geom_isosphere.scad>;
module isosphere(radius, detail = 0) {
function prj2sphere(t, r) = [for(p = t) p / norm(p) * r];
// Icosahedron
t = (1 + sqrt(5)) / 2 ;
icosahedron_points = [
[- 1, t, 0], [1, t, 0], [- 1, - t, 0], [1, - t, 0],
[0, - 1, t], [0, 1, t], [0, - 1, - t], [0, 1, - t],
[t, 0, - 1], [t, 0, 1], [- t, 0, - 1], [- t, 0, 1]
];
icosahedron_faces = [
[5, 11, 0], [1, 5, 0], [7, 1, 0], [10, 7, 0], [11, 10, 0],
[9, 5, 1], [4, 11, 5], [2, 10, 11], [6, 7, 10], [8, 1, 7],
[4, 9, 3], [2, 4, 3], [6, 2, 3], [8, 6, 3], [9, 8, 3],
[5, 9, 4], [11, 4, 2], [10, 2, 6], [7, 6, 8], [1, 8, 9]
];
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]];
polyhedron(points, faces);
points_faces = geom_isosphere(radius, detail);
polyhedron(points_faces[0], points_faces[1]);
}