Mass and geometry offset problems

23 views
Skip to first unread message

Nicolas B.

unread,
May 12, 2008, 1:48:54 PM5/12/08
to ode-users
Hi all,

I have a problem to offset both the geometry and the mass of a body. I
want to create a box with dimensions (3.0, 0.5, 0.5), with it center
at (0.0, 10.0, 0.0), with an offset rotation of 45 degrees on Z axis,
with weight 1.0. I tried the following code, extrapolated from various
tutorials :

// Create a body
dBodyID lBodyId = dBodyCreate(lWorldId);

// Mass setup
dMass lMass;
dMassSetBoxTotal(&lMass, 1.0, 3.0, 0.5, 0.5);
dMassRotate(&lMass, lRot);
dMassTranslate(&lMass, 0.0, 10.0, 0.0);
dBodySetMass(lBodyId, &lMass);

// Put the center of mass at 0.0, 0.0, 0.0 else ODE cry
dMassTranslate(&lMass, -lMass.c[0], -lMass.c[1], -lMass.c[2]);

// Geometry setup
dGeomID lGeomId = dCreateBox(lSpaceId, 3.0, 0.5, 0.5);
dGeomSetOffsetQuaternion(lGeomId, lRot);
dGeomSetOffsetPosition(lGeomId, 0.0, 10.0, 0.0);


This code does not work : the box moves as it has a very shifted
center of mass. One thing that disturbs me a lot is the constraint to
have the center of mass at 0.0, 0.0, 0.0. I would be very happy to
have a corrected version of that code.

The answer in the case of composite objects would be also welcome :
I've played with dGeomSetOffsetxxx and dMassSum, but again, I got very
shifted center of mass leading to non-sense simulations.

Any help would be greatly appreciated! Thanks!

cheers

Daniel K. O.

unread,
May 12, 2008, 4:22:11 PM5/12/08
to ode-...@googlegroups.com
Nicolas B. escreveu:

> I have a problem to offset both the geometry and the mass of a body.

AFAIK, this can't be done in ODE. Bodies don't accept masses that are
not centered at the origin. The only purpose for the center information
in the mass structure is so you can add a bunch of them, and (before
putting it on the body) center it before sending it to the body. Then
you offset the geoms accordingly to how much the mass was translated.


Pseudo-code:
-- 8< -- 8< -- cut here -- 8< -- 8< --
create a zero mass, Mt
for each geom to be added at position Pi:
create a mass Mi for this geom
dMassTranslate(&Mi, Pi[0], Pi[1], Pi[2]);
dMassAdd(&Mt, &Mi);

c = Mt.c //this is a vector

// Center the mass:
dMassTranslate(&Mt, -c[0], -c[1], -c[2]);
dBodySetMass(body, &Mt);

for each geom (again):
Gi = dCreate...(...);
dGeomSetBody(body, Gi);
dGeomSetOffsetPosition(Gi,
Pi[0] - c[0], Pi[1] - c[1], Pi[2] - c[2]);

-- >8 -- >8 -- cut here -- >8 -- >8 --

That is, after accumulating the masses you'll know how by much you have
to translate everything, both the mass, and the geom offsets: "-c".

For your particular case, the first loop would end up with Mt centered
at (0,10,0), thus c = (0,10,0). So your geom offset, (0,10,0) would be
canceled by adding "-c" in the last line.


This limitation is more of a design decision. I believe some important
equations would have to be updated to handle non-centered masses
(probably to just "center" them for calculations, then move them back),
and you would gain almost nothing (would shorten the above code in just
2 lines).


--
Daniel K. O.
"The only way to succeed is to build success yourself"

Jon Watte

unread,
May 12, 2008, 6:07:11 PM5/12/08
to ode-...@googlegroups.com
Nicolas B. wrote:
> I have a problem to offset both the geometry and the mass of a body. I
> want to create a box with dimensions (3.0, 0.5, 0.5), with it center
> at (0.0, 10.0, 0.0), with an offset rotation of 45 degrees on Z axis,
> with weight 1.0. I tried the following code, extrapolated from various
> tutorials :
>

The center of gravity is always the center of the body. However, that's
not really a big problem, because the body has no physical extent. Thus,
put the body where you want the physical center of gravity, and then put
the geom/geoms relative to that location where you want them.

For example, for a car with very low center of gravity, you might want
the COG at 0,0.01,0. With 0.2 meters of clearance, and a 0.5 meter tall
body, you would want the center of your collision geom box to be at
0,0.45,0. You implement this by placing the body at 0,0.01,0, and
placing the geom at 0,0.44,0 offset of the body.

Sincerely,

jw


Nicolas Bredeche

unread,
May 14, 2008, 4:55:51 PM5/14/08
to ode-users
Hi again,

  Thank you for the answers, after some troubles to follow your advices, I
got the trick. The trick is, for composite or basic objects :
 1) Create a dBody instance
 2) Compute the corresponding dMass instance, in the *local* object
coordinates, by playing with dMassAdd, dMassTranslate and dMassRotate
 3) Store the center of mass of the dMass in a temp variable, and
translate the dMass object to 0,0,0
 4) Set the dBody with the dMass instance
 5) Move the dBody instance to the center of mass previously saved in a
temp variable, with a dBodySetPosition call
 6) Hooking dGeoms instances to the dBody instance, in the *local* object
coordinates, with the propers offsets
 7) And finally set the position and the orientation of the dBody
instance, with dBodySetPosition and dBodySetQuaternion, to match the
*global* object coordinates.

A wiki entry of this might be welcome ;)

Reply all
Reply to author
Forward
0 new messages