feat: Add directrix tag to hirth joint

This commit is contained in:
Leni Aniva 2024-06-28 17:21:30 -04:00
parent 53ef5e454f
commit 914bc23582
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
2 changed files with 54 additions and 20 deletions

View File

@ -1 +1 @@
from nhf.materials import Material from nhf.materials import Material, Role

View File

@ -2,6 +2,13 @@ from dataclasses import dataclass
import math import math
import cadquery as Cq import cadquery as Cq
import nhf.springs as NS import nhf.springs as NS
from nhf import Role
def hirth_tooth_angle(n_tooth):
"""
Angle of one whole tooth
"""
return 360 / n_tooth
def hirth_joint(radius=60, def hirth_joint(radius=60,
radius_inner=40, radius_inner=40,
@ -9,9 +16,13 @@ def hirth_joint(radius=60,
n_tooth=16, n_tooth=16,
tooth_height=16, tooth_height=16,
tooth_height_inner=2, tooth_height_inner=2,
tol=0.01): tol=0.01,
tag_prefix="",
is_mated=False):
""" """
Creates a cylindrical Hirth Joint Creates a cylindrical Hirth Joint
is_mated: If set to true, rotate the teeth so they line up at 0 degrees.
""" """
# ensures secant doesn't blow up # ensures secant doesn't blow up
assert n_tooth >= 5 assert n_tooth >= 5
@ -51,9 +62,14 @@ def hirth_joint(radius=60,
.val() .val()
) )
tooth_centre_radius = radius_inner * math.cos(theta) tooth_centre_radius = radius_inner * math.cos(theta)
angle_offset = hirth_tooth_angle(n_tooth) / 2 if is_mated else 0
teeth = ( teeth = (
Cq.Workplane('XY') Cq.Workplane('XY')
.polarArray(radius=tooth_centre_radius, startAngle=0, angle=360, count=n_tooth) .polarArray(
radius=tooth_centre_radius,
startAngle=angle_offset,
angle=360,
count=n_tooth)
.eachpoint(lambda loc: tooth.located(loc)) .eachpoint(lambda loc: tooth.located(loc))
.intersect(Cq.Solid.makeCylinder( .intersect(Cq.Solid.makeCylinder(
height=base_height + tooth_height, height=base_height + tooth_height,
@ -66,36 +82,54 @@ def hirth_joint(radius=60,
height=base_height, height=base_height,
radius=radius, radius=radius,
centered=(True, True, False)) centered=(True, True, False))
.faces(">Z").tag("bore") .faces(">Z").tag(f"{tag_prefix}bore")
.union(teeth.val().move(Cq.Location((0,0,base_height))), tol=tol) .union(teeth.val().move(Cq.Location((0,0,base_height))), tol=tol)
.clean() .clean()
) )
#base.workplane(offset=tooth_height/2).circle(radius=radius,forConstruction=True).tag("mate") #base.workplane(offset=tooth_height/2).circle(radius=radius,forConstruction=True).tag("mate")
base.polyline([(0, 0, base_height), (0, 0, base_height+tooth_height)], forConstruction=True).tag("mate") (
base
.polyline([(0, 0, base_height), (0, 0, base_height+tooth_height)], forConstruction=True)
.tag(f"{tag_prefix}mate")
)
(
base
.polyline([(0, 0, 0), (1, 0, 0)], forConstruction=True)
.tag(f"{tag_prefix}directrix")
)
return base return base
def hirth_assembly(): def hirth_assembly(n_tooth=12):
""" """
Example assembly of two Hirth joints Example assembly of two Hirth joints
""" """
rotate = 180 / 16 #rotate = 180 / 16
obj1 = hirth_joint().faces(tag="bore").cboreHole(
diameter=10, tab = (
cboreDiameter=20, Cq.Workplane('XY')
cboreDepth=3) .box(100, 10, 2, centered=False)
obj2 = (
hirth_joint()
.rotate(
axisStartPoint=(0,0,0),
axisEndPoint=(0,0,1),
angleDegrees=rotate
)
) )
obj1 = (
hirth_joint(n_tooth=n_tooth)
.faces(tag="bore")
.cboreHole(
diameter=10,
cboreDiameter=20,
cboreDepth=3)
.union(tab)
)
obj2 = (
hirth_joint(n_tooth=n_tooth, is_mated=True)
.union(tab)
)
angle = hirth_tooth_angle(n_tooth)
result = ( result = (
Cq.Assembly() Cq.Assembly()
.add(obj1, name="obj1", color=Cq.Color(0.8,0.8,0.5,0.3)) .add(obj1, name="obj1", color=Role.PARENT.color)
.add(obj2, name="obj2", color=Cq.Color(0.5,0.5,0.5,0.3)) .add(obj2, name="obj2", color=Role.CHILD.color)
.constrain("obj1", "Fixed")
.constrain("obj1?mate", "obj2?mate", "Plane") .constrain("obj1?mate", "obj2?mate", "Plane")
.constrain("obj1?directrix", "obj2?directrix", "Axis", param=angle)
.solve() .solve()
) )
return result return result