**Moderators:** Sascha Willems, Thomas

48 posts
• Page **4** of **4** • 1, 2, 3, **4**

Hi Julio, I just tested in my game and It's working 10 times better! Thanks!

- MeltingPlastic
**Posts:**221**Joined:**Fri Feb 07, 2014 11:30 pm

nice, 10 fold improvement I take.

here is some that can be done to make it even better if you are not doing it already.

As you know all numerical integration methods are error bound by how many term are truncated on the expansion of the function.

Very few methods truncated the expansion at the third derivative (secant and Hessian method for some special differential equations).

but the more general methods truncate at the second derivative and by evaluation at some intermediate step is how they get fourth and fifth order accuracy (RK, prediction correction and implicit methods fall on this category)

Newton is a fourth order derivative accuracy because it uses RK4, however it does not uses the optimal weigh values (1/6, 1/3, 1/3, 1/6) instead it uses (1/4, 1/4, 1/4, 1/4) plus it evaluate the intermediate steps by doing numerical prediction for contacts and the analytical evaluation for bilateral joints, so is no a true RK5 order. you can read some intro here.

http://web.mit.edu/10.001/Web/Course_No ... node3.html

now imagine the final force equation on a body after the constraints forces are calculated. you get something like

(v1 - v0)/dt = 1/m (f + c0 * j0 + c1 * j1 + .....)

that need to be integrated to the next step.

the js at the constraint normal, and the cs and the force magnitude of the force along the js directions. I

t is these C0 that are the non linear values that make the integration be more or less accurate, is not stated in the expression but these C values are function of time and position, depending on what the constraint does.

Since they are only evaluate at the beginning of the step, any intermitted value has to be extrapolated numerically or analytically deduced. so let us call the expression on the right side as f(t,x) and we get a linear differential equation of the form:

dv = f(t,x) * dt

the expansion of the equation is at a time t0, x0, v0 is given by:

v1 = v0 + f'(t0,x0) * dt + f''(t0,x0) * dt ^2 + + f'''(t0,x0) * dt ^3 + ....

and the truncated linear expression is

v1 = v0 + f'(t0,x0) * dt + E(dt ^ 2)

as you can see even in the simplest integration method the error is a function of dt to some power

The reason I say this is so that I can justify what I am going to say next.

imagine you run the step a twice the time step, that is dt1 = dt0 / 2

now your error becomes four time smaller E (0.25 * dt0^2) per step/

that is the error of an euler integration improves four time with the reduction of the time step by half. In newton this error is E(dt^4) so the improvement is somewhere from 8 to 16 time.

the penalty for this is the simulation run twice and there is some house keeping on the client engine.

fortunately knowing this, the engine supports that functionality with function

NewtonSetNumberOfSubsteps (m_world, MAX_PHYSICS_SUB_STEPS);

the benefit is that there are few things that are shared, like the broaphasee housekeeping and transform update call backs, the iterative algorithm have smaller residual so the converge is almost twice as fast, and finally the task switching for threading only happens once.

All in all the cost for running with more than one sub step per update is marginal, but the improvement in simulation quality is at a minimum quadratic.

so if you are not doing that already, try it out NewtonSetNumberOfSubsteps (m_world, MAX_PHYSICS_SUB_STEPS);

with MAX_PHYSICS_SUB_STEPS set to say 2 or 3.

I mention this because you already know what newton is all about, speed is important, but what good it is if you can't get desirable quality?

I know this is a hard sale to fan boys who are more interested is promoting a narrative without really knowing how these things works, but I thought you now pass the point where speed and stacking boxes comparison is not longer how you measure a physics library quality.

here is some that can be done to make it even better if you are not doing it already.

As you know all numerical integration methods are error bound by how many term are truncated on the expansion of the function.

Very few methods truncated the expansion at the third derivative (secant and Hessian method for some special differential equations).

but the more general methods truncate at the second derivative and by evaluation at some intermediate step is how they get fourth and fifth order accuracy (RK, prediction correction and implicit methods fall on this category)

Newton is a fourth order derivative accuracy because it uses RK4, however it does not uses the optimal weigh values (1/6, 1/3, 1/3, 1/6) instead it uses (1/4, 1/4, 1/4, 1/4) plus it evaluate the intermediate steps by doing numerical prediction for contacts and the analytical evaluation for bilateral joints, so is no a true RK5 order. you can read some intro here.

http://web.mit.edu/10.001/Web/Course_No ... node3.html

now imagine the final force equation on a body after the constraints forces are calculated. you get something like

(v1 - v0)/dt = 1/m (f + c0 * j0 + c1 * j1 + .....)

that need to be integrated to the next step.

the js at the constraint normal, and the cs and the force magnitude of the force along the js directions. I

t is these C0 that are the non linear values that make the integration be more or less accurate, is not stated in the expression but these C values are function of time and position, depending on what the constraint does.

Since they are only evaluate at the beginning of the step, any intermitted value has to be extrapolated numerically or analytically deduced. so let us call the expression on the right side as f(t,x) and we get a linear differential equation of the form:

dv = f(t,x) * dt

the expansion of the equation is at a time t0, x0, v0 is given by:

v1 = v0 + f'(t0,x0) * dt + f''(t0,x0) * dt ^2 + + f'''(t0,x0) * dt ^3 + ....

and the truncated linear expression is

v1 = v0 + f'(t0,x0) * dt + E(dt ^ 2)

as you can see even in the simplest integration method the error is a function of dt to some power

The reason I say this is so that I can justify what I am going to say next.

imagine you run the step a twice the time step, that is dt1 = dt0 / 2

now your error becomes four time smaller E (0.25 * dt0^2) per step/

that is the error of an euler integration improves four time with the reduction of the time step by half. In newton this error is E(dt^4) so the improvement is somewhere from 8 to 16 time.

the penalty for this is the simulation run twice and there is some house keeping on the client engine.

fortunately knowing this, the engine supports that functionality with function

NewtonSetNumberOfSubsteps (m_world, MAX_PHYSICS_SUB_STEPS);

the benefit is that there are few things that are shared, like the broaphasee housekeeping and transform update call backs, the iterative algorithm have smaller residual so the converge is almost twice as fast, and finally the task switching for threading only happens once.

All in all the cost for running with more than one sub step per update is marginal, but the improvement in simulation quality is at a minimum quadratic.

so if you are not doing that already, try it out NewtonSetNumberOfSubsteps (m_world, MAX_PHYSICS_SUB_STEPS);

with MAX_PHYSICS_SUB_STEPS set to say 2 or 3.

I mention this because you already know what newton is all about, speed is important, but what good it is if you can't get desirable quality?

I know this is a hard sale to fan boys who are more interested is promoting a narrative without really knowing how these things works, but I thought you now pass the point where speed and stacking boxes comparison is not longer how you measure a physics library quality.

- Julio Jerez
- Moderator
**Posts:**11153**Joined:**Sun Sep 14, 2003 2:18 pm**Location:**Los Angeles

Thanks for the explanation. Yeah this stuff is sinking in. Maybe someday I'll make a small physics simulation just for fun to get a real handle on how the math all works.

- MeltingPlastic
**Posts:**221**Joined:**Fri Feb 07, 2014 11:30 pm

48 posts
• Page **4** of **4** • 1, 2, 3, **4**

Users browsing this forum: Julio Jerez and 1 guest