Optimal rotations of deformable bodies and orbits in magnetic fields.