5
我已经设法编辑了一段代码,该代码为了显示沿着曲线移动的点而给予了我。沿着MATLAB中的曲线移动的点
我试图找到一种方法来编辑这个,以便创建两个独立的点沿着这条曲线移动,或者创建另一个显示沿着图形移动的点的第二个图形。 重点是这些点需要彼此独立,以便可以将算法应用于它们。
目前,我有以下代码给出了一个单点沿曲线移动:
%# control animation speed
DELAY = 0.01;
numPoints = 600;
%# create data
x = linspace(0,1,numPoints);
f = 5;
C = 1-exp(-f);
y = C*(1-(exp(-f*x)));
%# plot graph
figure('DoubleBuffer','on') %# no flickering
plot(x,y, 'LineWidth',2), grid on
xlabel('x'), ylabel('y'), title('')
%# create moving point + coords text
hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ...
'Marker','o', 'MarkerSize',6, 'LineWidth',2);
hTxt = text(x(1), y(1), sprintf('(%.3f,%.3f)',x(1),y(1)), ...
'Color',[0.2 0.2 0.2], 'FontSize',8, ...
'HorizontalAlignment','left', 'VerticalAlignment','top');
%# infinite loop
i = 1; %# index
while true
%# update point & text
set(hLine, 'XData',x(i), 'YData',y(i))
set(hTxt, 'Position',[x(i) y(i)], ...
'String',sprintf('(%.3f,%.3f)',[x(i) y(i)]))
drawnow %# force refresh
%#pause(DELAY) %# slow down animation
i = rem(i+1,numPoints)+1; %# circular increment
if ~ishandle(hLine), break; end %# in case you close the figure
end