Points moving along a curve within MATLAB

前端 未结 1 827
清酒与你
清酒与你 2020-12-20 23:09

I have managed to edit a piece of code that was given to me in order to show a point moving along a curve.

I am trying to find a way to edit this in order to create

相关标签:
1条回答
  • 2020-12-20 23:18

    Here's how you can add another point that starts sliding from the end independent of the first point.

    In your code, before the line %#Infinite loop, add the following:

    hLine2 = line('XData',x(end), 'YData',y(end), 'Color','g', ...  
            'Marker','o', 'MarkerSize',6, 'LineWidth',2);  
    hTxt2 = text(x(end), y(end), sprintf('(%.3f,%.3f)',x(1),y(1)), ...  
        'Color',[0.2 0.2 0.2], 'FontSize',8, ...  
        'HorizontalAlignment','left', 'VerticalAlignment','top');  
    

    and inside the loop, before the drawnow command, add the following:

    set(hLine2, 'XData',x(end-i), 'YData',y(end-i))     
        set(hTxt2, 'Position',[x(end-i) y(end-i)], ...  
            'String',sprintf('(%.3f,%.3f)',[x(end-i) y(end-i)]))   
    

    So your second point slides down and the first slides up. You can define the trajectory for the point as you wish in the definition of hLine2 and hTxt2 enter image description here

    0 讨论(0)
提交回复
热议问题