Calculate the distance between two points in cartesian space