[Code] Setting Bodies Static

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

[Code] Setting Bodies Static

Postby AntonSynytsia » Thu Mar 09, 2017 12:36 am

This is not a question, but rather an observation that I made and though it would be good to share for others to know.

To set a body static, from other threads, I learned that its mass must be set to zero:
Code: Select all
NewtonBodySetMassMatrix(bodyToSetStatic, 0.0f, 0.0f, 0.0f, 0.0f)

But this is not enough. If the body being set static was initially moving, other bodies contacting it would either bounce on it or go through it. To fix it, the body that is set static, must also have its velocity and omega vectors zeroed out:
Code: Select all
dVector zero_vector(0.0f);
NewtonBodySetVelocity(bodyToSetStatic, &zero_vector[0]);
NewtonBodySetOmega(bodyToSetStatic, &zero_vector[0]);

Taking this further, to emulate a proper static moving platform, the bodyToSetStatic's velocity must be set to the velocity it is moving at, even though it's just being repositioned. The clip below shows the difference: https://drive.google.com/open?id=0B3qg8 ... EhSTUNXc28
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: [Code] Setting Bodies Static

Postby JoeJ » Thu Mar 09, 2017 3:37 am

Intersting. Up to now i have been using kinematic bodies with the same practice:
Set velocity only for conveyor belts.
Set velocity and position for moving platforms.

But if the same works with dynamic bodies with zero mass (static bodies),
i don't understand the purpose of kinematic bodies anymore.

When should we use kinematic bodies over static bodies?
(It's always counter intuitive to set a proper mass for kinematic bodies, so i'd prefer the static approach.)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: [Code] Setting Bodies Static

Postby Julio Jerez » Thu Mar 09, 2017 7:51 am

what AntonSynytsia say is right, but he is forgetting one part.
the body has unlimited capacity to push other body around.
this is what justify the existence of kinematic body, they are static bodies with mass.

this has to do with conservation for momentum
when two rigid body collide at the moment of collision the total momentum before collision should be equal to the total momentum after collision plus the loses during collision.
This principle is broken when we make the idealizing of a static rigid body.
a static rigid body is one in which has infinity mass.

this makes that when a dynamics body collide with a static body, the momentum that is distributed to the static body is lost because an infinity mass (wich is just a large number) multiplies by zero (the velocity) is always zero therefore the amount of momentum of a static before and after collision is zero, simple because its velocity is zero.

Now imagine a static body with a non zero velocity, its momentum is nearly infinite in computer terms, so this body is relentless in its motion and can push around any obstacle with sale mass. this why AntonSynytsia see then penetrating any other body.

you can try the experiment with this static collision calculator.
http://www.convertalot.com/elastic_coll ... lator.html
try making the mass of one body as big as you can, you will see that as long as it velocity is zero, it

acts just like in newton, but the moment you set its velocity to non zero, then the other body start receiving unreality values of velocities.

To remedy this problem of moving a static body around and not having it acting unrealistic, I added the kinematic body, which is a static body with mass. now this body act as dynamics body when colliding but they behave like static body in the scene in the sense that the do not get integrated.

This could has been an option on the body but as time progressed I realized that kinematic bodies has some other properties, like they occupy a special location on the body graph and other that I do not remember now, but their application goes beyond just been a flag on the body.

in conclusion AntonSynytsia observations are correct, in the sense if he reset the velocity each time plus he has to integrate then himself, but this is precisely what kinematic are designed to at a much lower cost. it is just better to integrate the kinematic body manually.

there is a game that uses Newton called ship simulator, is a very big mesh that moves around with a special dedicate simulator, but is has bodies on top, this motion is a big problem.
by making the ship does no has infinity mass an being kinematic make possible, the objects in them do not get unreality pushes.

The idealization of rigid body does not support the concept of infinity mass body, because such thing does not really exist in nature, my solution to represent that is the kinematic body.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Code] Setting Bodies Static

Postby Julio Jerez » Thu Mar 09, 2017 7:53 am

