3/23更新:
1.修正齒頂和齒底參數
2.修正鏡射後的漸開線旋轉角度,需X2
3.修正結果圖
4.調整為可輸入
_____以下正文_____
有鑑於網路上使用python繪製齒輪的資料稀少且大都不正確
小弟僅記錄自己的學習過程並分享給有需要的人
以下程式碼使用python和matplotlib函式庫繪製漸開線齒輪,尚有不足,但至少保證是漸開線齒輪無誤
參考公式皆來自:
https://www.khkgears.co.jp/tw/gear_technology/pdf/gear_guide1.pdf
上代碼
import numpy as np
import matplotlib.pyplot as plt
#可設定參數
m=float(input('請輸入模數(單位:mm)'))#模數
tn=int(input('請輸入齒數(整數)'))#齒數
alpha=int(input('請輸入壓力角(角度)'))#壓力角
d=float(input('請輸入軸徑'))#軸直徑
###
Dp=tn*m#節圓
rp=Dp/2
Db=Dp*np.cos(alpha*np.pi/180)#基圓
rb=Db/2
Da=Dp+2*m#齒頂圓直徑
ra=Da/2
Df=Dp-2.5*m#齒底圓直徑
rf=Df/2
#畫基圓
theta = np.linspace(0, 2 * np.pi, 100)
DbX = rb * np.cos(theta)
DbY = rb * np.sin(theta)
#畫節圓
DpX = rp * np.cos(theta)
DpY = rp * np.sin(theta)
#畫齒頂圓
DaX = ra * np.cos(theta)
DaY = ra * np.sin(theta)
#畫軸
dx = d/2 * np.cos(theta)
dy = d/2 * np.sin(theta)
x=[]
y=[]
#畫齒根
x.append(rf)
y.append(0)
#畫漸開線
final_a=np.degrees(np.arccos(rb/ra))
final_t=ra*np.sin(final_a/180*np.pi)/rb*180/np.pi
# print('final_a=',final_a)
# print('final_t=',final_t)
jump=True
t=0
while(jump):
if t>=final_t:
t=final_t
jump=False
cbArc=rb*t*np.pi/180#弧長
a=np.degrees(np.arctan(cbArc/rb))
inva=(t-a)*np.pi/180#漸開線函數
xc=(rb/np.cos(a*np.pi/180)) * np.cos(inva)#漸開線公式
yc=(rb/np.cos(a*np.pi/180)) * np.sin(inva)#漸開線公式
x.append(xc)
y.append(yc)
t+=2#t為漸開線畫線的精度,+2代表每2度畫一點,變化量越小越準
#鏡射
M=np.array([[1,0],
[0,-1]],)
mirCx=[]
mirCy=[]
for i in range(len(x)):
xm,ym,=M.dot([x[i],y[i]])
mirCx.append(xm)
mirCy.append(ym)
#旋轉
rpa=np.degrees(np.arccos(rb/rp))
rpt=rp*np.sin(rpa/180*np.pi)/rb#齒型和節圓交接的點,和圓心的夾角
# print('rpa=',rpa)
# print('rpt=',rpt)
theta=(rpt-rpa/180*np.pi)*2 + np.pi/tn
Mr=np.array([[np.cos(theta),-np.sin(theta)],
[np.sin(theta),np.cos(theta)]],)
for i in range(len(mirCx)):
ii=len(mirCx)-i-1#倒者走
xm,ym,=Mr.dot([mirCx[ii],mirCy[ii]])
x.append(xm)
y.append(ym)
#將齒根旋轉複製
xgear=[]
ygear=[]
for i in range(1,tn+1):
theta=np.pi/tn*i*2
Mr=np.array([[np.cos(theta),-np.sin(theta)],
[np.sin(theta),np.cos(theta)]],)
for i in range(len(x)):
xm,ym,=Mr.dot([x[i],y[i]])
xgear.append(xm)
ygear.append(ym)
xgear.append(xgear[0])
ygear.append(ygear[0])
plt.plot(dx,dy,DbX,DbY,'-.',DpX,DpY,'-.',DaX,DaY,'-.',xgear,ygear)
plt.axis('equal')
plt.title('Gear')
plt.show()
上結果
基本上我還少畫的齒底圓,齒輪也還沒有導圓角,
齒和齒之間(齒頂和齒底)是用直線連接而非圓弧
還有很多進步空間
各位大大可以再依照需求自行修改