⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 three_point_circle.m

📁 一个三点画圆的程序。点三个点
💻 M
字号:
% 点三点,画一个圆
% Author's email: zjliu2001@163.com
n=0;t=exp(i*[0:.02:2*pi]);x=[];y=[];
axes('position',[0.05,0.05,0.7,0.8]);
hold on;axis([0,1,0,1]);axis equal;
set(gca,'ButtonDownFcn',['a=get(gca,''currentpoint'');',...
      'if(n<3);x=[x,a(1,1)];y=[y,a(1,2)];end;n=n+1;',...
      'plot(x,y,''*'',''EraseMode'',''none'');',...
      'plot(x,y,''s'',''EraseMode'',''none'');',...
      'set(T,''string'',num2str(n));',...
      'if n==3;eval(Sk);end;']);
uicontrol(gcf,'style','text',...
   'unit','normalized','position',[0.02,0.87,0.84,0.07],...
   'BackgroundColor',[0.8 0.8 0.8],'ForegroundColor','r',...
   'string','在axes内用鼠标取三个点,点第四下就能得到一个圆',...
'fontsize',14);
T=uicontrol(gcf,'style','text',...
   'unit','normalized','position',[0.88,0.87,0.09,0.07],...
   'BackgroundColor',[0.6 0.6 0.6],'ForegroundColor','r',...
   'string',num2str(n),'fontsize',14);
Sk=['z=x(1:3)+y(1:3)*i;',...              % 画圆
      'z1=z(2)-z(1);c1=mean(z(1:2));',...
      'z3=z(3)-z(2);c3=mean(z(2:3));',...
      'C(1,1)=real(conj(z1)*c1);C(2,1)=real(conj(z3)*c3);',...
      'P=[real(z1),imag(z1);real(z3),imag(z3)]\C;',...
      'zc=P(1)+P(2)*i;r=abs(zc-z(1));plot(zc+r*t,''r'');',...
      'axis([0,1,0,1]);axis equal;'];
uicontrol(gcf,'style','push',...
   'unit','normalized','position',[0.8,0.67,0.19,0.07],...
   'BackgroundColor',[0.6 0.6 0.6],'ForegroundColor','r',...
   'string','restart','fontsize',14,'callback',...
   ['x=[];y=[];n=0;','set(T,''string'',''0'');cla;']);
uicontrol(gcf,'style','push',...
   'unit','normalized','position',[0.8,0.57,0.19,0.07],...
   'BackgroundColor',[0.6 0.6 0.6],'ForegroundColor','r',...
   'string','lineto','fontsize',14,'callback',...
   'plot([x,x],[y,y]);text(P(1),P(2),''刘'')');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -