Angular momentum bug

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Angular momentum bug

Postby FSA » Fri Jan 22, 2021 10:57 pm

It looks like there is a bug in Newton 4 with angular momentum. If the capsule is spinning on it's edge, it keeps getting faster. The scene is from ndSandBox.
Video: https://youtu.be/M7zHLqQTB0s
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 9:58 am

Yes, I have seen it, also David Gravel report it to me, and I could not reproduce it.
It seems a bug in the gyro torque calculation in the contact joint.

I see if I can make a repro with just one capsule that I can step over and see what is going on.
Thanks for the report.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 11:28 am

I just recreated the same test in 3.14
And it has the same problem.
The bug is hidden in 3.14 because angular damp is on by default in 3.14 but not in 4.00

I will see if something is wrong in the contact joint when using gyro torque, but bera in mind that they will alway be some numerical erro because it is a numerical integration, but you are right the error seems too large for a numerical integration.
I think it is in the contact joint because when bodies are in free rotation the total momentum is conserve from very long time.

I will debug it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 2:53 pm

wow, it is quite bad, I made teh repro.
I place a spinning capsule wit and angula velocity of 20 rad/sec in 2 meters above the air.
when if his the floor is loses 4 rad/sec because of friction, that quite normal and nice.

    39 wMag = 20.000111 w(-8.660347 15.000027 -10.000101)
    40 wMag = 20.000111 w(-8.660350 15.000022 -10.000103)
    41 wMag = 20.000111 w(-8.660355 15.000021 -10.000104)
    42 wMag = 20.000118 w(-8.660361 15.000024 -10.000108)
    43 wMag = 16.393618 w(-5.887784 14.641502 -4.439716)
    44 wMag = 16.393618 w(-6.196572 14.569480 -4.252461)
    45 wMag = 16.393618 w(-6.493022 14.499101 -4.045666)
    46 wMag = 16.393618 w(-6.775965 14.430643 -3.820148)

but the after that it keep gaing angular momemetrum real fast, at a rate 0f 0.1 rad/ secudn per steps

    382 wMag = 18.584291 w(-7.730444 16.894295 -0.446030)
    383 wMag = 18.618795 w(-7.766456 16.904692 0.757026)
    384 wMag = 18.618793 w(-7.713094 16.873812 1.562723)
    385 wMag = 18.618793 w(-7.581718 16.840740 2.359339)
    386 wMag = 18.618792 w(-7.373566 16.805786 3.139341)
    387 wMag = 18.618795 w(-7.090611 16.769289 3.895354)
    388 wMag = 18.676104 w(-6.571516 16.740984 5.035023)
    389 wMag = 18.676111 w(-6.161751 16.671850 5.734053)
    390 wMag = 18.676123 w(-5.685597 16.602530 6.389645)
    391 wMag = 18.676134 w(-5.147582 16.533680 6.995558)
    392 wMag = 18.676144 w(-4.552828 16.465954 7.546025)
    393 wMag = 18.750149 w(-3.543040 16.407848 8.354485)


that's obviously not good, teh reason this does no show in 3.14 is because the damping manage to extract about the same rate of increase of momentum. I believe we can do better than that.
the integration is RK4 so it will not remove energy so I expect so increase but I do not think a numerical error would be that big. if it is teh case I want to investigate the reason.
now I am very curious about this.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby FSA » Sat Jan 23, 2021 4:11 pm

Nice to hear that you were able to reproduce it.
Just to clarify: Is friction disabled in the demos? I would expect that friction takes care of this, even when angular damping is zero.
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 4:33 pm

Not friction is not disabled. And not friction does not take care of that. Kinetic Friction is a non conservative force, when the capsule is spinning with not sliding, the friction is zero because there is only static friction which is conservative. The capsule should spins for ever without gaining angular momentum.
This is very hard to achieve, but at least should spin stable for a long time, which is not the case now.

As I said this bug happens because a bug in the contact joint an gyro torque.
It has been there for so long because the default angular drag is on by default in 3.14 and hide the bug.
But in 4.xx there is not the case.

I have the solution already, I have to add the code, and that should be the solution.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby FSA » Sat Jan 23, 2021 8:28 pm

