Higher-order derivatives of rigid body dynamics with application to the dynamic balance of spatial linkages