11.3 如何繪製齒輪
前面已經討論許多繪製齒輪必要的過程,本節將綜合各節所述,作成可以放置任意位置的齒輪組draw_gear.m,呼叫程式時,可以在任意的地方建立齒輪之外形。利用其轉動座標的功能,可以調整其契合的位置,成為齒輪組。
其呼叫型式如下:
function [coords]=draw_gear(Dp,N,phi,range,x0,y0)
其中,輸入參數分別定義如下:
Dp: 節矩
N: 齒數
phi: 壓力角
range: 繪出之部份
x0,y0: 齒輪中心座標
function [coords]=draw_gear(Dp,N,phi,range,x0,y0) % [coords]=draw_gear(Dp,N,phi,range,x0,y0) % To draw a whole gear % Inputs: % Dp: Diametrical pitch % N: no of teeth in a gear % phi: pressure angle, degrees % range: the section range to be drawn % x0,y0: the location of the gear center % Example [coords]=draw_gear(10,15,20,360,0,0) [coord,theta,rp,rb]=tooth(Dp,N,phi); coords=[];i=0; while i<range coord1=rotate2D(coord,-i,x0,y0); coords=[coords;coord1]; i=i+theta; end plot(coords(:,1),coords(:,2));hold on; [coord]=bushing(rp/8,x0,y0); plot(coord(:,1),coord(:,2),'b-'); [coord]=bushing(-rp,x0,y0); plot(coord(:,1),coord(:,2),'r:'); [coord]=bushing(-rb,x0,y0); plot(coord(:,1),coord(:,2),'b:'); axis equal; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [coords,theta,rp,rb]=tooth(Dp,N,phi) % Example tooth(10,10,20) nn=10; d2r=pi/180; phir=phi*d2r; rp=N/Dp/2; pc=pi/Dp; ra=rp+1/Dp; rb=rp*cos(phir); rd=rp-1.25/Dp; thpb=pc/rp;% angle respect to one pitch tp=pc/2; rr=linspace(rb,ra,nn)'; invphi=tan(phir)-phir; for i=1:nn beta=acos(rp/rr(i)*cos(phir)); tt(i)=(tp/rp/2+invphi-tan(beta)+beta); end coord1=[rr.*cos(tt') rr.*sin(tt')]; coord3=reverse(coord1); th1=linspace(thpb/2,thpb/2-tt(nn),nn)'; coord0=[cos(th1) sin(th1)]*rd; th2=linspace(tt(nn),-tt(nn),nn)'; coord2=[cos(th2) sin(th2)]*ra; coord4=reverse(coord0); coords=[coord0;coord1;coord2;coord3;coord4]; theta=thpb/d2r; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [B]=reverse(A) nn=length(A); B=A; for i=1:nn,B(i,:)=A(nn-i+1,:);end B=[B(:,1) -B(:,2)]; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [coords] = bushing(rr,x0,y0) d2r=pi/180; theta=[360:-10:0]*d2r; r=abs(rr); rx=r*cos(theta);ry=r*sin(theta); if rr<0, rx=rx+x0; ry=ry+y0; coords=[rx' ry']; return; end; rx1=rx/2;rx2=-rx1; ry1=ry/2;ry2=-ry1; r4=r+r/4;r3=r/3; bx=[ 0 0 0 -r -r -r4 -r4 r4 r4 -r r r]; by=[r3 -r3 0 0 -r -r -r4 -r4 -r -r -r 0]; coords(:,1)=[bx rx rx1 rx2]'+x0; coords(:,2)=[by ry ry1 ry2]'+y0; %%%%%%%%%%%%%%%%%%%%%%%% function [coords]=rotate2D(coord,theta,x0,y0) th=theta*pi/180; c=cos(th);s=sin(th);fact=[c s;-s c]; coords=coord*fact; coords(:,1)=coords(:,1)+x0; coords(:,2)=coords(:,2)+y0;
執行範例
>> [coords]=draw_gear(10,15,20,360,0,0)
No comments:
Post a Comment