[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Center of mass???

Anders Wennerberg (anders@mrc.ks.se) writes:

>    I have tried to find a routine that could calculate the center of
> mass, in preliminary 2D but in near future 3D.   I would be happy if
> anyone could give direction where to find that kind of routine.

Here is how you do it in 2D. I've never had to extend
this to 3D, but when you figure it out, please let us
know. I'll write up an article on it. :-)

  s = Size(array, /Dimensions)
  totalMass = Total(array)
  xcm = Total(Total(array,2) * Indgen(s[0])) / totalMass
  ycm = Total(Total(array,1) * Indgen(s[1])) / totalMass



P.S. Thanks to David Foster for the algorithm above.

David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155