2025-04-24 16:08:45 +10:00
// Dodecahedron
// A regular dodecahedron or pentagonal dodecahedron is a dodecahedron composed of regular pentagonal faces, three meeting at each vertex. This example shows constructing the a dodecahedron with a series of intersects.
2025-03-06 18:01:24 -05:00
// Set units
2025-05-06 08:44:03 +12:00
@settings(defaultLengthUnit = in, kclVersion = 1.0)
2025-03-06 18:01:24 -05:00
2025-04-24 16:08:45 +10:00
// Define the dihedral angle for a regular dodecahedron
dihedral = 116.565
2025-03-06 18:01:24 -05:00
2025-04-24 16:08:45 +10:00
// Create a face template function that makes a large thin cube
2025-05-01 11:36:51 -05:00
fn createFaceTemplate(@dither) {
2025-04-24 16:08:45 +10:00
baseSketch = startSketchOn(XY)
2025-04-25 16:01:35 -05:00
|> startProfile(at = [-1000 - dither, -1000 - dither])
2025-04-24 16:08:45 +10:00
|> line(endAbsolute = [1000 + dither, -1000 - dither])
|> line(endAbsolute = [1000 + dither, 1000 + dither])
|> line(endAbsolute = [-1000 - dither, 1000 + dither])
|> close()
extruded = extrude(baseSketch, length = 1000 + dither + 1000)
return extruded
|> translate(x = 0, y = 0, z = -260 - dither)
2025-03-06 18:01:24 -05:00
}
2025-04-24 16:08:45 +10:00
// Define the rotations array with [pitch, roll, yaw, dither] for each face
faceRotations = [
[0, 0, 0, 0],
// face1 - reference face
[dihedral, 0, 0, 0.1],
// face2
[dihedral, 0, 72, 0.2],
// face3
[dihedral, 0, 144, 0.3],
// face4
[dihedral, 0, 216, 0.4],
// face5
[dihedral, 0, 288, 0.5],
// face6
[180, 0, 0, 0.6],
// face7
[180 - dihedral, 0, 36, 0.7],
// face8
[180 - dihedral, 0, 108, 0.8],
// face9
[180 - dihedral, 0, 180, 0.9],
// face10
[180 - dihedral, 0, 252, 0.11],
// face11
[180 - dihedral, 0, 324, 0.12],
// face12
]
2025-03-06 18:01:24 -05:00
2025-04-24 16:08:45 +10:00
// Create faces by mapping over the rotations array
2025-04-25 19:09:03 -05:00
dodecFaces = map(
faceRotations,
2025-05-08 15:10:47 -04:00
f = fn(@rotation) {
2025-04-25 19:09:03 -05:00
return createFaceTemplate(rotation[3])
|> rotate(
pitch = rotation[0],
roll = rotation[1],
yaw = rotation[2],
global = true,
)
},
)
2025-03-06 18:01:24 -05:00
2025-05-01 11:36:51 -05:00
fn calculateArrayLength(@arr) {
2025-04-25 19:09:03 -05:00
return reduce(
arr,
initial = 0,
2025-05-08 15:10:47 -04:00
f = fn(@item, accum) {
return accum + 1
2025-04-25 19:09:03 -05:00
},
)
2025-04-24 16:08:45 +10:00
}
2025-03-06 18:01:24 -05:00
2025-05-01 11:36:51 -05:00
fn createIntersection(@solids) {
2025-05-08 15:10:47 -04:00
fn reduceIntersect(@previous, accum) {
return intersect([previous, accum])
2025-04-24 16:08:45 +10:00
}
lastIndex = calculateArrayLength(solids) - 1
lastSolid = solids[lastIndex]
remainingSolids = pop(solids)
2025-04-25 19:09:03 -05:00
return reduce(remainingSolids, initial = lastSolid, f = reduceIntersect)
2025-04-24 16:08:45 +10:00
}
2025-03-06 18:01:24 -05:00
2025-04-24 16:08:45 +10:00
// Apply intersection to all faces
createIntersection(dodecFaces)