Would that mean, that even if a friction coeff for the material is set the capsule would rotate forever? How should real world behavior be achieved then? With angular/linear damping?
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 9:04 pm

If it is spinning around a point, them there is not kinetic friction. Yes it should spins for ever.
It is like a top. Look up in you tube for real examples of phitops so that you convince yourself.
As long as does not gain angular momentum, it is fine.

Friction only remove momentum from a system when there is slipage between the contacts.

Imagine a capsule rolling on its side, it will rolls for ever if there is not rolling friction, but rolling friction is only a property of elastic materials, not of rigid bodies.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby FSA » Sat Jan 23, 2021 10:11 pm

I understand that it is correct in an ideal system. But real world behavior is different. So the only way the rotation slows down would be with the two damping values?
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby FSA » Sat Jan 23, 2021 10:36 pm

This is how I would expect a rolling object to behave: https://www.phy.davidson.edu/fachome/dm ... %20another.

Of course, this is for elastic bodies. But how should this be reproduced in the engine?
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 10:40 pm

An app can always apply drag, but the physics has to be foremost correct before.
If it is possible I will get that fix first, at least my goal is the momentum is preserved better fir long time, Drag can be added, but drag can't be the law of physic.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 10:46 pm

Yes, that's what I said before, things like rolling friction are not properties of rigid body. But it can be added.
In fact there is a joint called dry rolling friction that does that in 3.14
It has not been added to 4.00 but is is eassy.

The problem I am taking about is that the solver can not add angular momentum like it is doing now, that's a fundamental flaw that can not be fix by adding drag.
Not getting that fix or significantly improve and the physic will be incorrect and you will never know why.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby FSA » Sat Jan 23, 2021 11:10 pm

My questions were not meant to be a fix for the problem.
I'm just wondering, how I should implement drag in my application.
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Re: Angular momentum bug

Postby Julio Jerez » Sat Jan 23, 2021 11:55 pm

I try one mode time.
in Newton 3.14 the drag coefficient was set on by default. this was done because back them, physics engines only had three collision shapes: spheres, capsules and boxes.
so when people placed bunch of spheres and capsules in a map, they never went to sleep and slow down the engine a lot.
I decide that to prevent that I set drag by default.
over the years people has criticized that a great deal, some even accused me that the engine was stable because of that, same happen with auto sleep that was also on by default and people accused me that auto was no possible to turn off.

I do not really care about people opinion of the engine, but I realized that having the drag on by default hide that bug in the engine and I never that chance to fix.

Now for 4.xx those functionalities are off by default. it is up to the app to apply then when they create a body or when they want to.

I just added the drag coefficient so that you can see how it work.
if you sync you will see that the capsule will go to rest.

But that is is no correct. if a user wnat to make a phitop, the the fact that it needs drag to make work, makes such basic and fundamental task impossible. the solution is to have the angular momentum calculation correct and the ability to add Drag also correct but and both independent of each other.

to apply viscous drag you just call this
Code: Select all
body->SetLinearDamping(dFloat32(0.1045f));
body->SetAngularDamping(dVector(dFloat32(0.1045f)));


to apply dry rolling friction it needs the joint, but that joint has not been ported from 3.14 yet.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Angular momentum bug

Postby FSA » Sun Jan 24, 2021 1:23 am

And I try again too:
I understood what you said. I understand that the capsule should not go to rest. My question was about rolling friction and how this should be implemented not about the bug. For me it was simply not clear, what the difference between the rolling friction joint and linear/angular damping was in that context.

to apply dry rolling friction it need the joint, [...]

That was the only thing I wanted to know.

I do not really care about people opinion of the engine

That is a bit sad :( Of course it's your engine, and I think you're just doing it because you have fun with it. But it's always a good idea to care about peoples opinions (not all of course). I think you would agree that the fun would be bigger, when you'll see the newton logo in some nice games. I'm not speaking for me here, since I'm already using newton, but sadly many don't.

Anyway, back to the topic of this thread: Let me know when you fixed the bug, I will continue testing the engine.
User avatar
FSA
 
Posts: 318
Joined: Wed Dec 21, 2011 9:47 am

Next

Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 12 guests