Help with gravity animation!
Show older comments
Hi,
I have been using MATLAB for a couple weeks now and I would love to try to animate something to do with gravity.
I have tried to animate a line (e.g. canonball) thrown starting from x = 0 and y = 0, (0,0), with a beginning velocity and throwing angle.
I tried to animate the line starting from (0,0) until it hits the ground but when I save and press Run, the figure opens but nothing happens.
Can someone help me understand what I am doing wrong? I have no clue what I am doing.
function animation = gravity()
g = 9.82; %g-constant
v0 = 35; %starting velocity
alpha = 50; %angle
picNr = 0; %picture number starts at 0 (for animation)
y = @(t)v0*t*sind(alpha)-0.5*g*t.^2; %throwing motion y-axis
x = @(t)v0*t*cosd(alpha); %throwing motion x-axis (constant velocity)
T = v0*sind(alpha)/(0.5*g); %time it takes for the "ball" to hit the ground
for t = linspace(0,T,100)
picNr = picNr + 1;
plot(x(t),y(t),'b--','LineWidth',5,'MarkerSize',12);
axis([-5 150 -5 45]);
animation(picNr) = getframe;
end
Any help would be deeply appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!