From 800b658410bfc54b4ffc26b48b829e2c3b402d1f Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Sat, 6 Jul 2024 23:50:10 -0700 Subject: [PATCH] feat: Right-handed spring --- nhf/parts/joints.py | 5 +++-- nhf/parts/springs.py | 18 ++++++++++++------ nhf/parts/test.py | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/nhf/parts/joints.py b/nhf/parts/joints.py index b69fb67..0a4b47a 100644 --- a/nhf/parts/joints.py +++ b/nhf/parts/joints.py @@ -314,12 +314,12 @@ class TorsionJoint: l = self.spring_tail_length if self.right_handed: r2 = -r2 - # This is (0, r2) and (l, r2) transformed by rotation matrix - # [[c, s], [-s, c]] return [ (0, 0, height), (c, s, height) ] + # This is (0, r2) and (l, r2) transformed by rotation matrix + # [[c, s], [-s, c]] return [ (s * r2, -s * l + c * r2, height), (c * l + s * r2, -s * l + c * r2, height), @@ -332,6 +332,7 @@ class TorsionJoint: height=self.spring_height, thickness=self.spring_thickness, tail_length=self.spring_tail_length, + right_handed=self.right_handed, ) def track(self): diff --git a/nhf/parts/springs.py b/nhf/parts/springs.py index 31fcf51..7ce0530 100644 --- a/nhf/parts/springs.py +++ b/nhf/parts/springs.py @@ -5,11 +5,14 @@ def torsion_spring(radius=12, height=20, thickness=2, omega=90, - tail_length=25): + tail_length=25, + right_handed: bool = False): """ Produces a torsion spring with abridged geometry since sweep is very slow in cq-editor. """ + if right_handed: + omega = -omega base = ( Cq.Workplane('XY') .cylinder(height=height, radius=radius, @@ -17,12 +20,14 @@ def torsion_spring(radius=12, ) base.faces(">Z").tag("top") base.faces("