Page 1 of 1

[Fixed]2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Thu Mar 29, 2012 5:40 am
by tatt61880
Edit: (by tatt61880 on 2012.05.13 21:26)
Fixed in 2.0.2b15. Thanks :clap:
-Tatt
----

NOTE: Please read my self-response, at first: Re: 2.0.2b14 Undo-ing changes vel/angvel.

Since Phun v5.28 or earlier.

When you undo, vel of Geoms will be changed under certain conditions.
This issue can be one of the cause of non-deterministic/randomness.

I consider that there are several conditions that can cause this issue.
* There is a small digit in vel and angvel (0.0000000003, 1.0000000003 etc.).
* Two or more Geoms are glued or fixated together.
* Other conditions of this issue aren't confirmed.

The scene below will reproduce this issue perfectly(100%).

[scene]61642[/scene]

The code below is what I wrote for bug report.
// When you set angvel := 0, this issue won't happen.
Code: Select all
Scene.Clear;
Scene.addPolygon {
    color := [0, 0, 1, 1]; /* blue */
    surfaces := [[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]];
    entityID := 1;
    geomID := 1;
    pos := [0.0, 0.0];
    body := 1;
    vel := [1.0000000003, 0.0];
    angvel := 0.0000000003
};
Scene.addPolygon {
    color := [1, 0, 0, 1]; /* red */
    surfaces := [[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]];
    entityID := 2;
    geomID := 2;
    pos := [0.5, 0.3];
    body := 1;
    vel := [1.0000000005, 0.0];
    angvel := 0.0000000003
};


== How to reproduce bug ==
When you opened the scene,
vel := [1.0000000, -3.7617631e-011]; // blue one
vel := [1.0000000, 3.7617631e-011]; // red one
angvel := 1.5047052e-010;
(NOTE: When I open the scene, it sometimes says vel = [1.0000000, -3.7617603e-011] (instead of [1.0000000, -3.7617631e-011]), and angvel = 1.5047041e-010. I cannot reproduce the issue.... Maybe another bug?)

Sim start and Undo.
Then, the vel and angvel will be changed.
vel := [1.0000000, 2.9481001e-011]; // red one
angvel := 1.1792400e-010;

== Survey results ==
Surprisingly, this change is not random.
The plot below shows the relation between #trials and vel/angvel : exponentially decrease.
i.e. vel = first_vel * (second_vel/first_vel)^(#undo).
Image

math.abs(vel(1)) // 10 trials
Code: Select all
3.7617631e-011
2.9481001e-011
2.3104324e-011
1.8106849e-011
1.4190343e-011
1.1121021e-011
8.7154728e-012
6.8303696e-012
5.3529403e-012
4.1951165e-012


angvel // 10 trials
Code: Select all
1.5047052e-010
1.1792400e-010
9.2417296e-011
7.2427397e-011
5.6761373e-011
4.4484083e-011
3.4861891e-011
2.7321478e-011
2.1411761e-011
1.6780466e-011

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Fri Mar 30, 2012 1:46 am
by tatt61880
Sorry, this issue happens not only with Polygons, but also with Circles and/or Boxes.
vel/angvel decrease exponentially. i.e. vel = first_vel * (second_vel/first_vel)^(#undo).
I've edited my post above.

The code below is an example.
Code: Select all
Scene.Clear;
Scene.addCircle {  /* blue circle */
    color := [0, 0, 1, 1];
    radius := 1;
    size := [1, 1];
    entityID := 1;
    geomID := 1;
    pos := [0.0, 0.0];
    body := 1;
    vel := [1.0000000003, 0.0];
    angvel := 0.0000000003
};
Scene.addBox {  /* red box */
    color := [1, 0, 0, 1];
    size := [1, 1];
    entityID := 2;
    geomID := 2;
    pos := [0.5, 0.3];
    body := 1;
    vel := [1.0000000005, 0.0];
    angvel := 0.0000000003
};

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Sat Mar 31, 2012 9:24 am
by tatt61880
I guess the cause of this issue must be re-calculating process for vel/angvel of glued/fixated geoms when Algodoo loaded scene or undo scene.
You can

== My hypothesis ==
1. Algodoo loads a scene which data = A.
2. Algodoo re-calculate the data(A), then data = func(A) = B.
3. Algodoo sets the data(B) into memory for undoing.
4. When you undo the scene, Algoodo remember the scene is data = B.
5. Algodoo re-calculate the data(B), then data = func(B) = C.

After 2. and 5. the data should be same.
If func(B) = B, it's no problem. But in some case, func(B) != B, actually. I think this happens by precision issue.

====
There must be re-calculating process, because when you load next data, angvel != 0.0.
Code: Select all
Scene.Clear;
App.GUI.Forces.velocities = true;
App.GUI.Forces.rotation = true;
App.GUI.Forces.drawValues = true;
Scene.addBox {
    color := [0, 0, 1, 1];
    body := 1;
    angvel := 0.0;
};
Scene.addBox {
    color := [1, 0, 0, 1];
    body := 1;
    pos := [1, 0];
    vel := [0.0, 1.0];
    angvel := 0.0;
};


== How to fix? ==
If my hypothesis is correct, you can fix this issue. Do not re-calculating vel/angvel. ;)

NOTE: I believe this issue is one of a cause of randomness but there must be other cause of randomness.

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Wed May 09, 2012 2:39 pm
by emilk
The cause of this is that it is only the velocity of geometries that are serialized, not the body. The body velocity is calculated from the geometry velocity and vsv, producing rounding errors.

I will fix this for undo/redo in the next beta, but it is actually a bit harder to fix for scene save/load. I will think it over.

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Wed May 09, 2012 6:30 pm
by tatt61880
Thanks!

emilk wrote:but it is actually a bit harder to fix for scene save/load. I will think it over.

Does this mean that reloading scene even changes vels?

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Thu May 10, 2012 5:31 pm
by emilk
tatt61880 wrote:Thanks!

emilk wrote:but it is actually a bit harder to fix for scene save/load. I will think it over.

Does this mean that reloading scene even changes vels?


For composite bodies, yes. But only sometimes, and only very little. I'll try to fix this for the next beta.

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Thu May 10, 2012 5:40 pm
by tatt61880
emilk wrote:
tatt61880 wrote:Thanks!

emilk wrote:but it is actually a bit harder to fix for scene save/load. I will think it over.

Does this mean that reloading scene even changes vels?


For composite bodies, yes. But only sometimes, and only very little. I'll try to fix this for the next beta.

Great! I wish you success. ;)

Re: 2.0.2b14 Undo-ing changes vel/angvel

PostPosted: Sun May 13, 2012 10:24 am
by emilk
Should be fixed now in b15