Combine 2 Physics objects

Started by
23 comments, last by Cacks 5 years, 9 months ago
6 hours ago, JoeJ said:

Usually physics engines support only to express the inertia of an ellipsoid (not even a simple box can be expressed accurately)

Inertia allways expressed as ellipsoide. It come from analitical mechanics, not from engine limitations. Each body regardless of it shape have a 3 general inertion axes so it have 3 inertion momentums respectively to each of general axes. So if you make a tensor from its momentums, it exacty match a tensor of ellipsoide quadric.  It why inertion tensor also known as ellipsoide of inertion.

#define if(a) if((a) && rand()%100)

Advertisement
1 hour ago, Fulcrum.013 said:

Each body regardless of it shape have a 3 general inertion axes so it have 3 inertion momentums respectively to each of general axes.

But it's only an approximation of the real thing which can be pretty bad.

There is an alternative matrix representation instead just 3 values. But i never used it and i don't know which shape it can describe and how that's better. (Just a skewed ellipsoid, or some asymmetric shape ?)

It would not be the first time i start to argue about this with physics people, so i wonder if you agree...

For a quick test, you could make a box out of point masses placed on a regular grid (e.g. a block of minecraft voxels). Then you pick a direction between two opposite diagonal corners through the center and calculate inertia by summing up (mass(i) * projectedSquareDistToCom(i)). The result differs from the one you get form the analytical ellipsoid.

If you visualize all directions, the shape you get could be expressed better with spherical harmonics, but i doubt this holds for more complex shapes and i'm happy with ellipsoids.

 

 

4 hours ago, JoeJ said:

It would be interesting to look if there are two kinds of up vector constraints, one for Unity objcets, and another on top of a PhysX joint which works as expected. 

I just want to clear up the confusion here, before Unity developers accuse me of selling the engine short. Compound collisions and Joint collisions isn't the same thing, although joints also allow for Compound collisions.

Compound collisions is a simpler and faster collision system. As long as there is gravity or a similar force involved it works perfectly. This is realistic as in the real world all physics bodies exercise a pull on each other, so there should always be some force, no matter how small, affecting a object.

I don't think the images shows it clearly, so I made a Gif:

Compound.gif.dfa4f0cea9668bd0a3e43f69dd07338b.gif

As can be seen here, the constraints should have kept the game playing on a 2D axis, but the compound collision sends it rotating in a relative axis, moving it in 3D space. The effect is much less noticeable with gravity, it is easy to fix.

Using joints will fix this, but really not necessary for such a small thing.

4 hours ago, JoeJ said:

Is this the same with UE?

If you use the fast compound collisions yes. I think it is part of the formula, like a rotation vector based on gravity that isn't allowed to be zero, that is what I think.

Unreal actually has over 24 collision modes, however these can be placed into 3 classes. 

1.) Single body collisions. You make these using the Unreal collision editor or by importing them. Think of this as a advanced convex hull system. You can use more than one collision shape here to make a custom collision shape, as long as the shapes don't overlap. Also K-DOP shapes.

2.) Joint collisions. This can be compound or not, the developer decides. Also supports 6DOF mode. These are easy to be setup inside the blueprint system of Unreal, by just adding in a joint component.

3.) Compound collisions. These are exactly like the Unity compound collisions but they are not so easy to use. They only work on Pawn Blueprint classes and have to be made using the Unreal Physics assets. These are used for character and gun collisions.

 

All these systems have more modes and preferences, it is easy to see why people think Unreal is a heavy to use engine. In Unity you just parent two collision objects to get compound collisions, or use a joint component.

42 minutes ago, JoeJ said:

But i never used it and i don't know which shape it can describe and how that's better.

It shape always ellipse. If you calculate inertion moment reapectively to all possible axes its values will draw a ellipsoide.

 

42 minutes ago, JoeJ said:

There is an alternative matrix representation instead just 3 values. But i never used it and i don't know which shape it can describe and how that's better. (Just a skewed ellipsoid, or some asymmetric shape ?)

