Jump to content
  • Advertisement
Sign in to follow this  

Another possible method for modeling springs with Euler's method

This topic is 3489 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

Now, as a disclaimer, this is based on my understanding of and limited experience with Euler's method. I recently took interest in trying to write something to model physics as a personal challenge and been looking at some resources as a guide. When I first came across an explanation of the complications in modeling springs, this solution instantly sprang to mind. I don't know if the physics is good, if the math is right, but its an interesting idea. I have yet to test an implementation of it. Hopefully someone here can give me insight or point out my mistakes. Euler's method isn't terrible. Its stable enough when the rate of change is linear. When acceleration is constant, using Euler's method to model movement is accurate enough. However springs are different. They present a problem because acceleration is not constant. However, the rate of acceleration is constant, what is known as the onset or jerk. Modeling springs on their jerk, however, take up back to linear rate of change equations that work much better under Euler's method. Here's some math, sorry for the sloppy formatting. Hooke's Law: F = -kp where p is position a = -1/m kp j = (DELTA a) / (DELTA t) where j is the jerk; a change in acceleration j = ((-kp_i / m) - (-kp_f / m)) / (DELTA t) where p_i is the initial position and p_f is final j = (-k)/(DELTA t m) * (p_f - p_i) j = (-k)/(DELTA t m) * (DELTA p) since p_f - p_i is the change of position DELTA p = -( DELTA t * m ) / k * j now k and j are constants, because k was defined as such under Hooke's law and j because the rate of change of acceleration is constant. Therefore we can merge these two into a super constant, termed K. This leaves us with the equation DELTA p = -K * DELTA t * m Where K is a different from k, but essentially a spring constant. Now, once again, I'm not sure if this is valid physics, but if it is, this equation should give a more accurate position per step during the integration.

Share this post

Link to post
Share on other sites
Okay, i just realized that i have things slightly wrong. Euler's method would still bring in inaccuracies in situations I described. There will be an error in velocity calculations when there is acceleration. They are just minimized when acceleration is constant.

I still stand by the math, but in that case, this equation could then be used for more accurate spring calculation, right? (Assuming its valid math)

Share this post

Link to post
Share on other sites
Jerk is not constant for a spring-mass system (unless it's standing still ;-)). Simple example: Choose spring constant = 1, damping = 0; you get (state-space form):

(d/dt) p = v
(d/dt) v = -p

Now say initial condition is

p(0) = 1
v(0) = 0 .

Then the solution to this ODE is,

p(t) = cos(t)
v(t) = -sin(t)

The jerk is,

j(t) = (d/dt) v(t) = -cos(t)

which is clearly not constant.


If you want a decent numerical method (which is nearly as simple as explicit Euler) for solving the kinds of ODEs that appear when you model systems of springs, try semi-implicit Euler. I'd say this is the "right" answer. There are fancier (higher-order) versions of this, and they are known generally as symplectic integrators; you can google it if you want to dive in.


There are also hackish things you can do. For instance, if your system looks like,

(d/dt) x = f(x)

and you know that the energy E(x) is conserved, then in principle the following ODE has the same solution

(d/dt) x = f(x) - (dE/dx)T(E(x) - E(x0))

since the second term is always zero. But if you were to simulate this with Euler, the results would be different, and the second term would tend to conserve energy. You can think of this as a poor man's predictor-corrector method.

E.g., for the system above, x = (p,v) , E(x) = E(p,v) = (1/2)(p2 + v2) , and,

(d/dt) p = v - p[(1/2)(p2 + v2) - E0]
(d/dt) v = p - v[(1/2)(p2 + v2) - E0]

where E0 is the initial energy of the system.

[Edited by - Emergent on May 21, 2009 3:29:50 PM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!