Compensate thermal displacement using measured distance