Equations to model tennis ball motion

Click For Summary
SUMMARY

This discussion focuses on modeling tennis ball motion using projectile equations while accounting for the ball's current velocity at the time of impact. The user has implemented a function in Swift to calculate the launch angle based on speed, distance, yOffset, and gravity, but encounters inaccuracies when the ball is already in motion. The conversation emphasizes the need to incorporate the ball's current velocity into the equations of motion and suggests researching ballistics equations that include air resistance and the Magnus force for more accurate modeling.

PREREQUISITES
  • Understanding of projectile motion equations
  • Familiarity with Swift programming language
  • Knowledge of basic physics concepts such as gravity and velocity
  • Experience with algebraic manipulation of equations
NEXT STEPS
  • Research ballistics equations that include air resistance and the Magnus force
  • Learn about advanced projectile motion modeling techniques
  • Explore physics simulation libraries in Swift for accurate motion representation
  • Study the mathematical derivation of projectile motion equations with initial velocity
USEFUL FOR

Game developers, physics enthusiasts, and anyone interested in accurately modeling projectile motion in simulations or games.

mariano_donat
Messages
8
Reaction score
0
I'm creating a tennis game and at this point I'm trying to model ball motion. I found multiple lectures on projectiles equations of motion which seem to apply well for when ball is not moving, but they do not take into account the velocity may have at the time of impact. For example, I found a function that gives me the angle of launch so ball can impact a target point at a given speed. If the ball is not moving, it works well, however if it is, it yields incorrect results. So how would one go about plugging current velocity in projectile equations of motion? For reference, this is how the function to calculate the angle looks like:

Code:
func launchAngle(speed: Float, distance: Float, yOffset: Float, gravity: Float, angle0: inout Float, angle1: inout Float) -> Bool {
        angle0 = 0
        angle1 = 0
  
        let speedSquared = speed * speed
        let operandA = powf(speed, 4)
        let operandB = gravity * (gravity * (distance * distance) + (2 * yOffset * speedSquared))
  
        if operandB > operandA {
            return false
        }
  
        let root = sqrt(operandA - operandB)
  
        angle0 = atan((speedSquared + root) / (gravity * distance))
        angle1 = atan((speedSquared - root) / (gravity * distance))
  
        return true
    }
 
Physics news on Phys.org
If I were doing this, I would first get the equations right and then launch into the coding. Trying to do it all in one step is likely to be fraught, particularly if you are discussing the problem with a third party. The first thing anyone on PF would need to do is to unpack your code and write it in algebraic form so it would be the courteous thing to present your question in algebraic form.
Have you done any searching on Google for ballistics with air resistance included? There are hundreds of hits with the equations in.
 
For now, I was neglecting air resistance + Magnus force to keep things simple. Equations are right, it's just that I don't seem to be able to find those taking into account ball's current velocity. All of them act from the perspective of "launching" a projectile in rest. I've been watching Sebastian Lague videos on youtube which were really helpful to get the basic equations to work, but even those do not contemplate current motion. So yes, I've been searching/reading a lot for the last couple of weeks and still couldn't find such equations. Doing a search with ballistics also does not seem to yield equations taking this into account.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 45 ·
2
Replies
45
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
6K