Created
August 22, 2020 20:24
-
-
Save Caaz/a9d52aad0b447e2fbcb0995849dfa9d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c1 = 0; // coordinate 1 | |
c2 = 1 / 2; // coordinate 2 | |
c3 = (1 + sqrt(5)) / 4; // coordinate 3; phi / 2 | |
function icosahedron_faces() = [ | |
[ 0, 1, 5], // right rear | |
[ 0, 4, 1], // right front | |
[ 0, 5, 10], // top rear right | |
[ 0, 8, 4], // top front right | |
[ 0, 10, 8], // top right | |
[ 1, 4, 9], // bottom front right | |
[ 1, 9, 11], // bottom right | |
[ 1, 11, 5], // bottom rear right | |
[ 2, 3, 6], // left front | |
[ 2, 6, 8], // top front left | |
[ 2, 7, 3], // left rear | |
[ 2, 8, 10], // top left | |
[ 2, 10, 7], // top rear left | |
[ 3, 7, 11], // bottom rear left | |
[ 3, 9, 6], // bottom front left | |
[ 3, 11, 9], // bottom left | |
[ 4, 6, 9], // front bottom | |
[ 4, 8, 6], // front top | |
[ 5, 7, 10], // rear top | |
[ 5, 11, 7], // rear bottom | |
]; | |
function icosahedron_vertices() = [ | |
[ c3, c1, c2], // 0: right top | |
[ c3, c1, -c2], // 1: right bottom | |
[-c3, c1, c2], // 2: left top | |
[-c3, c1, -c2], // 3: left bottom | |
[ c2, c3, c1], // 4: front right | |
[ c2, -c3, c1], // 5: rear right | |
[-c2, c3, c1], // 6: front left | |
[-c2, -c3, c1], // 7: rear left | |
[ c1, c2, c3], // 8: top front | |
[ c1, c2, -c3], // 9: bottom front | |
[ c1, -c2, c3], // 10: top rear | |
[ c1, -c2, -c3], // 11: bottom rear | |
]; | |
module icosahedron(size) { | |
scale(size) polyhedron(icosahedron_vertices(), icosahedron_faces()); | |
} | |
function normal_x(tri) = | |
(tri[1][0]-tri[0][0]) * (tri[2][2]-tri[0][2])- | |
(tri[1][2]-tri[0][2]) * (tri[2][1]-tri[0][1]); | |
function normal_y(tri) = | |
(tri[1][2]-tri[0][2]) * (tri[2][0]-tri[0][0])- | |
(tri[1][0]-tri[0][0]) * (tri[2][2]-tri[0][2]); | |
function normal_z(tri) = | |
(tri[1][0]-tri[0][0]) * (tri[2][1]-tri[0][1])- | |
(tri[1][1]-tri[0][1]) * (tri[2][0]-tri[0][0]); | |
function normal(tri) = [normal_x(tri),normal_y(tri),normal_z(tri)]; | |
icosahedron(1); | |
faces = icosahedron_faces(); | |
vertices = icosahedron_vertices(); | |
a = 360; | |
for (i = [0:19]) { | |
face = [vertices[faces[i][0]],vertices[faces[i][1]],vertices[faces[i][2]]]; | |
n = normal(face); | |
rotate([n[0]*a,n[1]*a,n[2]*a]) | |
hull() { | |
sphere(.1,$fn=20); | |
translate([1,0,0]) | |
sphere(.03,$fn=20); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment