(defun c:DrawGearFullTeeth ()
; 基本参数
(setq m 3) ; 模数
(setq z 21) ; 齿数
(setq alpha 20) ; 压力角(度)
(setq boreDia 25); 内孔直径
(setq keyWidth 8); 键槽宽
(setq keyDepth 4); 键槽深
; 计算几何参数
(setq d (* m z)) ; 分度圆直径
(setq r (/ d 2.0)) ; 分度圆半径
(setq da (* (+ z 2) m)) ; 齿顶圆直径
(setq df (* (- z 2.5) m)) ; 齿根圆直径
(setq baseDia (* d (cos (/ (* alpha pi) 180)))) ; 基圆直径
(setq baseR (/ baseDia 2.0))
; 渐开线函数(参数theta为弧度)
(defun involuteX (rb theta) (* rb (+ (cos theta) (* theta (sin theta)))))
(defun involuteY (rb theta) (* rb (- (sin theta) (* theta (cos theta)))))
; 生成单个齿槽轮廓点集
(setq thetaStep (/ pi 50)) ; 角度步长
(setq points '())
(setq thetaMax (sqrt (- (expt (/ da 2 baseR) 2) 1)))) ; 最大展角
; 生成渐开线齿廓(右侧)
(setq theta 0)
(while (<= theta thetaMax)
(setq x (involuteX baseR theta))
(setq y (involuteY baseR theta))
(if (> baseDia df) ; 基圆大于齿根圆时需添加过渡圆弧
(setq points (cons (list x y) points))
(setq theta (+ theta thetaStep))
; 添加齿根圆弧(示例简化,实际需精确计算)
(setq rootRadius (/ df 2))
(setq rootAngle (/ (* 2 pi) z)) ; 齿间角
(setq startAngle (- (/ rootAngle 2)))
(setq endAngle (/ rootAngle 2)))
(setq angleStep (/ (- endAngle startAngle) 10))
(setq ang startAngle)
(while (<= ang endAngle)
(setq x (* rootRadius (cos ang)))
(setq y (* rootRadius (sin ang)))
(setq points (cons (list x y) points))
(setq ang (+ ang angleStep)))
; 镜像生成左侧齿廓
(setq leftPoints (mapcar '(lambda (pt) (list (- (car pt)) (cadr pt))) points))
(setq allPoints (append points leftPoints))
; 创建闭合多段线(单个齿槽)
(command "PLINE")
(foreach pt allPoints (command pt))
(command "C")
; 环形阵列生成全齿
(command "ARRAY" "P" "" "PO" "0,0" z "360" "Y") ; 极轴阵列
; 修剪多余线条(齿顶圆与齿根圆)
(command "TRIM" (ssget "X" '((0 . "CIRCLE"))) "" "F" "0,0" da "") ; 示例简化修剪
; 绘制内孔和键槽(原代码部分)
(command "CIRCLE" "0,0" (/ boreDia 2))
(command "RECTANG" (list (- (/ keyWidth 2)) (- keyDepth)) (list (/ keyWidth 2) keyDepth))
(command "SUBTRACT" (entlast) "" (ssget "L"))
(princ)
)