KulSeran 3267 Report post Posted June 7, 2006 I've been reading about several different integration methods, like euler and verlet. One that looks promising is the midpoint method, since it is sympletic. BUT, i have come to a stumbling block. How do you actually write the integrator? The formulations for them assume you have some continious function y' = f(t,y(t)). For simple motion, d' = v, v' = a, a = f/m. can i just plug those in for f? they dont seem to be related to t, d, or v. It seems for a descrete simulation I would need y' = f(dt, y(t-dt)). Or something. I think i just got lost somewhere in the works between the numbers and the implementation. Anyone have a good link/thought on the subject? 0 Share this post Link to post Share on other sites
Stani R 1070 Report post Posted June 7, 2006 I think simple motion really is simple, but maybe I am missing the point here. (Or maybe I am missing some important concepts. For instance, I'm not exactly sure how angular momentum would play into this)The next position is the current position plus the current velocity times the time difference.The next velocity is the current velocity plus the current acceleration times the time difference.The current/next acceleration you can vary as you wish, maybe with the aforementioned F=ma equation. To calculate F, if it's a space game for instance you might want to apply gravitational forces for all the major objects in proximity, like the planets, plus a force component for propulsion.This is not a general integrator implementation, but it doesn't look like you are trying to build a generic integrator? 0 Share this post Link to post Share on other sites
KulSeran 3267 Report post Posted June 7, 2006 Ah I am trying to make an integrator. I need to integrate motion, but also different equations, likedelta-P = nR * delta-T / Vand a couple others for a simulation. But I dont see how to make that work with anything other than euler (new P = old P + nR/V * delta T)but euler isn't good for preserving energy over time. So I'm trying to figure out how you make any equation work in something like midpoint or verlet. 0 Share this post Link to post Share on other sites
Stani R 1070 Report post Posted June 7, 2006 I just found this article which shows an RK4 implementation. Not sure that it is generic enough for your case, but might give you some ideas.If you're into Java, (and even if you're not, there might be some hints in the code or methods there) you may be interested in Mantissa. Also on the Mantissa page there are a number of links to generic math libraries that include diferential equation solvers (as far as I can see).(This is the extent of my knowledge, so hopefully someone else will address the question in a more meaningful way =) ) 0 Share this post Link to post Share on other sites
KulSeran 3267 Report post Posted June 7, 2006 Lightbringer, thanks. That RK4 article should help.My java skill is a bit lacking, so i dont know what I will get from mantissa, but it is a start.Anything else from anyone would still be nice, the more I can read, i think the less confused i will be. 0 Share this post Link to post Share on other sites
KulSeran 3267 Report post Posted June 8, 2006 ---followup for the interested.While you can make an rk2/rk4 and many other general integrators,the ones i was interested in (symplectic/energy conserving) are a specific subclass that pertains to one specific set of formulas.If you want a symplectic integrator, you have to come up with one for the formula you are integrating.So something like pre-formulated velocity-verlet for newtonian motion is one pre-done example.Too bad, i was hoping there was a way to make something symplectic for every case (RK2/midpoint is close though) 0 Share this post Link to post Share on other sites
Eelco 301 Report post Posted June 9, 2006 integrators for differential equations are usually given in a fixed template: the y' = f(t,y(t)) you mentioned.any differential equation can be expressed as a system of such equations, thats why. you were indeed on the right track.say you define your system in two variables, position x and velocity v.velocity is the time derivative of position, and acceleration the time derivative of velocity.thus:x' = vv' = a = f(t) / mwhich upon closer inspection indeed conforms to y' = f(t,y(t)), ie the derivative of y expressed as a function of itself, time, or possibly some constants. if you have a generic integrator, all you need to do is plug in the right hand sides of this system of first order differential equations. 0 Share this post Link to post Share on other sites
Enselic 829 Report post Posted June 9, 2006 FWIW, I've written a RK4 vs Euler intergation demo which contains a generic RK4 integration method which you might find of interest. You will find at www.chromecode.com/downloads (It's the second from the top, the one named 'RK4 vs Euler') 0 Share this post Link to post Share on other sites
MrRowl 2490 Report post Posted June 9, 2006 David Baraff's Siggraph '97 Course notes - see differential equation basics and then Rigid Body Dynamics: Lecture Notes I (unconstrained motion) for an implementation example. 0 Share this post Link to post Share on other sites