尝试在 CadQuery Python 中对螺栓进行建模:
import cadquery as cq
from math import sqrt, tan, radians
# Параметры модели
head_diameter = 10.0 # Диаметр по вершинам (описанная окружность)
head_height = 5.0 # Высота головки
shaft_diameter = 5.0 # Диаметр стержня
shaft_length = 20.0 # Длина стержня
# Расчетные параметры
R = head_diameter / 2 # Радиус описанной окружности
r = R * sqrt(3)/2 # Радиус вписанной окружности
chamfer_size = (R - r) / tan(45) # Размер фаски для угла 45°
#1. Создаем шестигранную головку
bolt_head = (
cq.Workplane("XY")
.polygon(6, 2*R) # Создаем шестигранник
.extrude(head_height) # Выдавливаем на высоту головки
.translate((0, 0, -1 * (head_height/2)))
)
bolt_head = bolt_head.edges("Z").chamfer(1)
# 2. Создаем стержень
bolt_shaft = (
cq.Workplane("XY")
.circle(shaft_diameter/2)
.extrude(-shaft_length)
)
# 3. Объединяем компоненты
bolt = bolt_head.union(bolt_shaft)