2.0.2b6 Position issue

If you have problems installing or running Algodoo, have found a bug or need in-game help - this is it!

2.0.2b6 Position issue

Postby tatt61880 » Sun Feb 05, 2012 8:43 pm

[scene]60682[/scene]
Information window says "y = 0.000 m" but plot window says "y = -0.005 m".
Please tell me why, if there exists an intended offset for plot.
Image

CSV file also says "y = -0.005 m" when t = 0
Time,Position (y)
0,-0.005
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: 2.0.2b6 Position issue

Postby emilk » Tue Feb 07, 2012 11:23 am

Yes, the plot does have an intended offset. The reason is a bit complicated, but I'll try:

During the simulation, the position and velocity are acctually off by half a time step. This is because Algodoo uses the Leap-Frog integration scheme, which ensures energy conservation.

But this also means that we cannot use the naive aproach to calculating the energy of e.g. a ball in a gravity field:

E = Ep + Ek, Ep = mgh, Ek = mv^2/2

Where h is the height and v the velocity of the object. The sum E will be fluctuating, since the position (h) and velocity (v) is off by half a time step. To fix this I project the position along the velocity by half a time step to compensate, making the enrgy calculation seem perfect. The same goes for the plot, to ensure the force/pos integral will perfectly correspond to energy.

However, this causes the problem above: the plot will not show the current position, but the projected position, i.e. the position one half time step back (5ms back in time), estimated from current velocity.

As you see, I've opted to have the position of the Information box correspond to the actual (visual) position of the object. But if someone tries to calculate the object energy from the position/velocity in the information box, it will be off from what the information box shows below. That is: position a circle at the origin, and you will see the potential energy in the Information box will change if you change the velocity of the object.


All of this can become quite confusing, but I have yet to find a nicer way of doing this. The only option I can see is to not project the position backward, but instead project everything else forward - velocity, forces etc. But that's a lot harder than it sounds. Another alternative is to project the position a half-step everywhere, even visually, but that would mean colisions would occur that would never be visible on screen. i.e., all contact arrows would be shown at contact points that make no sense...

Anyway, end of rant. I'm open for suggestions here.
Emil Ernerfeldt, lead developer
emilk
 
Posts: 616
Joined: Mon Aug 31, 2009 11:01 am
Location: Umeå, Sweden

Re: 2.0.2b6 Position issue

Postby tatt61880 » Tue Feb 07, 2012 5:55 pm

I think I've understood what causes the issue.

Related changelog.
Changelog(v2.0.2 b2) wrote:FIX: Bug causing kinetic and potential energy calculations to be out of sync, making it appear in the plot as if the total energy was not constant.

====

dt := delta time for next step;
v0 := current vel;
x0 := current pos(0);
v1 := next step vel;
x1 := next step pos(0);

Currently, x1 = x0 + v1 * dt, right?
The issue will be solved when x1 = x0 + (v0+v1)/2 * dt.

This change requires to change physics engine.
Calculation time become a bit longer, but new physics will be more precision than current one.
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan


Return to Help / Bug reports

Who is online

Users browsing this forum: No registered users and 1 guest