How relativity determines the Hamiltonian description of an object in classical mechanics