Thread: Vector
View Single Post
Old 09-03-2006, 09:11 PM   #3
PipeDream's Avatar

Code Moderator
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)


Finally you submit this! The demonstration is beautiful. Approved.

Constant accelerations produces parabolas. That very simple integration method will always increase or decrease energy since it can only exactly reproduce lines. If you flip the order of adding velocity/acceleration to position/velocity you'll see it decay instead of grow. Since the solution is exactly a parabola you can use an explicit formula.
But if you want to be generic to non constant acceleration you can get the same exact integration of constant acceleration with a tiny bit more complexity:
Collapse JASS:
    local integer k1v //unoptimized Runge Kutta 2
    local integer k1x //Takes a trial half sized step
    local integer k2v //computes derivatives in middle of interval
    local integer k2x //uses those values to step from beginning to end

    set k1v = VectorAmplify(vectors[4],BouncyPeriod()*.5)
    set k1x = VectorAmplify(vectors[3],BouncyPeriod()*.5)

    set k2v = VectorAmplify(vectors[4],BouncyPeriod()) //recompute acceleration if it's time or position dependent
    set k2x = VectorSum(k1v,vectors[3])
    call VectorScale(k2x,BouncyPeriod())
    call VectorAdd(vectors[2],k2x)
    call VectorAdd(vectors[3],k2v)
    call VectorDestroy(k1v)
    call VectorDestroy(k1x)
    call VectorDestroy(k2v)
    call VectorDestroy(k2x)
And remove the scale of BouncyPeriod() from the initial state. This is a somewhat less interesting demonstration since it doesn't grow in energy and because of that the skidding karukef mentions occurs more frequently.

In general for spells the lack of conservation in the simple integrator is not a problem, but it will become one as you increase the time step. .01 is smaller than what is necessary for visually smooth. With this integrator you can safely increase to a less aggressive .03-.05.
PipeDream is offline   Reply With Quote