--- jupyter: description: 'A lever as a 2D CAD exercise: a dimensioned drawing to model in planex2d or any CAD system, a solution as a fully constrained sketch from a rough outline, and the area and centroid to check a model against.' --- # Lever A lever turns a shaft through its hub and carries a pin at its eye. It has two bosses joined by an arm whose edges are tangent to both, and a slot that saves weight. Model the lever from the drawing in planex2d or in any CAD system, then check its area and centroid against the values at the end of the page. A solution in planex2d follows. ![The lever exercise: a dimensioned drawing of a lever with a hub, an eye, an arm tangent to both and a slot in the arm](../_static/gallery/lever.png){.result} ```python import planex as px ``` ```python nbsphinx="hidden" from docs_figures import Row ``` ## The outline The outline is drawn roughly, starting at the bottom of the hub. It is a line, a half circle around the eye, a line back and a half circle around the hub, both half circles of radius 16 for now. The bore and the pin hole go around the centers of the two arcs with `concentric=`, which `auto_constraint=True` keeps as a constraint, and the slot starts 35 from the hub's center. The outline only needs the right shape, and the dimensions in the next section give it its sizes (Figure 1). ```python lever = px.Sketch(auto_constraint=True) lever.Move((0, -20)).Line(110, id="lower") lever.Arc(16, 180, id="eye") lever.Line(110, id="upper") lever.Arc(16, 180, id="hub") lever.Circle(10, concentric="hub", id="bore") lever.Circle(5, concentric="eye", id="pin_hole") lever.Move((35, 0)).Slot(40, 10, id="slot"); # 40 between the centers of its ends, 10 wide ``` ```python nbsphinx="hide-input" Row((lever, "The rough outline, both arcs of radius 16", {"fill": False}), caption="The outline") ``` ## The dimensions The hub's center is the origin, and the eye's center lies on the horizontal axis, 110 away. The chain has made each piece tangent to the one before it, and the hub to the bottom line where the outline closes, so the arm's edges run straight from boss to boss. The slot lies on the axis. `Slot` has already made its width a dimension, `slot.w`, and its spine carries the length. With these, nothing in the sketch is left free (Figure 2): ```python lever.Constrain("hub.center", "origin", px.Coincident) lever.Constrain("eye.center", "H", px.Coincident) lever.Constrain("hub", px.Radius, 20, id="hub_r") lever.Constrain("eye", px.Radius, 12, id="eye_r") lever.Constrain("hub.center", "eye.center", px.Distance, 110, id="length") lever.Constrain("bore", px.Diameter, 20, id="bore_d") lever.Constrain("pin_hole", px.Diameter, 10, id="pin_d") lever.Constrain("slot.spine", px.Horizontal) lever.Constrain("slot.spine.start", "H", px.Coincident) lever.Constrain("hub.center", "slot.spine.start", px.Distance, 35, id="slot_at") lever.Constrain("slot.spine", px.Distance, 40, id="slot_l") print("status", lever.status, "| degrees of freedom", lever.dof) ``` ```python nbsphinx="hide-input" Row((lever, "Every dimension and tie of the sketch", {"constraints": True}), caption="The fully constrained sketch") ``` ## The checks These are the area and the centroid of the lever, with the hub's center at the origin, to compare with your own model (Figure 3): ```python face = lever.Face() print("area", round(face.mass, 2), "mm²") print("centroid", tuple(round(v, 2) for v in face.center[:2])) ``` ```python nbsphinx="hide-input" Row((face, "The lever, its centroid marked", {"marks": [face.center[:2]]}), caption="The lever") ``` The outline as DXF in millimeters, for another CAD system or a laser cutter: ```python lever.WriteDXF("lever.dxf", unit=px.mm, scale=1) # scale=1: the numbers as they are ``` The outline as DXF: [lever.dxf](lever.dxf) ```python nbsphinx="hidden" import sys sys.path.insert(0, "..") import matplotlib.pyplot as plt from drawings import SheetFigure, View from gallery import save_figure # the slot's width, from the ends of its two sides to just past the slot's right end (sx1, _), w = lever.Location("slot.spine.end"), lever.dimensions["slot.w"] view = View([(lever, {"length": -35, "slot_at": 32, "slot_l": 32, "hub_r": (225, "outside"), "eye_r": (315, "outside"), "bore_d": 135, "pin_d": (45, "leader")}, {"bore": "lines", "pin_hole": "lines", "slot.startcap": "cross-v", "slot.endcap": "cross-v"})], # the axis broken where the slot's width stands on it axes=[((-25, 0), (sx1 + w / 2 + 3, 0), (0, 0)), ((sx1 + w / 2 + 20, 0), (127, 0), (110, 0))], measures=[((sx1, -w / 2), (sx1, w / 2), sx1 + w / 2 + 13, w)]) drawing = SheetFigure([view], margin=20, notes=("planex2d.org", "2D exercise 02")) print("scale 1 :", round(1 / drawing.planex_scale), "| paper", [round(v * 25.4) for v in drawing.get_size_inches()], "mm") save_figure(drawing, "lever", dpi=200) plt.close(drawing) ```