A geometric characterization of a sharp Hardy inequality