NewtonBodySetMassProperties usage

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonBodySetMassProperties usage

Postby misho » Fri Mar 09, 2018 3:40 pm

Hi,

I need to change the mass of an object with time - is this possible in Newton? My case is, I have a vehicle that expends fuel with time and becomes lighter.

One method that seems to let me do that is

NewtonBodySetMassProperties()

I haven't experimented with it, but in the tutorials it seems to be used only during the initial creation of the body.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby Julio Jerez » Fri Mar 09, 2018 4:41 pm

you NewtonBodySetMassProperties can use that any time, bu that is an expnsivel operation,

you can instead save the values afte initialization by calling, NewtonBodyGetMass
which will give you the mass and inertias
the you can use, NewtonBodySetMassMatrix with a scale factor of the one you saved

NewtonBodySetMassMatrix only assign the mass to the body NewtonBodySetMassProperties calcual the inertia from distribution from the shape.

if you do not win to save the values you can also do like this:
1-Get the collision shape from the body
2-Get the inertia from the shape. this a unitary inertia matrix
3-mutiplay the unit inertia by the new mass,
4-Call NewtonBodySetMassMatrix
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetMassProperties usage

Postby misho » Fri Mar 09, 2018 4:48 pm

Great, thanks!

How "expensive" is that operation? I'd call this on only one body at a time...

To push this even further: Is it possible to set mass on only one collision member of a compound collision?

For example, I want to include car's gasoline tank as a separate collision member of a compound collision, and I want it to decrease in mass as the gas is being expended. The reason would be, this change in mass would alter the CG and MOI values, slightly, but I'd like to simulate that change.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby Julio Jerez » Fri Mar 09, 2018 7:24 pm

yes you can, using NewtonBodySetMassProperties.
suppose the image below represent the vehicle,
collision.png
collision.png (4.88 KiB) Viewed 6760 times


say the top image is the vehicle with a full tank of gas, calling NewtonBodySetMassProperties with that collision shape will calculate the proper inrtia and center of mass.

say that later on your vehicle uses some gas and now the tank weigh less, you can get the collision shape and make a copy by calling
NewtonCollision* NewtonCollisionCreateInstance (const NewtonCollision* const collision);

then you find the sub shape that represent the gas tank and you scale it new volume, then you call NewtonBodySetMassProperties with this modified new shape and the new COM and inertia will be set correctly. there are functions to get the volume of the sub shapes if you need that.

You can hold to the helper shape or delete it if you like, the entire operation are very efficient, in teh sence that the operate in time linear to teh number of shape.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetMassProperties usage

Postby misho » Fri Mar 09, 2018 10:21 pm

Perfect Julio, that's exactly what I needed!

And I do appreciate the illustration!!! :D

Misho
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby misho » Fri Mar 30, 2018 2:18 am

Julio Jerez wrote:you can instead save the values afte initialization by calling, NewtonBodyGetMass
which will give you the mass and inertias
the you can use, NewtonBodySetMassMatrix with a scale factor of the one you saved


Ok - if I understood you correctly, this is how I went about it:

At body creation:

Code: Select all
   // create a body with given compound collision and mass
   eObject->nBody = CreateRigidBody (world, eObject, objectCollision, eObject->GetGrossMass());
   // grab the inertia which will be later used to set decreasing mass to the body
   dFloat dummyMass;
   NewtonBodyGetMass(eObject->nBody, &dummyMass, &eObject->inertia.m_x, &eObject->inertia.m_y, &eObject->inertia.m_z);


I have 3 values that keep track of mass:

  • Gross Mass, the original mass of the rocket hardware PLUS propellant
  • Empty Mass, the mass of rocket hardware alone
  • Propellant Mass, calculated from (Gross mass - Empty Mass)

Then, inside ApplyForceAndTorqueCallback(), I calculate and apply the new mass:

Code: Select all
// mass depeletion due to propellant expenditure
double fCurrentMass = ent->GetPropellantMass() + ent->GetEmptyMass();

// set the body mass matrix
dFloat massScale = fCurrentMass / ent->GetGrossMass();
ent->inertia.Scale(massScale);
NewtonBodySetMassMatrix(ent->nBody, fCurrentMass, ent->inertia.m_x, ent->inertia.m_y, ent->inertia.m_z);


Does this look correct? I think my other thread, where I seem to have problem with thrust and gravity, has something to do with incorrect inertias...
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby misho » Sun Apr 01, 2018 2:45 pm

Any thoughts on this?
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby Julio Jerez » Sun Apr 01, 2018 2:56 pm

no is not correct,

you need to make a compound collision to set the mass matrix, and use for that.

the went you want to change the mass distribution you just change the collision part, and calculate the new mass and call function
void NewtonBodySetMassProperties (const NewtonBody* const bodyPtr, dFloat mass, const NewtonCollision* const collisionPtr)

every time.

you can use the concept of density; which is the Mass / volume of the shape
then say the tank change to half tank, that mean is have less Gas, you can assume the tank is a perfect fit, so you calculate the tank volume by 0.5
now the collision shape has a different mass distribution.

you also cal calculate ethe new mass by subtracting getting the volume of the gas tank and multiplying by the desity of the gas.

so the new mass = mass0 - GasTankVolume * fliudDensity;

now you have both the new Mass, and the new mass distribution, you call
void NewtonBodySetMassProperties (const NewtonBody* const bodyPtr, dFloat mass, const NewtonCollision* const collisionPtr)

and you apply top the body. you do that ever time a sub shape changes.




the new volume of the shape
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonBodySetMassProperties usage

Postby misho » Sun Apr 01, 2018 3:29 pm

Hold on - let's back up:

  • I'm not yet at the "localized gas tank" stage - let's first consider the original problem: a whole single body being a gas tank, and the whole body is losing mass.
  • You told me NOT to use NewtonBodySetMassProperties() function because it is too expensive - so I am not. My code does exactly what you suggested (see above), and I AM seeing proper mass-depleting behaviour, but I am wondering if this is correct with respect to MOI calculations, because I am seeing strange behaviour, described in my other ("enigma") post - I think the two are related.
Misho Katulic
CTO, FSX SpacePort
TerraBuilder
www.terrabuilder.com
misho
 
Posts: 673
Joined: Tue May 04, 2010 10:13 am

Re: NewtonBodySetMassProperties usage

Postby Julio Jerez » Sun Apr 01, 2018 4:24 pm

I said not using if you are not going anything like what you are doing.
I you know what the mass and the inertia then SetMassMatrix is the fastest way,
if you are doing mass distribution calculation at run time,
then NewtonBodySetMassProperties is the fastest way of doing it. any other way will be far worse.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests

cron