A bouncing circle on a 2d plot, how to plot a cos2 function

1 vue (au cours des 30 derniers jours)
Bryan Shivram
Bryan Shivram le 23 Nov 2020
Hello! I need some help with trying to form a cos^2 function, I'm trying to have it go from y= 30 to 0, however it only goes from 30 to 15. Any help would be greatly appreciated.
r=1;
hmax= 28;
n =1000;
h= linspace(0,hmax,n);
t= linspace(0,360,n);
k = 0;
pt= 1/6000;
x= zeros(length(h),length(t));
y=x;
a=r+h;
b= r+hmax/2*(cosd(t).^2)+hmax/2;
for i= 1:n
x(i,:) = a(i)+r.*cosd(t);
y(i,:)= b(i)+r.*sind(t);
end
figure(1)
ball_bounce= plot(x,y,'b');
axis([0 30 0 30])
grid on
while k < 10
if rem(k,2) == 0
for i = 1:n
set(ball_bounce,'XData',x(i,:),'YDATA',y(i,:));
pause(pt)
end
end
if k>10
break
end
end

Réponses (1)

Nora Khaled
Nora Khaled le 23 Nov 2020
In your code you have
b= r+hmax/2*(cosd(t).^2)+hmax/2;
which I think is the trajectory of the ball. and if you plot it you get an ocillation between 30 and 15.
try this
b= hmax*(cosd(t).^2);

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by