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

KSSV
KSSV 2021년 1월 31일
Okay....what is the question for us?
gracias claude
gracias claude 2021년 1월 31일
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
gracias claude
gracias claude 2021년 1월 31일
or how do I accomplish the annimation ?
Walter Roberson
Walter Roberson 2021년 1월 31일
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.
Walter Roberson
Walter Roberson 2021년 1월 31일
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.
gracias claude
gracias claude 2021년 1월 31일
should I do this in a for or while loop ?
Walter Roberson
Walter Roberson 2021년 1월 31일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2021년 1월 31일

댓글:

2021년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by