[ODE] More accuracy ???
Nguyen Binh
Nguyen Binh <ngbinh at glassegg.com>
Fri May 23 01:56:02 2003
Hi ,
In moveAndRotateBody (dxBody *b, dReal h) function of step.cpp
file (ode 0.35 distro) we have :
------Begin code fragment
......
// handle linear velocity
for (j = 0; j < 3; j++)
b->pos[j] += h * b->lvel[j];
.....
------End
I understand those code update 3D position of the body using first
order Euler method.In which,
lvel = pos'
Is it true?
Look more closely, I found b->facc[j] is 'external force' apply to
the body along jth axis, so:
facc = lvel' = pos''
That's means we have a "cheap" and more accurate way to solve the
ODE problem:
we should update pos with :
pos(t + h) = pos(t) + h*pos'(t) + h*h/2*pos''(t)
= pos(t) + h*lvel(t) + h*h/2*facc(t).
So, the code is modified to
------Begin code fragment
......
// handle linear velocity
dReal h2 = h*h/2;
for (j = 0; j < 3; j++)
b->pos[j] += h * b->lvel[j] + h2*b->facc[j];
.....
------End
So our ODE has O(h3) accuracy compare to just O(h2) with the old
one.
How is your idea? Is something wrong with me?
I have little time to test it, and it works just fine.I mean I see
no 'wrong' behavior but no 'better' than the old one.
--
Best regards,
---------------------------------------------------------------------
Nguyen Binh
Software Engineer
Glass Egg Digital Media
E.Town Building
7th Floor, 364 CongHoa Street
Tan Binh District,
HoChiMinh City,
VietNam,
Phone : +84 8 8109018
Fax : +84 8 8109013
www.glassegg.com
---------------------------------------------------------------------