fix: Torsion joint slot labeling

This commit is contained in:
Leni Aniva 2024-07-10 10:52:48 -07:00
parent 2395c46839
commit bf299d338c
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 25 additions and 16 deletions

View File

@ -1,4 +1,5 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional
import math import math
import cadquery as Cq import cadquery as Cq
import nhf.parts.springs as springs import nhf.parts.springs as springs
@ -454,14 +455,14 @@ class TorsionJoint:
.workplane() .workplane()
.hole(self.radius_axle * 2) .hole(self.radius_axle * 2)
) )
theta_begin = math.radians(rider_slot_begin) theta_begin = -math.radians(rider_slot_begin)
theta_span = math.radians(self.rider_slot_span) theta_span = math.radians(self.rider_slot_span)
if abs(math.remainder(self.rider_slot_span, 360)) < TOL: if abs(math.remainder(self.rider_slot_span, 360)) < TOL:
theta_step = theta_span / self.rider_n_slots theta_step = theta_span / self.rider_n_slots
else: else:
theta_step = theta_span / (self.rider_n_slots - 1) theta_step = theta_span / (self.rider_n_slots - 1)
for i in range(self.rider_n_slots): for i in range(self.rider_n_slots):
theta = theta_begin + i * theta_step theta = theta_begin - i * theta_step
j = self.rider_n_slots - i - 1 if reverse_directrix_label else i j = self.rider_n_slots - i - 1 if reverse_directrix_label else i
result.polyline(self._directrix(self.rider_disk_height, theta), result.polyline(self._directrix(self.rider_disk_height, theta),
forConstruction=True).tag(f"dir{j}") forConstruction=True).tag(f"dir{j}")
@ -475,26 +476,34 @@ class TorsionJoint:
Cq.Assembly() Cq.Assembly()
.add(spring, name="spring", color=Role.DAMPING.color) .add(spring, name="spring", color=Role.DAMPING.color)
.add(track, name="track", color=Role.PARENT.color) .add(track, name="track", color=Role.PARENT.color)
.add(rider, name="rider", color=Role.PARENT.color) .add(rider, name="rider", color=Role.CHILD.color)
) )
TorsionJoint.add_constraints(result, TorsionJoint.add_constraints(
rider="rider", track="track", spring="spring", result,
directrix=directrix) rider="rider", track="track", spring="spring",
directrix=directrix)
return result.solve() return result.solve()
@staticmethod @staticmethod
def add_constraints(assembly: Cq.Assembly, def add_constraints(assembly: Cq.Assembly,
rider: str, track: str, spring: str, spring: str,
rider: Optional[str] = None,
track: Optional[str] = None,
directrix: int = 0): directrix: int = 0):
""" """
Add the necessary constraints to a RT assembly Add the necessary constraints to a RT assembly
""" """
( if track:
assembly (
.constrain(f"{track}?spring", f"{spring}?top", "Plane") assembly
.constrain(f"{track}?dir", f"{spring}?dir_top", .constrain(f"{track}?spring", f"{spring}?top", "Plane")
"Axis", param=0) .constrain(f"{track}?dir", f"{spring}?dir_top",
.constrain(f"{rider}?spring", f"{spring}?bot", "Plane") "Axis", param=0)
.constrain(f"{rider}?dir{directrix}", f"{spring}?dir_bot", )
"Axis", param=0) if rider:
) (
assembly
.constrain(f"{rider}?spring", f"{spring}?bot", "Plane")
.constrain(f"{rider}?dir{directrix}", f"{spring}?dir_bot",
"Axis", param=0)
)