Wall Ball bounce Physics

Motion of the ballI nitial position:
x0=0,
y0=0.
Constant Velocity: Vx= Vcosθ and Vy= Vsinθ where V and θare user inputs
.Position as function of time:x(t) = x0+ Vxty(t) = y0+ VytIn an iterative calculation:
x(t+Δt) = x(t) + VxΔt
y(t+Δt) = y(t) + VyΔt
Collision DetectionSince the box is bounded by x=10, y=10, x=-10, and y=-10, a ball will be colliding with one of the walls when x(t)≥10, x(t)≤-10, y(t)≥10, or y(t)≤-10. When a collision occurs, the ball will be bouncing off the wall.(Make sure the red dot will not go outside the box.)

7 Comments

Okay....what is the question for us?
Haha guess I forgot that part. How do I actually display the ball ? and how do I know the t or time in the equation. Do I just set a bunch of variables ? 1:.01:20
or how do I accomplish the annimation ?
Hint: if a ball would bounce during this time step, do not simply reverse its velocity vector (or simply compute the correct angle of reflection.) You should calculate the distance it needs to travel to reach the wall, and the distance it travels back after the bounce should only be the "remaining" available distance that it would travel in a time step.
For example if your ball would normally travel 5 mm in one time step, and you calculate that it is 4 mm away from the wall, then after it hits the wall it should only travel (5-4) = 1 mm.
And remember that the angle of incidence equals the angle of reflection.
Constant velocity tells you that you do not have to worry about gravity or friction. With constant velocity, you know that the total distance traveled is velocity times time. But that doesn't tell you what path you followed.
How to display the dot? Well you might be interested in comet() or in animatedline() set to retain a small number of past positions. Or you might create a single dot with scatter() or plot() and continually update its XData and YData properties.
should I do this in a for or while loop ?
What is your stopping condition?
If you are required to do a particular number of time steps then use for
If you are required to stop when a condition is reached (e.g., 20 bounces), then use a while loop.
If you are required to go indefinitely until the user interrupts with control-C then use a while loop.

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Asked:

on 31 Jan 2021

Commented:

on 31 Jan 2021

Community Treasure Hunt

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

Start Hunting!