Centre Of Gravity How?

Blitz3D Forums/Blitz3D Programming/Centre Of Gravity How?

_PJ_(Posted 2010) [#1]
With respect to a 'physics (mechanical approximation) engine', if I had a non-uniform mesh, with a non-central centre of gravity, what is the best way to deal with the effect of gravity on that mesh?

My current thoughts are:
1- Set the HANDLE of the mesh to be at the physical centre coordinates
2- Set a pivot at the CoG coordinates
3- Calculate the force fractionally between the two points
4- Translate the mesh accordingly to the ratio of the two points' fractional gravity

5 - How to account for th effects of air resistancve etc. i.e. when a cone is 'balanced' on its point? In reality, this would never remain stable, but in a 3D simulation with a regular, symmetrical cone, the CoG would be directly above the balanced point.


Yasha(Posted 2010) [#2]
Are you talking about implementing some of the role of a physics engine yourself?

Because if you're using an existing physics solution such as ODE, the simplest thing would probably be to set the mesh handle wherever you want the centre of gravity, and let the engine take care of the rest. You shouldn't have to do anything else yourself.


_PJ_(Posted 2010) [#3]
I am coding a simple physics (mechanical approximation) 'engine' myself.
Essentially,k just dealing with the meshes having a weight and 'physical' geometry for collisions etc.

note: that assuming (which works for my purposes) the 'material' of the objects and their density is uniform, then the centre of gravity's location ought to be calculable. I can't just "place the handle" where I want the centre of gravity to be without first calculating the centre of gravity...


Yasha(Posted 2010) [#4]
Hmmm...

As far as calculating the centre of gravity goes, I don't think there is an easy way for arbitrary shapes (I hate those words... finding the easy way is the whole point of programming). If your object is easily broken down into regular primitives, it's a different matter, of course. What are you looking for here - are you wanting to dynamically apply physics to any closed mesh, or do you have a prepared set of meshes and props whose centres you can calculate in advance?

As far as calculating the centre of gravity of an arbitrary shape goes, the only way I can think of offhand is to use a particle-based physics system - "fill" the mesh volume with a few hundred particles arranged in a regular, rigid structure and use a trial-and-error algorithm to literally measure the centre of gravity. This would be ridiculously slow, but shouldn't be too hard for shapes of uniform density (on the other hand, it sounds pretty cool... might write this myself...).

What is important is that you don't need to recalculate the centre of gravity once you've found it. I'd still go with putting the mesh handle at the centre of gravity once you've found that point - even if you're not using ODE, I recommend you take a look at its wiki/source code to get a feel for how they handle this with their body/geom system.

Also, what are your aims with this system? I'd advise against trying to simulate air resistance in anything intended for real-time use.


_PJ_(Posted 2010) [#5]
Fortunately, I'm dealing with quite simple shapes. Essentially meshes built from collections/arrangements of cubes :) ... perhaps a maximum of less than 5 cubes per parent mesh. The actual arrangement of cubes within these collections, though, wont necessarily be known. This makes the calculation much easier of course.

Think (and you're onto a BIUG clue as to what I'm doing) - "3D 'Physical' Tetris"

Whilst not suitable for "any mesh", for the issue here, a simple algorithm which combines the total CoGs and find the average should suffice I think?

Sorry, I should have mentioned this earliewr that it's really not something very complex I'm aiming for,

My comment about air-resistance was really with regards to any real-life siutuation where incalculable factors are significant. Like trying to balance a very thin, tall cylinder on its end. I was wondering how best to introduce the randomnisity of air-resistance etc. without the complexity.


Yasha(Posted 2010) [#6]
If the component parts are cubes of the same size that don't intersect (making a few more assumptions based on "Tetris"), you don't even need to know the positions of the cubes within the main mesh... just take the average of every vertex's coordinates and you should have the centre of gravity.

If you want to add a little randomness... I suppose you could simply apply a random force just above the minimum threshold every few milliseconds? No idea about that one, sorry.


_PJ_(Posted 2010) [#7]
Thanks Yasha...
That makes sense of how to locate the CoG, thank you, now I jusdt need to get the trig in to determine how the offset affects the object.

I'm pretty sure it ought to be:

Distance from Pivot(Centre of contact with whatever it lands on)
Multiplied By
Cosine(angle)
Multiplied By Weight
Gives:
Ratio of torsional g-force?

It's still not clear how an object might 'slide' down if the CoG is pulling it... :S

I'll see how it works with what I have, who knows, Deus might be Ex Machina ;)