Animate CO2 motor in MATLAB

后端 未结 1 580
萌比男神i
萌比男神i 2021-01-26 10:15

I am trying to recreate this engine in Matlab: http://www.animatedengines.com/co2.html. I am looking to use handle graphics in order to animate all of the moving parts. I have

1条回答
  •  孤街浪徒
    2021-01-26 11:16

    Here's an example for a small circle moving around a larger circle:

    %# create large-circle coordinates
    t = 0:pi/100:2*pi;
    xc = cos(t);
    yc = sin(t);
    
    %# create small-circle coordinates
    xs = 0.1*cos(t);
    ys = 0.1*sin(t);
    
    %# plot large circle
    figure,plot(xc,yc,'r');
    
    %# plot small circle at first position
    %# and capture handle
    smallCircleH = plot(xs+xc(1),ys+yc(1),'b');
    
    %# loop to update the handle of the small circle
    for tIdx = 1:length(t)
       %# update position of small circle
       set(smallCircleH,'xData',xs+xc(tIdx),'yData',ys+yc(tIdx));
       %# wait a bit to appreciate the beauty
       pause(0.1);
    end
    

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