本文基于MATLAB,采用两种方式绘制圆,一种是直角坐标系下plot(x,y)绘制圆,另外一种是极坐标系下polar(theta,rho)绘制圆。
工具/原料
1
MATLAB
2
plot
3
fill
4
polar
方法/步骤
1
第一,启动MATLAB,新建脚本(Ctrl+N),输入以下代码:close all; clear all; clcr=2; theta=0:pi/100:2*pi;x=r*cos(theta); y=r*sin(theta);rho=r*sin(theta);figure(1)plot(x,y,'-')hold on; axis equalfill(x,y,'c')figure(2)h=polar(theta,rho);set(h,'LineWidth',2)
2
第二,保存和运行上述脚本,在figure(1)中得到plot(x,y)和fill(x,y)绘制的圆。
3
第三,保存和运行上述脚本,在figure(2)中得到polar(theta,rho)绘制的圆。
4
第四,可以将plot(x,y),polar(x,y)绘制的圆画在一张图上,只需要接着输入以下代码:figure(3)subplot(1,2,1);plot(x,y,'-');hold on; axis squarefill(x,y,'c')subplot(1,2,2);h=polar(theta,rho);set(h,'LineWidth',2)
5
第五,保存和运行上述增加后的脚本,在figure(3)中将plot(x,y),polar(x,y)绘制的圆画在了一张图上。