# 莫比烏斯帶

cqmore.polyhedron 提供有 sweep 函式，cqmore.matrix 提供了矩陣處理相關函式，而 cqmore.polygon 提供了一些建立簡單多邊形的函式，例如 star，如果用它來做莫比烏斯帶會如何呢？

from cqmore import Workplane
from cqmore.matrix import translation, rotationX, rotationZ
from cqmore.polyhedron import sweep
from cqmore.polygon import star

profile = [(p[0] * star_r, p[1] * star_r, 0) for p in star()]

rotationX90 = rotationX(90)

angle_step = 360 / frags
profiles = []
for i in range(frags + 1): # 這邊要加一
m = rotationZ(i * angle_step) @ translationX20 @ rotationX90 @ rotationZ(i * angle_step / 2)
profiles.append(m.transformAll(profile))

return Workplane().polyhedron(*sweep(profiles))

frags = 24

from cqmore import Workplane
from cqmore.matrix import translation, rotationX, rotationZ
from cqmore.polyhedron import sweep
from cqmore.polygon import star

# 轉為 3D 的點
profile = [(p[0] * star_r, p[1] * star_r, 0) for p in star()]

rotationX90 = rotationX(90)

angle_step = 360 / frags
profiles = []
for i in range(frags): # 這邊不用加一了
m = rotationZ(i * angle_step) @ translationX20 @ rotationX90 @ rotationZ(i * angle_step / 2)
profiles.append(m.transformAll(profile))

# closeIdx 設為 0 以上的值就會自動接合切面
return Workplane().polyhedron(*sweep(profiles, closeIdx = 0))

frags = 24

from cqmore import Workplane
from cqmore.matrix import translation, rotationX, rotationZ
from cqmore.polyhedron import sweep
from cqmore.polygon import star

profile = [(p[0] * star_r, p[1] * star_r, 0) for p in star()]

rotationX90 = rotationX(90)

angle_step = 360 / frags
profiles = []
for i in range(frags):
m = rotationZ(i * angle_step) @ translationX20 @ rotationX90 @ rotationZ(i * angle_step / 2)
profiles.append(m.transformAll(profile))

return Workplane().polyhedron(*sweep(profiles, closeIdx = 5))

frags = 24

from cqmore import Workplane
from cqmore.matrix import translation, rotationX, rotationZ
from cqmore.polyhedron import sweep
from cqmore.polygon import star

# 六角星
profile = [(p[0] * star_r, p[1] * star_r, 0) for p in star(n = 6)]

rotationX90 = rotationX(90)

angle_step = 360 / frags
profiles = []
for i in range(frags):
m = rotationZ(i * angle_step) @ translationX20 @ rotationX90 @ rotationZ(i * angle_step / 2)
profiles.append(m.transformAll(profile))

return Workplane().polyhedron(*sweep(profiles, closeIdx = 6))