Function for computing linear distance between two points