suffer 发表于 2006-5-8 08:26

[转帖]心形线动态生成演示

function =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();
axis manual
hold on
daspect();
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 编辑 ]
页: [1]
查看完整版本: [转帖]心形线动态生成演示