马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
- function [xcar,ycar]=drawcardioid(varargin)
- % A demonstration to show the form of the cardioid
- error(nargchk(0,3,nargin));
- nin = nargin;
- if nin==0
- cx1=0; cy1=0; % The coordinate of the center point.
- r=1; % The radius of the circle.
- elseif nin==1
- cx1=0; cy1=0;
- r=varargin{1};
- elseif nin==2
- cx1=0;
- cy1= vararin{1};
- r = varargin{2};
- else
- cx1=vararin{1};
- cy1=vararin{2};
- r=vararin{3};
- end
- if nargout==0
- flag=1;
- else
- flag=0;
- end
- theta = linspace(0,2*pi,120);
- x0 = r*cos(theta);
- y0 = r*sin(theta);
- x1 = x0+cx1;
- y1 = y0+cy1;
- cx2 = 2*x0+cx1;
- cy2 = 2*y0+cy1;
- x3=x0.*cos(theta)-y0.*sin(theta);
- y3=x0.*sin(theta)+y0.*cos(theta);
- for k=1:120
- x2(k,:) = cx2(k)+x0;
- y2(k,:) = cy2(k)+y0;
- xx(k)=cx2(k)+x3(k);
- yy(k)=cy2(k)+y3(k);
- end
- xcar = xx;
- ycar = yy;
- if flag
- plot(x1,y1);
- axis([cx1-3.2*r cx1+3.2*r cy1-3.2*r cy1+3.2*r]);
- axis manual
- hold on
- daspect([1 1 1]);
- set(gcf,'doublebuffer','on');
- for k = 1:120
- plot(x2(k,:),y2(k,:),'g',xx(k),yy(k),'r*');
- pause(0.05);
- %plot(x2,y2,'color','w');
- end
- end
复制代码
来自山城棒棒儿
[ 本帖最后由 suffer 于 2006-10-9 20:10 编辑 ] |