鏡像

November 26, 2021

2D 鏡像

`Workplane` 在 2D 部份，提供有 `mirrorX``mirrorY` 方法，可以針對 2D 形狀建立鏡像。例如：

``````import cadquery as cq

heart = (cq.Workplane()
.moveTo(0, -10)
.lineTo(10, 0).threePointArc((10, 5), (0, 5)) # 一半的愛心
.mirrorY() # 以 Y 軸進行鏡像
)
``````

``````import cadquery as cq

rects = (cq.Workplane()
.center(10, 10)
.rect(5, 5)
.mirrorY()
)
``````

``````import cadquery as cq

rect = (cq.Workplane()
.center(10, 10)
.rect(5, 5)
)

rects = (cq.Workplane()
)

show_object(rects)
``````

``````import cadquery as cq

rects = (cq.Workplane()
.moveTo(5, 5)
.lineTo(10, 5)
.lineTo(10, 10)
.lineTo(5, 10)
.close()
.mirrorX())
``````

3D 鏡像

``````import cadquery as cq

boxes = (cq.Workplane()
.moveTo(5, 5)
.lineTo(10, 5)
.lineTo(10, 10)
.lineTo(5, 10)
.close()
.extrude(10)
.mirror(mirrorPlane = 'YZ')
)
``````

``````import cadquery as cq

boxes = (cq.Workplane()
.moveTo(5, 5)
.lineTo(10, 5)
.lineTo(10, 10)
.lineTo(5, 10)
.close()
.extrude(10)
.mirror(mirrorPlane = 'YZ', union = True)
)
``````

``````import cadquery as cq

boxes = (cq.Workplane()
.moveTo(5, 5)
.lineTo(10, 5)
.lineTo(10, 10)
.lineTo(5, 10)
.close()
.extrude(10)
)

# 基於方塊在 X 方向最遠面進行鏡像
boxes = boxes.mirror(boxes.faces('>X'), union = True)
``````