2017-12-13 35 views
0

跳ねるボールの軌道をマッピングする次のコードを作成しました。私は軌道に沿って移動するポイントを作成しようとしています。コードは機能しますが、アニメーションは再生されません。Matlab:跳ねるボールのアニメーションを再生できません

私は学部生ですが、コードはエレガントではありません。 (コードを改善したり、私を新しい方向に向けるためのヒントがある場合は、お勧めすることを恐れてはいけません。)

アニメーションを動作させるにはどうすればよいですか?

syms xdis(t1) ydis(t1) ydis1(t1) xdis1(t1) xdis2(t1) ydis2(t1) xdis3(t1)... 
    ydis3(t1) xdis4(t1) ydis4(t1) xdis5(t1) ydis5(t1) xdis6(t1) ydis6(t1) 

dt = 0.05; 
tmax = 6; 
t = 0:dt:tmax ; 

height=10; 
velocity=12; 
angle=0; 
g=-9.8; 
xpos = 0 ;      
ypos = height;     
xvel = velocity*cosd(angle);  
yvel = velocity*sind(angle); 
xdis(t1)= xvel*t1+xpos; 
ydis(t1)=yvel*t1+0.5*g*t1^2+ypos; 

troot1=solve(ydis(t1)==0,t1); 
troot11=vpa(troot1(1)); 
troot12=vpa(troot1(2)); 


dydis(t1)=diff(ydis(t1),t1); 
p=solve(dydis(t1)==0,t1); 
h=vpa(ydis(p)); 


i1=vpa(dydis(troot11)); 

yvel1=0.7*i1; 
ypos1=0; 
ydis1(t1)=yvel1*t1+0.5*g*t1^2; 
xdis1(t1)=xvel*t1+xdis(vpa(troot12)); 

troot2=solve(ydis1(t1)==0,t1); 
troot21=(troot2(1)); 
troot22=(troot2(2)); 

dydis1(t1)=diff(ydis1(t1),t1); 
p1=solve(dydis1(t1)==0,t1); 
i2=vpa(dydis1(troot21)); 
yvel2=0.7*i2; 

ydis2(t1)=yvel2*t1+0.5*g*t1^2+ypos1; 
xdis2(t1)=xvel*t1+vpa(xdis1(troot22)); 

troot3=solve(ydis2(t1)==0,t1); 
troot31=troot3(1); 
troot32=troot3(2); 

dydis2(t1)=diff(ydis2(t1),t1); 
p2=solve(dydis2(t1)==0,t1); 
i3=vpa(dydis2(troot31)); 
yvel3=0.7*i3; 

ydis3(t1)=yvel3*t1+0.5*g*t1^2+ypos1; 
xdis3(t1)=xvel*t1+vpa(xdis2(troot32)); 

troot4=solve(ydis3(t1)==0,t1); 
troot41=troot4(1); 
troot42=troot4(2); 

dydis3(t1)=diff(ydis3(t1),t1); 
p2=solve(dydis3(t1)==0,t1); 
i4=vpa(dydis3(troot41)); 
yvel4=0.7*i4 

ydis4(t1)=yvel4*t1+0.5*g*t1^2+ypos1; 
xdis4(t1)=xvel*t1+vpa(xdis3(troot42)); 

troot5=solve(ydis4(t1)==0,t1); 
troot51=troot5(1); 
troot52=troot5(2); 

dydis4(t1)=diff(ydis4(t1),t1); 
p2=solve(dydis4(t1)==0,t1); 
i5=vpa(dydis4(troot51)); 
yvel5=0.7*i5; 

ydis5(t1)=yvel5*t1+0.5*g*t1^2+ypos1; 
xdis5(t1)=xvel*t1+vpa(xdis4(troot52)); 

troot6=solve(ydis5(t1)==0,t1); 
troot61=troot6(1); 
troot62=troot6(2); 



o=troot12-0; %% xdis(1) ydis(1) 
o1=troot22-troot21; %% xdis1 ydis1 
o2=troot32-troot31; %% xdis2 ydis2 
o3=troot42-troot41; %% xdis3 ydis3 
o4=troot52-troot51; %% xdis4 xdis4 
o5=troot62-troot61; 

int1=o; 
int2=o+o1; 
int3=o+o1+o2; 
int4=o+o1+o2+o3; 
int5=o+o1+o2+o3+o4; 
int6=o+o1+o2+o3+o4+o5; 


kt=0.05; 
kmax=6; 
k=0; 
while k<kmax 
    if 0<=k && k<=int1 
    s1(k/0.05+1)=vpa(xdis(k)); 
    s2(k/0.05+1)=vpa(ydis(k)); 
    elseif int1<k && k<=int2 
    s1(k/0.05+1)=vpa(xdis1(k-int1)); 
    s2(k/0.05+1)=vpa(ydis1(k-int1)); 
    elseif int2<k && k<=int3 
    s1(k/0.05+1)=vpa(xdis2(k-int2)); 
    s2(k/0.05+1)=vpa(ydis2(k-int2)); 
    elseif int3<k && k<=int4 
    s1(k/0.05+1)=vpa(xdis3(k-int3)); 
    s2(k/0.05+1)=vpa(ydis3(k-int3)); 
    elseif int4<k && k<=int5 
    s1(k/0.05+1)=vpa(xdis4(k-int4)); 
    s2(k/0.05+1)=vpa(ydis4(k-int4)); 
    elseif int5<k && k<=int6 
    s1(k/0.05+1)=vpa(xdis5(k-int5)); 
    s2(k/0.05+1)=vpa(ydis5(k-int5)); 
    end 
    k=k+kt; 
end 


figure(1) 
for t=1:1:length(s2) 
plots{t}=plot(s1(t),s2(t),'ro','MarkerSize',10); 
axis([0 xvel*6 0 h]) 
pause(0.001) 
end 
+0

を、それを使用したい場合は、あなたのアニメーションループにon'の保持 '欠けている倍増するシンボリック変数hを変換する必要がありますか?私はあなたのプロットが前のプロットを上書きしていると推測して、最後のプロットしか見ることはできません。もしそうなら、 'forループ'の直前に 'hold on 'を追加してください。 –

+0

forループの前に 'hold on'を追加しましたが、動作しませんでした。 – user125918

答えて

2

あなたが関数の内部axis

figure(1) 
for t=1:1:length(s2) 
    plots{t}=plot(s1(t),s2(t),'ro','MarkerSize',10); 
    axis([0 xvel*6 0 double(h)]) 
    pause(0.001) 
end 
+0

それは働いた!ありがとうございました。 – user125918

+0

円の複製を停止する機能はありますか? – user125918

+0

あなたは元の投稿へのコメントで、あなたが「ホールドオン」を追加したと言った。削除してみてください –

関連する問題