Cosplay/nhf/springs.py

43 lines
1.5 KiB
Python
Raw Normal View History

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,
tail_length=25):
"""
Produces a torsion spring with abridged geometry since sweep is very slow in
cq-editor.
"""
base = (
Cq.Workplane('XY')
.cylinder(height=height, radius=radius,
centered=(True, True, False))
)
base.faces(">Z").tag("top")
base.faces("<Z").tag("bot")
result = (
base
.cylinder(height=height, radius=radius - thickness, combine='s',
centered=(True, True, True))
.transformed(
offset=(0, radius-thickness),
rotate=(0, 0, 0))
.box(length=tail_length, width=thickness, height=thickness, centered=False)
.copyWorkplane(Cq.Workplane('XY'))
.transformed(
offset=(0, 0, height - thickness),
rotate=(0, 0, omega))
.center(-tail_length, radius-thickness)
.box(length=tail_length, width=thickness, height=thickness, centered=False)
)
result.polyline([(0, radius, 0), (tail_length, radius, 0)],
forConstruction=True).tag("directrix_bot")
c, s = math.cos(omega * math.pi / 180), math.sin(omega * math.pi / 180)
result.polyline([
(s * tail_length, c * radius - s * tail_length, height),
(c * tail_length + s * radius, c * radius - s * tail_length, height)],
forConstruction=True).tag("directrix_top")
return result