Given the spheres in 3D space: center(xi,yi,zi), radius and density and the info is stored in an array sphere_data[n][5]:
// Sphere_ID x y z radius density
1 x1 y1 z1 rad1 density_1
2 x2 y2 z2 rad2 density_2
...
n xn yn zn radn density_n
So how to calculate the center of mass for this cloud of 3D sphere?
Any tips or recommendation would be appreciate.
If the center of the mass of the system is $(x,y,z)$, we then have $$x = \dfrac{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i x_i}{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i} = \dfrac{\sum_{i=1}^n r_i^3\rho_i x_i}{\sum_{i=1}^n r_i^3\rho_i}$$ $$y = \dfrac{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i y_i}{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i} = \dfrac{\sum_{i=1}^n r_i^3\rho_i y_i}{\sum_{i=1}^n r_i^3\rho_i}$$ $$z = \dfrac{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i z_i}{\sum_{i=1}^n \dfrac43\pi r_i^3\rho_i} = \dfrac{\sum_{i=1}^n r_i^3\rho_i z_i}{\sum_{i=1}^n r_i^3\rho_i}$$