It is not alternative, it is same. Matrix define a rotated ellipsoide and consists of factors from rotated ellipsoide equation. It used to make calculations using basis not aligned to general inertion basis. For basis aligned with general inertion basis ellipsoide is not rotated so any factors but its 3 values placed on general diagonal is zero. It is why general inertion axes  and general inertion momentums called general. 

 

#define if(a) if((a) && rand()%100)

3 hours ago, Scouting Ninja said:

Compound collisions and Joint collisions isn't the same thing

The term 'Joint collision' should not even exist. (From all you say i see it must be very confusing to handle physics engine as an Unity user, so what i say is not meant as correction, but in hope to limit some confusion...)

If you connect two bodies with a joint, they still remain two bodies, both of them are simulated, but a joint limits their relative degrees of freedom and can also include motors. If the joint limits all DOFs it is a 'fixed' joint, and the two bodies behave as if they would be only one solid body (compound). But the difference is:

* You can just enable or disable the joint to let the bodies disjoint or not (never a need to recalculate fused mass properties).

* You have to expect robustness issues like oszillation (jitter), much worse if the number of bodies becomes larger than just two.

* Inertia is not approximated by a single ellipsoid (so you could simulate complex shape more accurate if desired).

So in practice fixed joints are good for temporary connections, like a character driving a vehicle for a while an then continues to walk. But you always consider to use a compound instead for performance and stability reasons.

 

Compound really is to use multiple convex hull collision shapes to form a single body. Only one body is simulated by the physics engine. A collision against one of its sub-shapes can never cause the shapes to displace relative to each other. But you still have the option to remove / add / displace bodies yourself outside of the physics update. (Probably game engines do not expose all physics engine features.)

Usecase is to model a shape like a torus. You would need to join a large number of convex cylinder bodies to approximate such a shape. Using compound it is just one body solves and integration is as fast as for a simple box. (But collision detection is still more expensive because all subshapes need to be checked.)

 

The issues you get from up vectors / gravity still seems to be some kind of flaw to me. Probably caused by not making clear if those constraints are Unity constraints meat for procedural / kinematic animation, or physics joints meant for simulation. Those things should be seperated by both GUI and terminology, it seems this is done done totally right from what you say.

I really should take a closer look myself at those engines some day... i'm still left in confusion, although you've spent lots of efford. Maybe there is one more thing about inertia to tell - if you do not know that, it's a win:

Nonuniform inertia affects simulation robustness, meaning a long thin object is much more likely to cause jitter and such. So it is often worth to manually change inertia to be more uniform. E.g. for a ragdoll, the joints have much more impact on turning resistance than inertia anyways, so you can make each body to have uniform inertia and the effect is not noticeable, but jitter may be reduced dramatically. I guess this often happens automatically (Havok export tools had a checkbox to let the user decide), but it's worth to check it out. (Personally i often use inertia from a solid sphere that has the same volulme than the real body and replace the inertia numbers with that).

... hoping anything of this is useful :)

 

4 hours ago, Fulcrum.013 said:

It shape always ellipse.

I take this as an agreement that 3 number inertia is an approximation for anything that is not an ellipsoid. (Why do you physics guys always dodge this question? :D )

4 hours ago, Fulcrum.013 said:

It is not alternative, it is same.

No, i do not mean to use the matrix to have rotated representation of 3 number inertia, i mean something than can do more than an ellipsoid. I think Newton has support, but i also remember it form reading papers from the Baraff / Mirtich times, and i connect it with the term 'asymmetric inertia' (but that may be wrong).

 

 

 

 

1 hour ago, JoeJ said:

i do not mean to use the matrix to have rotated representation of 3 number inertia

Matrices is just a other form of representation of quadric equation https://nb.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/quadratic-approximations/v/expressing-a-quadratic-form-with-a-matrix

1 hour ago, JoeJ said:

also remember it form reading papers from the Baraff / Mirtich times

Mirtich like any other math and physic guys use a matrix representation for any equations where it possible, becouse it much shorter then polinomus.

 

