java - Calculating an object's position, velocity and other derivatives of motion efficiently -


ok, here's programming/physics puzzle in, let's java (although doesn't matter - consistency, use java).

i have array of doubles each element represents successive derivates of object's position. so:

d[0] // position d[1] // velocity d[2] // accelleration 

etc ...

there @ least 1 , potentially number of elements (but in practice, not more 5). elements beyond end of array assumed zero.

we have double t time.

so if d.length 3 specifically:

d[0] += d[1] * t + d[2] * t * t / 2 d[1] += d[2] * t 

but how can write iterative solution (no recursion!) update of elements of array time t length of a?

votes should awarded efficiency , conciseness.

edit: laws of motion on physics pages of site, each term has form:

power(t,n) / factorial(n) 

so next term of first equation d[3] * t*t*t / 6

if not familiar these equations, please don't ask me explain.

a test case:

final static double[] d = { 5.0, 4.0, 3.0, 2.0, 1.0 }; double t = 10.0 

should give:

[945.0, 300.66666666666663, 73.0, 12.0, 1.0] 

second element may vary due precision errors.

i think works.

int length = d.length; (int = 0; < length - 1; i++) {     double temp = 0;     (int j = length - 1; j > i; j--)         temp = (temp + d[j]) * t / (j - i);     d[i] += temp; } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -