Math/Physics question: Formula for acceleration given distance

I’m looking for a formula to use for some physics calculations.

I have:
-an initial starting velocity
-a final velocity (zero)
-the distance it needs to take to go from starting velocity to ending velocity

I want to find:
-the rate of acceleration needed to go make that change in velocity across that specified distance.

I tried looking this up online but none of them were giving me formulas for solving what I need with what I have.

Are you assuming the rate of acceleration is constant? If so,

A = (v(T) - v0) / T = (V(T) - v0) / T = - v0 / T

where T is the time it takes for v0 (initial velocity) to reduce to v(T) (= 0, final velocity), and A is the constant rate of acceleration (which is negative if v0 > 0, hence is really deceleration).

If the rate of acceleration is constant, then the position of the object is given by a quadratic, like

p(t) = p0 + v0 * t + 0.5 A t^2

You said you know the distance, D, which must equal p(T) - p0, so

D = v0 * T + 0.5 * A T^2

which gives

T = (-v0 + sqrt(v0^2 + 2 * A * D) ) / A

substituting into the first equation and simplifying yields

v0^2 + 2 * A * D = 0 =>

A = - 0.5 v0^2 / D

Kinematics! if we know 3 of the 5 we can find the other two.

  • Initial Velocity (known)
  • Final Velocity (known)
  • Distance (known)
  • Acceleration (??)
  • Time (??)

Since we know 3 of the 5, we can solve for the other two. There are four kinematic equations on this page:

Find the equation that takes your 3 known variables and has acceleration as the only unknown variable.

NOTE: This is for one dimension! If you are in multi-dimensions, then you have to solve these equations for each dimension separately.

@GarthSmith
Those equations seem to be exactly what I needed!
Except when I actually plugged them into my code, the acceleration it produced was WAY underpowered; it felt like something between 30 -100 times too low.

In the start function I have:
acceleration = Mathf.Abs((maxSpeed * -1) / decelDist / 2);

And in my update function I have:

float distX = target.x - transform.position.x;
           
            if (distX > 0) {
               
                xVel += acceleration * Time.deltaTime;
                if (xVel >= maxSpeed) {
                    xVel = maxSpeed;
                    bFullSpeed = true;
                    Debug.Log("Full speed engaged!");
                }
            }
            else {
               
                xVel -= acceleration * Time.deltaTime;
                if (xVel <= maxSpeed * -1) {
                    xVel = maxSpeed * -1;
                    bFullSpeed = true;
                    Debug.Log("Full speed engaged!");
                }
            }

The design is that the object is supposed to proceed at full speed until it it called to turn the other direction. Then it executes this code each frame, causing it to accelerate in the opposite direction. (Once it hits full speed I run different code.) The distance I give it (decelDist) is the distance I want it to travel before it reaches its apex and starts moving in the opposite direction.
It functions correctly; it does move a specific distance before reaching that apex, and I can adjust that distance. It’s just that distance is a good 50 times or more what I thought I was setting it to.

So I’m getting this equation for acceleration. Notice that velocities are getting squared.

a = (Vf^2 - Vi^2) / 2 / d
acceleration = (Final Squared - Initial Squared) / (2*distance)

Took a simpler route (than I used the first time, which must’ve been riddled with errors) to solving for A and got the same thing as Garth. That’s certainly the appropriate formula.

D’oh! I totally dropped a square, you’re right!

Okay it’s working now, thanks a lot!

1 Like