Files
cadSet/text-to-cad/models/cad-router-v1/shaft_reference_set_v1/004910_like.py
T
2026-07-27 16:01:32 +08:00

127 lines
4.2 KiB
Python

"""Approximate long cylindrical pin with a shallow axial end recess."""
from math import atan2, degrees, hypot, sqrt
from build123d import Box, Cylinder, Location
from shaft_common import cut_end_bore, export_horizontal, stepped_body
OUTER_DIAMETER = 18.0
LENGTH = 120.0
RECESS_DIAMETER = 6.0
RECESS_DEPTH = 5.0
VIEWER_POCKET_CENTER = (50.72611906534796, 1.4055875192234604, 8.886497233823093)
VIEWER_POCKET_WIDTH = 2.0
VIEWER_POCKET_HEIGHT = 2.0
VIEWER_POCKET_DEPTH = 1.0
VIEWER_POCKET_OVERSHOOT = 0.2
CIRCULAR_POCKET_CENTER = (68.62703575804954, 0.06569140145571417, 8.989927422862593)
CIRCULAR_POCKET_NORMAL = (0.0, -0.156229, -0.987721)
CIRCULAR_POCKET_DIAMETER = 8.0
CIRCULAR_POCKET_DEPTH = 1.0
CIRCULAR_POCKET_OVERSHOOT = 0.2
COUNTERBORE_CENTER = (40.48928144002571, -7.833112445247494, 4.424155112072327)
COUNTERBORE_NORMAL = (0.000061, -0.039505, -0.999219)
COUNTERBORE_HOLE_DIAMETER = 3.0
COUNTERBORE_DIAMETER = 6.0
COUNTERBORE_DEPTH = 2.0
COUNTERBORE_FACE_SELECTOR = {
"reference_id": "f1",
"face_index": 164,
"row_index": 0,
}
COUNTERBORE_OVERSHOOT = 0.2
COUNTERBORE_THROUGH_OVERSHOOT = 2.0
def cut_viewer_rectangular_pocket(body):
x_pos, y_pos, z_pos = VIEWER_POCKET_CENTER
radial_length = hypot(y_pos, z_pos)
normal_y = y_pos / radial_length
normal_z = z_pos / radial_length
rotation_x = degrees(atan2(-normal_y, normal_z))
tool_depth = VIEWER_POCKET_DEPTH + VIEWER_POCKET_OVERSHOOT
tool_center_offset = (VIEWER_POCKET_OVERSHOOT - VIEWER_POCKET_DEPTH) / 2.0
tool_center = (
x_pos,
y_pos + normal_y * tool_center_offset,
z_pos + normal_z * tool_center_offset,
)
tool = Location(tool_center, (rotation_x, 0.0, 0.0)) * Box(
VIEWER_POCKET_WIDTH,
VIEWER_POCKET_HEIGHT,
tool_depth,
)
return body - tool
def cut_viewer_circular_pocket(body):
x_pos, y_pos, z_pos = CIRCULAR_POCKET_CENTER
normal_x, normal_y, normal_z = CIRCULAR_POCKET_NORMAL
normal_length = sqrt(normal_x**2 + normal_y**2 + normal_z**2)
normal_y /= normal_length
normal_z /= normal_length
rotation_x = degrees(atan2(-normal_y, normal_z))
tool_depth = CIRCULAR_POCKET_DEPTH + CIRCULAR_POCKET_OVERSHOOT
tool_center_offset = (CIRCULAR_POCKET_DEPTH - CIRCULAR_POCKET_OVERSHOOT) / 2.0
tool_center = (
x_pos,
y_pos + normal_y * tool_center_offset,
z_pos + normal_z * tool_center_offset,
)
tool = Location(tool_center, (rotation_x, 0.0, 0.0)) * Cylinder(
CIRCULAR_POCKET_DIAMETER / 2.0,
tool_depth,
)
return body - tool
def cut_viewer_counterbore(body):
x_pos, y_pos, z_pos = COUNTERBORE_CENTER
normal_x, normal_y, normal_z = COUNTERBORE_NORMAL
normal_length = sqrt(normal_x**2 + normal_y**2 + normal_z**2)
normal_y /= normal_length
normal_z /= normal_length
rotation_x = degrees(atan2(-normal_y, normal_z))
through_depth = OUTER_DIAMETER + 4.0
through_tool_depth = through_depth + COUNTERBORE_THROUGH_OVERSHOOT
through_center_offset = (through_depth - COUNTERBORE_THROUGH_OVERSHOOT) / 2.0
through_center = (
x_pos,
y_pos + normal_y * through_center_offset,
z_pos + normal_z * through_center_offset,
)
through_tool = Location(through_center, (rotation_x, 0.0, 0.0)) * Cylinder(
COUNTERBORE_HOLE_DIAMETER / 2.0,
through_tool_depth,
)
counterbore_tool_depth = COUNTERBORE_DEPTH + COUNTERBORE_OVERSHOOT
counterbore_center_offset = (COUNTERBORE_DEPTH - COUNTERBORE_OVERSHOOT) / 2.0
counterbore_center = (
x_pos,
y_pos + normal_y * counterbore_center_offset,
z_pos + normal_z * counterbore_center_offset,
)
counterbore_tool = Location(counterbore_center, (rotation_x, 0.0, 0.0)) * Cylinder(
COUNTERBORE_DIAMETER / 2.0,
counterbore_tool_depth,
)
return body - through_tool - counterbore_tool
def gen_step():
body, total = stepped_body([(OUTER_DIAMETER, LENGTH)])
body = cut_end_bore(body, total, RECESS_DIAMETER, RECESS_DEPTH)
result = export_horizontal(body, "pin_004910_like")
result = cut_viewer_rectangular_pocket(result)
result = cut_viewer_circular_pocket(result)
result = cut_viewer_counterbore(result)
result.label = "pin_004910_like"
return result