How do get a ball bounces off the wall?

5 views (last 30 days)
chae lin lee
chae lin lee on 24 Mar 2019
Answered: Image Analyst on 24 Mar 2019
How do get a ball bounces off the wall?
The ball has to bounce off the wall. Help me.
The code I made is as follows.
clc,clf,clear
v0=10;
t(1)=0;x=0;y=0;
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 10 0 40])
M(1)=getframe;
dt=1/32;
open(v);
for i = 2:1000
t(i)=t(i-1)+dt;
x=t(i);
y=v0*t(i);
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 10 0 40])
M(i)=getframe;
writeVideo(v,M(i));
if y>=40, break, end
end
close(v);

Answers (1)

Image Analyst
Image Analyst on 24 Mar 2019
Basically, just reflect it
yMax = 40;
if y > yMax
distanceBeyond = y - yMax;
y = yMax - distanceBeyond;
end

Categories

Find more on Graphics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!