Jump to content
  • Advertisement
Sign in to follow this  
JakeM

best time step?

This topic is 4830 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Aside from experimentation, is there a mathematical way to determine the best fixed time step for a physics spring simulation?

Share this post


Link to post
Share on other sites
Advertisement
the best time step is infinitely small, so 1/infinity. don't try to implement that though, you'll get roundoff error ;)


on a more serious note, a better idea might be to average out the time it's taken to do your physics loop over the last 3-15 trials (depending on how fast you wish your timestep's response to be) and use that as your dt. of course, however, that falls into the category of experimentation... that and you also have to set some default values so that the program doesn't go balistic before the average is up and running

Share this post


Link to post
Share on other sites
My model could be low poly or high poly, and that would change how long the simulation runs, but
not the physics involved, so I don't see the reason why I would base the timestep value on the length
of the simulation?

Share this post


Link to post
Share on other sites
Suppose the force in the spring is described by

F= -k x

where k is the spring constant and x is the displacement from equilibrium. Then we can write

F = m a = m x''

where m is the mass of the oscillating thing, a is acceleration, and x'' is the 2nd derivative of x with respect to time. This gives you the following differential equation

m x'' = -k x

or,

x'' = -(k / m) x.

Now, the units of k are Mass/Time^2 so the units of (k / m) are 1/Time^2. From this you can get a timscale for the spring, i.e.

t* = sqrt(m / k)

is the characteristic timescale of the spring.

RULE OF THUMB: Use a timestep that is 1/10th the characteristic timescale.

However, be warned that if you have to integrate for a long time you will need to be careful that the integration method you use is appropriate. Alternatively, the exact solution to this equation is

x(t) = x(0) cos(w t) + (x'(0)/w) sin(w t)

where w = sqrt(k / m), x(0) is the initial displacement, and x'(0) is the initial velocity.


-Josh







Share this post


Link to post
Share on other sites
Quote:
Original post by JakeM
My model could be low poly or high poly, and that would change how long the simulation runs, but
not the physics involved, so I don't see the reason why I would base the timestep value on the length
of the simulation?


When you integrate numerically you are approximating the solution and that results in an error at each timestep. The more timesteps you take, the greater the error you accumulate, i.e. roundoff error as Uthman said.


-Josh

Share this post


Link to post
Share on other sites
There is no mathematically best time-step. It is a trade-off:
  1. A shorter time-step will result in a lower frame rate -- more time spent on physics, less time spent on graphics.
  2. A shorter time-step means less error due to approximation, but more error due to lack of floating-point precision.
Realistically, the error due to lack of floating-point precision is usually much less than the error due to approximation, so the real trade-off is a more accurate simulation vs. a better frame rate.

The absolute maximum time-step would be the average duration of a frame. What is the use of redrawing a frame if the simulation is the same as the last frame? However, a time-step of that duration might look jittery (especially with low frame rates), so half the average frame duration would be better.

Share this post


Link to post
Share on other sites
Though as others have said there is not necessarily a "best time step", in some cases there is a calculatable point at which the time step starts to go bad. Many numerical methods, e.g., Euler, Verlet, Runge-Kutta and others, are "conditionally stable." They require the time step to be within a given range (high or low), or otherwise the simulation will eventually overflow. The calculation is both problem dependent (heavy vs. light objects, big vs. small objects, etc.) and method-dependent (Euler vs. Verlet). The name given to the condition that defines the upper bound on a stable time step is the "Courant-Friedrichs-Levy" or "CFL" condition. It is a necessary, but not sufficient condition for simulation stability.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The maximum timestep can easily be longer than the average duration of a frame. You just need to be able to interpolate or extrapolate the motions of things when drawing. Interpolating or extrapolating is probably a lot cheaper than running a full physics step, so this can allow higher framerates without requiring more work from the physics engine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!