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

3 views (last 30 days)
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

Answers (1)

Nora Khaled
Nora Khaled on 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);

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!