Use Encoder to Calculate Distance