Distance functions and optimal taxation