This commit is contained in:
Miloslav Ciz 2024-08-27 17:09:58 +02:00
parent 2c518b91ca
commit 3816e78230
19 changed files with 1805 additions and 1802 deletions

View file

@ -1,6 +1,6 @@
# Distance
Distance is a [measure](metric.md) of how far away from each other two [points](point.md) are. Most commonly distance refers to physical separation in space, e.g. as in distance of planets from the Sun, but more generally distance can refer to any kind of parameter space and in any number of [dimensions](dimension.md), e.g. the distance of events in time measured in seconds (1D distance) or distance of two text strings as the amount of their dissimilarity ([Levenshtein distance](levenshtein_distance.md)). Distances are very important in [computer science](compsci.md) and [math](math.md) as they allow us to do such things as [clustering](clustering.md), path searching, physics simulations, various comparisons, [sorting](sort.md) etc.
Distance is a [measure](metric.md) of how far away from each other two [points](point.md) are. Most commonly distance refers to physical separation in space, e.g. as in distance of planets from the Sun, but more generally distance may refer to any kind of parameter space and in any number of [dimensions](dimension.md), e.g. the distance of events in time measured in seconds (1D distance) or distance of two text strings as the amount of their dissimilarity ([Levenshtein distance](levenshtein_distance.md)). Distances are very important in [computer science](compsci.md) and [math](math.md) as they allow us to do such things as [clustering](clustering.md), path searching, physics simulations, various comparisons, [sorting](sort.md) etc.
Distance is similar/related to [length](length.md), the difference is that distance is computed between two points while length is the distance of one point from some implicit origin. I.e. distance is computed between two [vectors](vector.md) while length is computed from just one vector.
@ -36,7 +36,7 @@ int distCheb(int x0, int y0, int x1, int y1)
}
```
Both of these distances approximate a circle in 2D with a square or a sphere in 3D with a cube, the difference is that taxicab is an upper estimate of the distance while Chebyshev is the lower estimate. For speed of execution ([optimization](optimization.md)) it may also be important that taxicab distance only uses the operation of addition while Chebyshev may result in [branching](branch.md) (*if*) in the max function which is usually not good for performance.
Both of these distances approximate a [circle](circle.md) in 2D with a square or a sphere in 3D with a cube, the difference is that taxicab is an upper estimate of the distance while Chebyshev is the lower estimate. For speed of execution ([optimization](optimization.md)) it may also be important that taxicab distance only uses the operation of addition while Chebyshev may result in [branching](branch.md) (*if*) in the max function which is usually not good for performance.
A bit more accuracy can be achieved by averaging the taxicab and Chebyshev distances which in 2D approximates a circle with an 8 segment polygon and in 3D approximates a sphere with 24 sided [polyhedron](polyhedron.md). The integer-only [C](c.md) code is following: