Euclidean distance
In
mathematics, the Euclidean distance or Euclidean metric is the "ordinary"
distance between the two points that one would measure with a ruler, which can be proven by repeated application of the
Pythagorean theorem. By using this formula as distance, Euclidean space becomes a metric space . Older literature refers to this metric as Pythagorean metric.
Encyclopedia
In
mathematics, the
Euclidean distance or
Euclidean metric is the "ordinary"
distance between the two points that one would measure with a ruler, which can be proven by repeated application of the
Pythagorean theorem. By using this formula as distance, Euclidean space becomes a metric space . Older literature refers to this metric as
Pythagorean metric.
Definition
The
Euclidean distance between two points and , in Euclidean
n-space, is defined as:
One-dimensional distance
For two 1D points, and , the distance is computed as:
The absolute value signs are used, since distance is normally considered to be an unsigned scalar value.
Two-dimensional distance
For two 2D points, and , the distance is computed as:
2D approximations for computer applications
A fast approximation of 2D distance based on an octagonal boundary can be computed as follows.
Let and . If , approximated distance is .
The difference from the exact distance is between -6% and +3%; more than 85% of all possible differences are between −3% to +3%.
The following
Maple code implements this approximation and produces the plot on the right, with a true circle in black and the octagonal approximate boundary in red:
fasthypot :=
unapply:
hypot := unapply:
plots[display];
Other approximations exist as well. They generally try to avoid the square root, which is an expensive operation in terms of processing time, and provide various error:speed ratio. Using the above notation,
dx +
dy − ×min yields error in interval 0% to 12% . A better approximation in term of RMS error is:
dx +
dy - ×min and yields error in interval −3% to 7%.
Also note that when comparing distances , it isn't necessary to take the square root at all. If distance is greater than distance , then will also be greater than . Or, when checking to see if distance is greater than , that is the same as comparing with or , etc. An example of the first case might be when trying to determine which nearest grid point an arbitrary point should "snap to" in a 2D CAD/CAM system. This isn't really an approximation, however, as the results are exact.
Three-dimensional distance
For two 3D points, and , the distance is computed as
3D approximations for computer applications
As noted in the 2D approximation section, when comparing distances , it isn't necessary to take the square root at all. If distance is greater than distance , then will also be greater than . An example is when searching for the minimum distance between two surfaces in 3D space, using a 3D CAD/CAM system. One way to start would be to build a point grid on each surface, and compare the distance of every grid point on the first surface with every grid point on the second surface. It isn't necessary to know the actual distances, but only which distance is the least. Once the closest two points are located, a much smaller point grid could be created around those closest points on each surface, and the process repeated. After several iterations, the closest two points could then be fully evaluated, including the square root, to give an excellent approximation of the minimum distance between the two surfaces. Thus, the square root only needs to be taken once, instead of thousands of times.
See also
- Mahalanobis distance
- Metric