Added method to calculate the energy of a ball.