Search code examples
javamathprojectile

'Basic' Projectile Trajectories


I'm trying to recreate projectile trajectories in Java, however, I get stuck on some things. I've watched a lot of videos explaining formula's and stuff but they have a target in their equation and I do not. What I mean by this is that they have a range to calculate their bullet drop upon, but I'm trying to figure out how much the bullet will eventually drop.

What I am currently working with is:

dropDistance = (9,807 / 2) * t²

I am not mathematician whatsoever and I am literally stuck on this and I have no clue how to implement this when the range of the target is unknown. It's supposed to work in 3D space (x,y,z) but I think only the Y is needed in the formula?


Solution

  • This is a simple physics problem.

    You need to begin with Newton's second law of motion. You've heard of it, but the important bit is that really three equations, because force and acceleration are vectors:

    force = mass*acceleration
    

    Simplify your problem by starting with two dimensions. In that case this is two equations:

    Fx = m*ax = 0 (no force in x-direction; ignore drag)
    Fy = m*ay = -m*g
    

    Solving for ay:

    ay = -g = constant (9.8 m/sec^2)
    

    You know from calculus that ay = dvy/dt and vy = duy/dt. Integrate twice to get the position uy as a function of time:

    uy = -(g*t^2)/2 + c0*t + c1
    

    You also need ux:

    ax = dvx/dt = 0
    

    Integrating twice:

    ux = c2*t + c3
    

    Substitute initial conditions to evaluate constants.

    Stop watching videos and read an intro physics text.