英语翻译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 n
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 10:08:12
英语翻译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 n
英语翻译
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
英语翻译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 n
上述matlab程序代码执行效果如下图所示:
原理是:一个动圆沿一个定圆的圆周外部无滑动的滚动(两个圆的半径相等),动圆的圆周上的一固定点运动的轨迹就是心形线.
本人对matlab不是很熟悉,直接调用心形线参数方程写的.
源码: