Skip to content

Instantly share code, notes, and snippets.

@crides
Created May 8, 2022 19:05
Show Gist options
  • Save crides/aa902bba2c0c4c447e584b395d44dc29 to your computer and use it in GitHub Desktop.
Save crides/aa902bba2c0c4c447e584b395d44dc29 to your computer and use it in GitHub Desktop.
import cadquery as cq, math, numpy as np
t_r, b_r = 10, 15
back_r, back_ba, back_h, back_l1, back_l2, back_ta = 45, 60, 45, 40, 30, 20
inner_t = 25
side = (
cq.Workplane()
.transformed(offset=(0, -b_r, 0)).circle(b_r).transformed(offset=(0, b_r - t_r, back_h)).circle(t_r).loft())
bot_end = (back_r * math.sin(math.pi / 3), back_r * (math.cos(math.pi / 3) - 1))
c = (0, -back_r)
angs = 90 - back_ba + np.array(range(3)) * back_ba / 3
bottom = cq.Sketch().segment((0, -2 * b_r), (0, 0)).arc(c, back_r, angs[0], back_ba / 3).arc(c, back_r, angs[1], back_ba / 3).arc(c, back_r, angs[2], back_ba / 3).segment(bot_end, (0, -2 * b_r)).assemble()
top = (cq.Sketch()
.segment((0, -2 * t_r), (0, 0), "d").segment((back_l1, 0), "l1").segment((0, 0), (0, 1), "l2").arc((0,0), (0, 1), (1, 1), "in")
.constrain("l1", "Fixed", None).constrain("d", "Fixed", None)
.constrain("l1", "l2", "Coincident", None).constrain("l2", "Length", back_l2)
.constrain("l1", "l2", "Angle", back_ta)
.constrain("in", "Radius", inner_t).constrain("in", "ArcAngle", 90).constrain("l2", "in", "Coincident", None)
.constrain("in", "l2", "Angle", -90)
.solve().close().assemble())
back = cq.Workplane().placeSketch(bottom, top.moved(cq.Location(cq.Vector(0, 0, back_h)))).loft(True)
plane = cq.Plane((0, -b_r * 2, 0), (1, 0, 0), (0, -back_h / (2 * (b_r - t_r)), 1))
plane_top = plane.toLocalCoords(cq.Vector(0, -t_r * 2, back_h))
print(plane_top)
plane = cq.Workplane(plane)
tri_sket = (cq.Sketch().segment((0, 0), plane_top, "v").segment((5, 0), "t").segment((0, 0), "s")
.constrain("v", "Fixed", None).constrain("t", "FixedPoint", 0).constrain("s", "v", "Coincident", None)
.constrain("t", "s", "Coincident", None).constrain("t", "Length", 40).constrain("s", "Length", 65)
.solve().assemble()
)
tri = plane.placeSketch(tri_sket).toPending().extrude(100)
whole = side + back - tri
show_object(whole)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment