Added 3rd dimension: distance.

Also reworked all computations to let this update work.