calculate the center of gravity