2024-06-26 12:57:22 -07:00
|
|
|
import math
|
|
|
|
import cadquery as Cq
|
|
|
|
|
|
|
|
def torsion_spring(radius=12,
|
|
|
|
height=20,
|
|
|
|
thickness=2,
|
|
|
|
omega=90,
|
2024-07-06 23:50:10 -07:00
|
|
|
tail_length=25,
|
|
|
|
right_handed: bool = False):
|
2024-06-26 12:57:22 -07:00
|
|
|
"""
|
|
|
|
Produces a torsion spring with abridged geometry since sweep is very slow in
|
|
|
|
cq-editor.
|
|
|
|
"""
|
2024-07-06 23:50:10 -07:00
|
|
|
if right_handed:
|
|
|
|
omega = -omega
|
2024-06-26 12:57:22 -07:00
|
|
|
base = (
|
|
|
|
Cq.Workplane('XY')
|
|
|
|
.cylinder(height=height, radius=radius,
|
|
|
|
centered=(True, True, False))
|
|
|
|
)
|
|
|
|
base.faces(">Z").tag("top")
|
|
|
|
base.faces("<Z").tag("bot")
|
2024-07-06 23:50:10 -07:00
|
|
|
|
|
|
|
box_shift = -radius if right_handed else radius-thickness
|
2024-06-26 12:57:22 -07:00
|
|
|
result = (
|
|
|
|
base
|
|
|
|
.cylinder(height=height, radius=radius - thickness, combine='s',
|
|
|
|
centered=(True, True, True))
|
|
|
|
.transformed(
|
2024-07-06 23:50:10 -07:00
|
|
|
offset=(0, box_shift),
|
2024-06-26 12:57:22 -07:00
|
|
|
rotate=(0, 0, 0))
|
2024-06-30 19:03:16 -07:00
|
|
|
.box(
|
|
|
|
length=tail_length,
|
|
|
|
width=thickness,
|
|
|
|
height=thickness,
|
|
|
|
centered=False)
|
2024-06-26 12:57:22 -07:00
|
|
|
.copyWorkplane(Cq.Workplane('XY'))
|
|
|
|
.transformed(
|
|
|
|
offset=(0, 0, height - thickness),
|
|
|
|
rotate=(0, 0, omega))
|
2024-07-06 23:50:10 -07:00
|
|
|
.center(-tail_length, box_shift)
|
2024-06-30 19:03:16 -07:00
|
|
|
.box(
|
|
|
|
length=tail_length,
|
|
|
|
width=thickness,
|
|
|
|
height=thickness,
|
|
|
|
centered=False)
|
2024-06-26 12:57:22 -07:00
|
|
|
)
|
2024-07-06 23:50:10 -07:00
|
|
|
r = -radius if right_handed else radius
|
|
|
|
result.polyline([(0, r, 0), (tail_length, r, 0)],
|
2024-06-26 12:57:22 -07:00
|
|
|
forConstruction=True).tag("directrix_bot")
|
|
|
|
c, s = math.cos(omega * math.pi / 180), math.sin(omega * math.pi / 180)
|
|
|
|
result.polyline([
|
2024-07-06 23:50:10 -07:00
|
|
|
(s * tail_length, c * r - s * tail_length, height),
|
|
|
|
(c * tail_length + s * r, c * r - s * tail_length, height)],
|
2024-06-26 12:57:22 -07:00
|
|
|
forConstruction=True).tag("directrix_top")
|
|
|
|
return result
|