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