Recently I was trying to solve a small AI problem but got stuck in between as I could not find the center of mass of the various bodies.
I was wondering if any one of you could help me out with this one.
Problem explanation: Assume that i have a 2D body which is very irregular in shape and has a uniform mass distribution throughout. It’s like the body is made up of ‘n’ tiny particles each of unit mass and hence though the body is very irregular in shape but the mass distribution is uniform. How can I locate the center of mass or center of gravity of this body?
Avanish!!
OK. I get it now. You have a vast number of discrete particles to work with. With emphasis on the big number.
Well, why didn’t you say?
You can’t do it exactly (i.e. without approximation) any faster than iterating though all the points. At least not without providing more relevant information.
Adam’s sampling suggestion is a good way to obtain an approximation if you have random access to the data.
An alternative that won’t be faster for a single operation, but might be useful if you are going to have to recalculate often is to reduce the working set to a smaller group of heavier points. Something like this:
N_x * N_y * N_zcells of sizes(l_x,l_y,L_z).For this to represent an improvement, you’ll want to have an average of 10 or more original points per cell, but not so many that the introduced grandularity washes out the signal you are looking for.
How best to do step 2 depends on how the original data is organized and on how much room you have in memory to store intermediate results. With lots of memory available:
M,Rx,Ry, andRz(or one scalar arrayMand one vector arrayR, that depends on your implementation language)With relatively little memory but lots of time available for pre-calculation you would walk the main list once for every cell (but if you have that kind of time you probable can just do this straight).