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
|
2024-07-08 21:46:35 -07:00
|
|
|
plane = result.copyWorkplane(Cq.Workplane('XY'))
|
|
|
|
plane.polyline([(0, r, 0), (tail_length, r, 0)],
|
|
|
|
forConstruction=True).tag("dir_bot")
|
|
|
|
omega = math.radians(omega)
|
|
|
|
c, s = math.cos(omega), math.sin(omega)
|
|
|
|
l = -tail_length
|
|
|
|
plane.polyline([
|
|
|
|
(-s * r, c * r, height),
|
|
|
|
(c * l - s * r, c * r + s * l, height)],
|
|
|
|
forConstruction=True).tag("dir_top")
|
2024-06-26 12:57:22 -07:00
|
|
|
return result
|