Calculating Ball Trajectory in Basketball Simulation Game

  • Context: Undergrad 
  • Thread starter Thread starter Quasker
  • Start date Start date
  • Tags Tags
    Ball Trajectory
Click For Summary

Discussion Overview

The discussion revolves around calculating the trajectory of a basketball in a simulation game, focusing on the mathematical modeling of the ball's motion frame by frame. Participants explore the effects of gravity, drag, and other forces on the ball's trajectory, considering both simplified and more complex models.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant proposes calculating horizontal and vertical positions using basic trigonometric functions based on initial velocity and angle.
  • Another participant explains the influence of gravity as a constant downward force, providing equations for vertical and horizontal motion under constant acceleration.
  • A third participant introduces the concept of drag, noting that it complicates the calculations by requiring a numerical solution for the drag equation.
  • Further, a participant emphasizes that drag fundamentally alters the trajectory calculations and suggests that additional factors like ball spin and wind should also be considered for a realistic model.
  • In response to the complexity introduced by drag and other factors, one participant expresses a preference for a simplified model that only accounts for gravity.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to modeling the ball's trajectory. There are competing views on whether to include drag and other external factors, with some advocating for a simplified model while others highlight the importance of a more comprehensive approach.

Contextual Notes

The discussion includes assumptions about constant gravity and the potential need for additional variables, such as drag coefficients and external forces, which remain unresolved. The implications of these factors on the trajectory calculations are acknowledged but not fully explored.

Quasker
Messages
2
Reaction score
0
So I'm making a little basketball simulation game and I need a good way to calculate the path of a ball. I want to do this on a frame by frame basis where one frame lasts about 50 milliseconds. Each frame will store values for the state of the ball and then after applying some math, those values will be changed for the next frame.

So right now I have the horizontal and vertical positions, velocity, mass, and angle. I can add more variables if needed, these are just the first ones to come to my mind.

I think I can calculate the horizontal and vertical positions with something like this:
horizontal : newX = oldX + (oldVelocity * cos(angle))
vertical : newY = oldY + (oldVelocity * sin(angle))

If that is not a good way to do it, then let me know, it's just what I thought of with my limited physics knowledge.

I have no clue though how gravity and drag would factor in. I think the angle of the ball and the velocity should change from frame to frame, I just don't know how.

So, assuming a constant gravity, what would be a good way to make these calculations?

Thanks!
 
Physics news on Phys.org
Welcome to PF Quasker!

You can assume that gravity is a constant force that acts vertically downward. It causes an acceleration g, where g = 9.81 m/s2. In case you don't know, acceleration is just the rate of change (increase or decrease) of velocity, so this number is saying that gravity causes the downward velocity of the object to increase by 9.81 meters per second (m/s) every second. So the acceleration is the change in velocity divided by the time, which is 9.81 (m/s)/s = m/s2. Let's say the vertical position is denoted using the coordinate y. In the case of constant acceleration, the general equation for position vs. time is:

y = y0 + v0yt + (1/2)ayt2

where y0 is the initial vertical position (at t = 0), v0y is the initial vertical speed, and ay is the acceleration in the vertical direction. In this particular case, we have ay = -g, with the minus sign arising because the acceleration is downward. So the equation becomes:

y = y0 + v0yt - (1/2)gt2

The most general equation for the horizontal position, x, vs. time of the object under a constant acceleration would be:

x = x0 + v0xt + (1/2)axt2

HOWEVER, in this case, we have ax = 0. There is no horizontal component to the acceleration, because there are no forces acting in the x-direction, and Newton's Second Law says that a net force is required to cause an acceleration. Therefore, in this case, the equation reduces to:

x = x0 + vxt​

where vx = v0x is the (constant) horizontal speed.

If v is the total speed, then the horizontal and vertical components are given, respectively, by the equations

vx = vcosθ
vy = vsinθ​

where θ is the angle of the ball's velocity vector, measured from the horizontal. Now, you mentioned that you knew the *initial* value for θ, but not the subsequent values. Well, you can figure them out if you need to, because vx is constant, and vy varies with time in a well-defined way. Remember that acceleration is just the rate of change of velocity. Therefore, the change in velocity is going to be the rate of change with time, multiplied by the total time elapsed. E.g. if my acceleration is a rate of1 m/s per second, then to figure out how much my speed would have increased (starting from 0) after 3 seconds, I'd just multiply the rate by the time interval: 1 (m/s)/s * 3 s = 3 m/s. This makes perfect sense. Since my speed increases by 1 m/s every second, after three seconds it will have gotten up to 3 m/s (assuming I started at 0). Stating this mathematically:

v = v0 + at​

The velocity at time t is the initial velocity plus the change in velocity, which, as I just explained, is the acceleration times the time interval. So, for our vertical velocity, this would become:

vy = v0y - gt​
 
You also mentioned drag, which cepheid didn't cover. You can take the drag as a force proportional to the square of the speed, and acting in direct opposition to the direction of travel. This is makes things a bit more complicated, because now you can't treat the horizontal and vertical components of velocity as independent.
 
Drag does not just make it a bit more complicated, it changes the game completely. Taking drag into account requires solving numerically the drag equation from frame to frame. Not to mention that an accurate drag coefficient must be known.

A realistic model would also need to take the spin of the ball into account, wind, etc. And we end up with the problem of external ballistics.
 
Thanks for the replies, very informative. After reading a couple of the replies, I think it will probably be best to use a simplified model that doesn't consider air resistance, ball spin, etc. I guess the only external force would be gravity.
 

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 45 ·
2
Replies
45
Views
5K