Mirroring an Object
First we create a rectangle which is a 2D object so we use BuildSketch.
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildSketch() as TestMirrorSketch:
#Creates a Rectangle
Rectangle(20,10)
show_all()
Next we place it in the first quadrant with 0,0 in the lower left corner.
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildSketch() as TestMirrorSketch:
# Creates a rectangle and centers and places it at 0,0
Rectangle(20,10,align=(Align.MIN,Align.MIN))
# Imagine for purpose of choosing the correct Align MIN/MAX combination
# that 0,0 is in the upper right corner and numbering goes to the left
# and downward. So x=Aling.MIN and y=Align.MAX would place your
# rectangle in the second clockwise quadrant.
show_all()
The next step is to mirror the 2D object along the Y Axis. To do so we need to define the plane which we are going to use as mirror. The plane that we need to use is YZ.
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildSketch() as TestMirrorSketch:
# Creates a rectangle and centers and places it at 0,0
Rectangle(20,10,align=(Align.MIN,Align.MIN))
# We mirror the rectangle
mirror(about=Plane.YZ)
show_all()
So what did we get? We did get a mirror but we also got a copy/bigger face object because the mode of this operation was the default "ADD". If we extrude this we would get a block of 40x10xh.
If we only want out orginal object we need to set a mode for mirror (or the new mirror object) to "REPLACE".
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildSketch() as TestMirrorSketch:
# Creates a rectangle and centers and places it at 0,0
Rectangle(20,10,align=(Align.MIN,Align.MIN))
# We mirror the rectangle and replace it
mirror(about=Plane.YZ,mode=Mode.REPLACE)
show_all()
We also can set an arbitrary mirror plane. We do this the same way as before. We define a plane but we also move it with offset.
from build123d import *
from ocp_vscode import *
set_defaults(reset_camera=Camera.KEEP, black_edges=True,center_grid=True)
with BuildSketch() as TestMirrorSketch:
# Creates a rectangle and centers and places it at 0,0
Rectangle(6,5,align=(Align.MIN,Align.MIN))
# We mirror the rectangle
mirror(about=Plane.YZ.offset(amount=3),mode=Mode.REPLACE)
show_all()
As it is a default YZ plane at x=0 we move it along the X-Axis by +6 to the right. Then the mirror takes place and the whole object is mirrored at x=6 on a XY plane. (Please note I had to change the size of the rectangle)