资源简介

信号与系统实践作业。matlab仿真星系运动,还用流星、彗星等随机出现并划过

资源截图

代码片段和文件信息

function starmodel(N)
N=100;
figure(‘Color‘[0 0 0]);
view(gca-3718)
axis equal;
t=(0:0.001:1)*2*pi;
x1=10*cos(t)-6;y1=8*sin(t);z1=zeros(size(x1));
x2=4*cos(2*t);z2=4*sin(2*t);y2=zeros(size(x2));
x3=20*cos(t);y3=20*sin(t);z3=zeros(size(x1));
x=[x1 x2];y=[y1 y2];z=[z1 z2];
plot3(x1y1z1‘w‘x2y2z2‘w‘x3y3z3‘w‘) ;
axis off
h0=line(‘Color‘‘r‘‘Marker‘‘.‘‘MarkerSize‘100‘EraseMode‘‘Xor‘);%恒星
set(h0‘xdata‘0‘ydata‘0‘zdata‘0);
h1=line(‘Color‘‘g‘‘Marker‘‘.‘‘MarkerSize‘40‘EraseMode‘‘Xor‘);%行星1
h11=line(‘Color‘[0.49 1 0.83]‘Marker‘‘.‘‘MarkerSize‘50‘EraseMode‘‘Xor‘);%行星2
h2=line(‘Color‘‘y‘‘Marker‘‘.‘‘MarkerSize‘30‘EraseMode‘‘Xor‘);%行星3
h3=line(‘Color‘[0.75 0 0.75]‘Marker‘‘.‘‘MarkerSize‘20‘EraseMode‘‘Xor‘);%卫星(行星2的)
hh=zeros(100);%星星的句柄矩阵 
hlx=line(‘Color‘[1 1 1]‘Marker‘‘h‘‘MarkerSize‘7‘EraseMode‘‘Xor‘);%流星!
set(hlx‘Color‘[0 0 0]‘xdata‘10‘ydata‘10‘zdata‘10);
text(-3106‘行星绕恒星运动示意图‘‘color‘‘w‘‘fontsize‘15);
text(-383‘轨道1‘‘color‘‘w‘);
text(4-4‘轨道2‘‘color‘‘w‘);
text(-5-352‘轨道3‘‘color‘‘w‘);
set(gcf‘doublebuffer‘‘on‘)  %消除抖动

i=1;k=1;
judge=0;     

while 1
    set(h1‘xdata‘x1(i)‘ydata‘y1(i)‘zdata‘z1(i));
    set(h2‘xdata‘x2(i)‘ydata‘y2(i)‘zdata‘z2(i));
    set(h11‘xdata‘x3(i)‘ydata‘y3(i)‘zdata‘z3(i));
    set(h3‘xdata‘2*cos(i/150*2*pi)+x3(i)‘ydata‘y3(i)‘zdata‘2*sin(i/150*2*pi)+z3(i));
    drawnow;
    pause(0.0005);
    i=i+1;
    ii=fix(i/100);
    if judge==0
        judge=1;
        set(hlx‘Color‘[1 1 1]);
        poslx=rand(13)*30-15;
        cslx=rand(13)*0.6-0.3;
    end
    if (judge>0)&&(judge<200)
        set(hlx‘xdata‘poslx(1)‘ydata‘poslx(2)‘zdata‘poslx(3))
        poslx(1)=  poslx(1)+cslx(1);
        poslx(2)=  poslx(2)+cslx(2);
        poslx(3)=  poslx(3)+cslx(3);
        judge=judge+1;  
    end 
    if judge==200
         set(hlx‘Color‘[0 0 0]);
        judge=0; 
    end
    if i/100-ii==0
        if hh(ii)==0
        hh(ii)=line(‘Color‘[1 1 1]‘Marker‘‘p‘‘MarkerSize‘6‘EraseMode‘‘Xor‘);%Stars!
        end
         pos=rand(3)*40-20;
         set(hh(ii)‘xdata‘pos(1)‘ydata‘pos(2)‘zdata‘pos(3));  
    end
    if i>1000
        i=1;
        k=k+1;
    end
    if k>N 
        break ;
    end  
end




 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2382  2012-03-07 22:40  starmodel_team1.m

评论

共有 条评论