Gafferon Games has a great article on RK4 Integration for building physics simulations which can be found here: Integration Basics
Personally my mathematics and physics knowledge could use improvement. I feel comfortable within the realm of vector mathematics, trig, some stats (I've had to use linear line regression formulas for software, etc. ), and basically most things high school level to first year college.
Now to the question, I've read this article, downloaded the associated source and debugged line by line to try and get an understanding of what is happening and still feel like I'm clearly not getting what I'm looking at. I've searched the internet trying to find the "For Dummies" versions, frankly I learn a little differently and staring at formulas all day with the emphasis on memorization isn't going to cut it as I need to understand what is happening so I can be flexible applying it.
So here's what I think I understand so far, but I am hoping someone else can clarify or completely correct me. The RK4 uses a Euler step, then bases that to move forward in time to calculate several more essentially Euler steps(?) and determines using a weighted sum what the best position and velocity is for the next frame?
Furthermore that acceleration method (converted into AS3):
private function acceleration(state:State, time:Number):Number
{
const k:int = 10;
const b:int = 1;
return - k*state.x - b*state.v;
}
takes a constant mass(10) and force(1)? and returns some weird calculation I have no idea why...-mass * position - force * velocity? what?
Then for my last bit of confusion, in the evaluate methods which look like (AS3):
private function evaluateD(initial:State, time:Number, dtime:Number, d:Derivative):Derivative
{
var state:State = new State();
state.x = initial.x + d.dx*dtime;
state.v = initial.v + d.dv*dtime;
var output:Derivative = new Derivative();
output.dx = state.v;
output.dv = acceleration(state, time+dtime);
return output;
}
We store a new state with the time step, then set a derivative to return...I sort of understand this as it's used in the approximation process, but what is this!:
output.dx = state.v;
output.dv = acceleration(state, time+dtime);
// ok I get we are getting the new velocity since v = a * t, obviously I
// don't what acceleration() is returning though.
We set the derivative output change in position to the states new velocity? Huh?
Lastly this test simulation runs doing this:
var state:State = new State();
state.x = 100;
state.v = 0;
t = 0;
dt = 0.1;
while (Math.abs(state.x)>0.001 || Math.abs(state.v)>0.001)
{
trace(state.x, state.v);
integrate(state, t, dt);
t += dt;
}
So we are setting a new state with a positional value of 100, and a velocity of 0? What is the point of this simulation if we have no velocity...
Anyway, needless to say I'm pretty confused and have drifted off planet Earth. Hoping someone out there can clarify this for me.