2 hours ago, JoeJ said:

and i connect it with the term 'asymmetric inertia' (but that may be wrong).

 Some kind of asymetri may come from rotations respectively to other point than center of masses, for example for joint rotation.  So to find a inertion moment for shifted center used a rule of aхis shift that together with rotation of ellipsoide represented by extended 4x4 matrix, that is form of representation of full quadric equation that have all factors nonzero. 

#define if(a) if((a) && rand()%100)

2 hours ago, JoeJ said:

Inertia is not approximated by a single ellipsoid (so you could simulate complex shape more accurate if desired).

https://en.wikipedia.org/wiki/Moment_of_inertia 

#define if(a) if((a) && rand()%100)

3 hours ago, Fulcrum.013 said:

Some kind of asymetri may come from rotations respectively to other point than center of masses, for example for joint rotation.  So to find a inertion moment for shifted center used a rule of aхis shift that together with rotation of ellipsoide represented by extended 4x4 matrix, that is form of representation of full quadric equation that have all factors nonzero.

9 hours ago, Fulcrum.013 said:

It is not alternative, it is same. Matrix define a rotated ellipsoide and consists of factors from rotated ellipsoide equation. It used to make calculations using basis not aligned to general inertion basis. For basis aligned with general inertion basis ellipsoide is not rotated so any factors but its 3 values placed on general diagonal is zero. It is why general inertion axes  and general inertion momentums called general. 

Yeah, i think that's it. I was reading up on Newton forum, and the developer mentions asymmetric inertia in combination with full inertia matrix support when he made a simulation of a Rattleback (toy thing that only wants to rotate counter clockwise). This has an elliptical shape, but the inertia is rotated a bit off (achieved by additional weights or holes in real world to affect density). So full inertia matrix means the option to rotate the inertia from the principal axis, which is useful for primitives like capsule / box / ellipsoid etc. (for a polyhedron you could just rotate the geometry instead.)

I finally get it. The rest i've remembered just wrong, thanks!

 

Edit: Haha - I was puzzling about some matrix math in Newtons code while looking it up, and the Khan video explains it. :) I should watch more of this...

1 hour ago, JoeJ said:

So full inertia matrix means the option to rotate the inertia from the principal axis,

Inertia  ellipsoide  position and orientation depends from body's mass distribution only. So ellipsoide have his centre in centre of mass that in general case not match a model space origin and general inertion axes rotated. Homogenous spheres, boxes, capsules, cylinders, boxes, ellipsoides have a center of mass at its geometrical center, and like a cone have main inertion axes alligned to sides/rotation axe. But for other kind of shapes like as for compound or heterogenous matherial shapes inertion basis not match model space basis. 

Like centre of mass match a symmetri planes for symetrical bodies, general inertion axes always lies in the planes of symmetri. It whay most of animals and moving machines allways symmetrical - to keep at least one of general inertion axes into same plane with forward movement direction.

Also capsules, cylinders, ellipsoides, cones, parabaloids an other quadrics can be represented by same matrix, but with other set of factors, and as result rotated and shifted, like as any equation. To transform any equation it require to substitute vectors of new basis to variables of equation and then open the brackets and calculate factors. It is what actually transformation matrices do for linear equations. For quadric equations it work little bit complexive and require 2 matrix multiplication. Just higher power equation usualy not represented by matrix becouse used much rare than  linear and quadric  equations.

#define if(a) if((a) && rand()%100)

2 hours ago, Fulcrum.013 said:

To transform any equation it require to substitute vectors of new basis to variables of equation and then open the brackets and calculate factors. It is what actually transformation matrices do for linear equations. For quadric equations it work little bit complexive and require 2 matrix multiplication. Just higher power equation usualy not represented by matrix becouse used much rare than  linear and quadric  equations.

Interesting (and new to me, but it already helps).

What would be the simplest general problem you can think of where this is useful so i can practice that?

I want to look at how quadric error metrics for mesh simplification works anyways, but if you know something simpler please let me know...

This topic is closed to new replies.

Advertisement