Hamiltonian optics