AntonSynytsia please try to represent the same video using a kinematic body. you should get better result, or a the very least the same.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Code] Setting Bodies Static

Postby AntonSynytsia » Thu Mar 09, 2017 12:54 pm

Julio, thanks for the extensive feedback.

In the original clip example there was a typo. I applied a lower velocity than the speed at which the matrix position was shifting. That's why objects were slowly sliding off.

In the following clip the positions are updated properly. I also added kinematic bodies, to see the difference between static dynamic bodies. The details are described in the clip: https://drive.google.com/open?id=0B3qg8 ... VNlNTJpbGM

Joe, as Julio described, I think that kinematic bodies are more suitable for static movements, but kinematic bodies are meant to always be kinematic. Dynamic bodies, on the other hand, can be altered between static-dynamic and movable-dynamic, simply by zeroing-out/restoring the mass matrix when necessary. So, there are gains and looses on both sides.
Last edited by AntonSynytsia on Fri Mar 10, 2017 1:48 am, edited 1 time in total.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm

Re: [Code] Setting Bodies Static

Postby JoeJ » Thu Mar 09, 2017 2:02 pm

I never tried it out, but what would happen if we set a very small mass for the kinematic body.
Would a heavy body on top sink into it because we fool the collision system to think kinematic body would move 99% and dynamic body only 1%?

Can this cause any problems like ending up resolving collisions almost only by the constant velocity seperating error correction?
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: [Code] Setting Bodies Static

Postby Julio Jerez » Thu Mar 09, 2017 2:57 pm

I think that kinematic bodies are more suitable for static movements, but kinematic bodies are meant to always be kinematic. Dynamic bodies,

yes that much is true. if you need to change the state of the body on fly then yes, that's a solution just remember, that a static body colliding with a dynamics body will transfer a much large momentum to the body that you would expect, make sure you set restitution to a low value.

For example say you have a ball falling on a static body with a restitution of 1.0
the ball will bounce with a velocity on 1.0 (not withstanding the limitation of Euler integration).
now imagine the static body has a velocity of one going up, now you would expect the ball to bounce with velocity of 2.0, instead you get a velocity of about 4.0, twice the difference (in this case 4.0)
you can try that experiment with the collision calculator I posted.
Most people will see that as a malfunction, but it comes straight out of the equations.
The reason this would be wrong is not because of the equations are wrong but because at that point we are applying the equations to a problem outside of the domain it can handle.

People do not have experience with collision with moving object with infinite mass, and even when there do have experience with objects with very large mass ratios, what happen is that in these cases one object get deformed and the momentum is converted to other kind of energy deformation.

Again the reason that kinematic bodies has mass, is so that some amount of movement gets transferred to the kinematic body and is lost, otherwise you get terrible explosions because like I said
a static body with velocity has the capacity of generation momentum out of nothing.
therefore each time a collision occur he generates twice the momentum of the other body, but he never loses anything.

keep experimenting you will find this out by yourself, but is a really bad idea to add velocity to a static body.


JoeJ wrote:I never tried it out, but what would happen if we set a very small mass for the kinematic body.
Would a heavy body on top sink into it because we fool the collision system to think kinematic body would move 99% and dynamic body only 1%?

Can this cause any problems like ending up resolving collisions almost only by the constant velocity seperating error correction?

The kinematic body will gain a huge velocity. I suppose it will be a problem yes. But again that is not what kinematic bodies are for, they are a solution to the problem of gaining momentum from collision with static bodies with non zero velocity. They should have a relatively large masses.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: [Code] Setting Bodies Static

Postby JoeJ » Thu Mar 09, 2017 5:44 pm

OK, thanks.
Probably i never experienced any problems with any settings because i use zero restitution material.
Setting it to 1 will help me to find proper masses :)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: [Code] Setting Bodies Static

Postby AntonSynytsia » Fri Mar 10, 2017 1:50 am

Thanks again, Julio. I will stick to kinematic bodies for moving platforms.
AntonSynytsia
 
Posts: 193
Joined: Sat Dec 28, 2013 6:36 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 12 guests

cron