function clear_Callback(hObject, eventdata, handles) cla;
function straightline_Callback(hObject, eventdata, handles) global s;
grid on;
x01=str2double(get(handles.x1,'string')); x02=str2double(get(handles.x2,'string')); y01=str2double(get(handles.y1,'string')); y02=str2double(get(handles.y2,'string')); x=linspace(x01,x02,1000);
y=((y02-y01)/(x02-x01))*(x-x01)+y01; plot(x,y,'b'); hold on; s=1;
function circular_arc_Callback(hObject, eventdata, handles) grid on;
x03=str2double(get(handles.x3,'string')); x04=str2double(get(handles.x4,'string')); y03=str2double(get(handles.y3,'string')); y04=str2double(get(handles.y4,'string')); R=str2double(get(handles.r,'string')); l=sqrt((y04-y03).^2+(x04-x03).^2); k=sqrt(R^2-(l^2)/4);
x0=(x03+x04)/2+((y04-y03)*k)/l; y0=(y03+y04)/2-((x04-x03)*k)/l; x=linspace(x03,x04,1000); y=y0+sqrt(R^2-(x-x0).^2); plot(x,y,'b'); axis equal; hold on; global s s=0;
function lxcb_Callback(hObject, eventdata, handles) global s F X Y;
if s==1
x01=str2double(get(handles.x1,'string')); x02=str2double(get(handles.x2,'string')); y01=str2double(get(handles.y1,'string')); y02=str2double(get(handles.y2,'string')); k=str2double(get(handles.buchang,'string')); X=x01;Y=y01;
F=0;
E=(abs(x01-x02)+abs(y01-y02))/k; while E>0 if F>=0 X=X+k;
m=linspace(X-k,X,100); n=Y;
F=F-(y02-y01); plot(m,n,'r'); else Y=Y+k; p=X;
q=linspace(Y-k,Y,100); F=F+(x02-x01); plot(p,q,'r'); end E=E-1; end else
x03=str2double(get(handles.x3,'string')); x04=str2double(get(handles.x4,'string')); y03=str2double(get(handles.y3,'string')); y04=str2double(get(handles.y4,'string')); b=str2double(get(handles.buchang,'string')); j=str2double(get(handles.jcq,'string')); R=str2double(get(handles.r,'string')); l=((y04-y03)^2+(x04-x03)^2)^0.5; m=(y04-y03)/l; n=(x03-x04)/l;
xx=(x03+x04)/2+(R^2-l^2/4)^0.5*m; yy=(y03+y04)/2+(R^2-l^2/4)^0.5*n; if ~(x03<=xx&xx<=x04&y03>=yy&y04>=yy) errordlg('请输入第二一象限的顺圆弧');
else xi=x03;yi=y03;xii=x03;yii=y03; jvx=0; jvy=0;
xj=fix((xx-x03)/b);yj=fix((yy+R-y03)/b); %计算步数 m=2^j; %模 while (xj>0||yj>0) if xj>0
jvx=jvx+yi-yy; end
if yj>0
jvy=jvy+xx-xi; end
flag=0; if(jvx>m)
xj=xj-1;flag=1; xi=xi+b;
jvx=mod(jvx,m); end
if(jvy>m)
yj=yj-1;flag=1; yi=yi+b;
jvy=mod(jvy,m); end
if flag==1
line([xii,xi],[yii,yi],'color','r'); hold on; xii=xi; yii=yi; end end end
line([xi,xx],[yi,yy+R],'color','r');
xi=xx;yi=yy+R;xii=xx;yii=yy+R; jvx=0; jvy=0;
xj=fix((x04-xx)/b);yj=fix((yy+R-y04)/b); m=2^j;
axis auto;
while (xj>0||yj>0) if xj>0
jvx=jvx+yi-yy; end
if yj>0
jvy=jvy+xi-xx; end
flag=0; if(jvx>m)
xj=xj-1;flag=1; xi=xi+b;
jvx=mod(jvx,m); end
if(jvy>m)
yj=yj-1;flag=1; yi=yi-b;
jvy=mod(jvy,m);
end
if flag==1
line([xii,xi],[yii,yi],'color','r'); xii=xi; yii=yi; hold on; end end end
function dbcb_Callback(hObject, eventdata, handles) global X Y F u E s; if s==1
x01=str2double(get(handles.x1,'string')); y01=str2double(get(handles.y1,'string')); x02=str2double(get(handles.x2,'string')); y02=str2double(get(handles.y2,'string')); k=str2double(get(handles.buchang,'string')); if u==0 X=x01;
Y=y01; u=u+1;
E=(abs(x01-x02)+abs(y01-y02))/k; F=0; else
if E>0
if F>=0 X=X+k;
m=linspace(X-k,X,1000); n=Y;
F=F-(y02-y01); plot(m,n,'r'); hold on; else
Y=Y+k; p=X;
q=linspace(Y-k,Y); F=F+(x02-x01); plot(p,q,'r'); hold on; end E=E-1; else
u=0; end end else
global fla;
x03=str2double(get(handles.x3,'string')); x04=str2double(get(handles.x4,'string')); y03=str2double(get(handles.y3,'string')); y04=str2double(get(handles.y4,'string')); b=str2double(get(handles.buchang,'string')); j=str2double(get(handles.jcq,'string')); R=str2double(get(handles.r,'string')); l=((y04-y03)^2+(x04-x03)^2)^0.5; m=(y04-y03)/l;
n=(x03-x04)/l;
xx=(x03+x04)/2+(R^2-l^2/4)^0.5*m;
yy=(y03+y04)/2+(R^2-l^2/4)^0.5*n;
if ~(x03<=xx&&xx<=x04&&y03>=yy&&y04>=yy) errordlg('请输入第二一象限的顺圆弧');
else %第二象限的顺圆插补 xi=x03;yi=y03;
jvx=0; jvy=0;
xj=fix((xx-x03)/b);yj=fix((yy+R-y03)/b); %第二象限的计数器 m=2^j;
k=1;
while (xj>0||yj>0) if xj>0
jvx=jvx+yi-yy; end
if yj>0
jvy=jvy+xx-xi; end
flag=0;
if(jvx>m)
xj=xj-1;flag=1; xi=xi+b;
jvx=mod(jvx,m); end
if(jvy>m)
yj=yj-1;flag=1; yi=yi+b;
jvy=mod(jvy,m); end