Convergent evolution of mechanically optimal locomotion in aquatic invertebrates and vertebrates