[ODE] Re: center of mass

Nagymathe Denes denes at invictus.hu
Thu Oct 20 18:00:32 MST 2005


:o)

> Now let me summarize things I know and what you told together to see if I 
> got things as they should.
> If we virtually add a mass to each geom of a complex geom stuff; orienting 
> each geom with geomtransform
> we need to do the same transformation to the mass as the mass position 
> wont follow (but where is the mass at start ?
The masses are completely independent of geoms. Geoms themselves are 
'weightless shells'; we used to attach the mass and inertia properties of a 
similar (but solid) shape of the collision geom to the body, but not 
necessarily. It's just because usually if you see a box, you expect it 
moving like a solid box; but it could even be an emtpy cardboard box with a 
heavy ball inside...

> cos we don't position it and we dont attach it... at 0,0,0 Am I right ?).
Note that the pos and R of geoms within geomtransform means their _relative_ 
pos and R in respect to the cm, doesn't matter where they are in  world 
coordinates.

> Summing the masses build up a center of masses of the complex object, 
> which is wherever placed.
> Now we need to put a rigid body to be linked to all these geoms. This 
> rigidbody has to be at this center
> of mass (why moving the geoms instead of the body ? strange), so we set 
> its position to the mass position
> vector mass.c.
Yes. You could move the body instead of moving all the geoms. In that case 
you'd have to rotate mass.c with R and add the result to the original pos. 
Simpler than moving the geoms, right. The only difference is that in this 
case the cm of the resulting compound object wouldn't be exactly at the 
originally given position.

> The example does moving geoms to this center of mass m:
>  for (k=0; k<2; k++) {
>    dGeomSetPosition (g2[k],
>              dpos[k][0]-m.c[0],
>              dpos[k][1]-m.c[1],
>              dpos[k][2]-m.c[2]);
>      }
>
> But then it moves the center of mass ????
> dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]);
Yes. Now, as you've corrected the relative positions of the geoms, and the 
body is exactly at the cm, you need centered cm for the body, aren't you? 
:o)
This function effectively 'zeroes out' m.c substracting itself from it.


> And there is something strange too: I can't draw the right geomtransform 
> geoms. Well I draw them but they do not move
> with the object if I don't use the same drawGeom function of the example 
> i.e what is this for ? :
> dGeomID g2 = dGeomTransformGetGeom (g);         // I do that
> const dReal *pos2 = dGeomGetPosition (g2);           //that too
> const dReal *R2 = dGeomGetRotation (g2);            //this as well
>
> Then I think its sufficient but:
> dVector3 actual_pos;           /* I don't do this strange transformation 
> */
> dMatrix3 actual_R;
> dMULTIPLY0_331 (actual_pos,R,pos2);
> actual_pos[0] += pos[0];
> actual_pos[1] += pos[1];
> actual_pos[2] += pos[2];
> dMULTIPLY0_333 (actual_R,R,R2);
> drawGeom (g2,actual_pos,actual_R,0);
See above; It's just because geomtransform is a sort of 'hack', and pos and 
R of a geomtransform-ed body is its _relative_ pos and R, so remains 
unchanged all the time. The current world-space pos and R can be calculated 
this way (that's about the same what a geomtransform performs when it needs 
to collide; gets the pos and R of itself (usually the body) and the rel. 
data, calculates the worldspace pos and R of the embedded geom, temporarily 
'overwrites' its data, performs coll. check, and restores the original 
relative data.).


> Finally if I attach a joint to the rigidbody of a complex geoms object, I 
> don't have any idea how
> the joint will be linked in reality between this complex object and 
> another rigidbody. Do you ?
> To the closest geom virtually ?
No. :o) It will connect the invisible bodies 'behind' the visible geoms or 
complex geom groups. Remember: geoms are ONLY used for collision detection, 
nothing else. Even visualizing them is just for debugging :o) as games used 
to render much more complex geometries instead of the 'real' geoms used for 
their collision tests. :o)
The thing that confuses most novices is that the 'real' bodies that are 
subject of the forces, torques, movements, joints, etc. cannot really be 
visualized as they themselves don't have any shape. But they have positions, 
velocities, and mass properties, and can carry these 'shells' called geoms. 
So we used to render the geoms, but the bodies are like 'ghosts in the 
shell' :o))

Denes




More information about the ODE mailing list