# 柏拉圖多面骰

November 27, 2021

2. 有些模型本身就適合 CSG 的風格。
3. 雖然 BREP 的面是平滑表現，有時你就是想控制面的細節（例如建立 UV 球）。

## cqmore.polyhedron

``````from cqmore.polyhedron import icosahedron
from cqmore import Workplane

polyhedra = Workplane()
for detail in range(5):
Workplane()
.translate((2 * radius * detail, 0, 0))
)
``````

`cqmore.polyhedron` 的函式都會傳回 `Polyhedron` 實例，它是個 `NamedTuple`，具有 `points``faces` 成員，因為本質上就是個 `tuple`，結合 `*` 解構，就可以撰寫出 `polyhedron(*icosahedron(radius, detail))` 這種風格的程式碼，閱讀上就是建立 icosahedron 多面體。

## 結合 BREP/CSG

``````from cadquery import Face
from cqmore import Workplane
from cqmore.polyhedron import tetrahedron, hexahedron, octahedron, dodecahedron, icosahedron

number_of_faces = 12 # 柏拉圖多面體面數 4, 6, 8, 12 或 20
font_name = 'Arial Black'
font_size = 5
font_distance = 1
detail = 0

platonic_polyhedra = {
4: tetrahedron,
6: hexahedron,
8: octahedron,
12: dodecahedron,
20: icosahedron
}

dice = (Workplane()
.polyhedron(
)
)

# 選取全部的面
faces = dice.faces().vals()
nums = len(faces)
texts = Workplane()
for i in range(nums):
# 在每個面的幾何中心建立文字
Workplane(faces[i])
.workplane(origin = faces[i].Center())
.text(
str(nums - i),
font_size,
-font_distance,
font = font_name
)
)

# 多面體與文字的減集
dice = dice.cut(texts)

show_object(dice)
``````