Skip to content

Instantly share code, notes, and snippets.

@jaz303
Last active May 10, 2016 11:28
Show Gist options
  • Save jaz303/e4e3bc9c5667259c3bcc5267763e2464 to your computer and use it in GitHub Desktop.
Save jaz303/e4e3bc9c5667259c3bcc5267763e2464 to your computer and use it in GitHub Desktop.
Integrating distance with damping

I'm trying to calculate the total distance travelled by an object with a known initial velocity and a damping factor that is applied to the velocity at each timestep. The iterative solution is easy:

// timestep and damping are constant
// v is velocity
// d is total distance
while (Math.abs(v) > 0.001) {
	d += timestep * v;
	v *= damping;
}

I'd like to do this in a single step using numeric methods rather than iteration but I don't know how to integrate a function which contains a recurrence relation (i.e. v_n+1 = damping * v_n), plus my algorithm brushes aside the fact that the damping factor should also probably relate somehow to the timestep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment