Send Close Add comments: (status displays here)
Got it!  This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Euclidean distances
by RS  admin@robinsnyder.com : 1024 x 640


1. Euclidean distances
The Euclidean distance between two points is the straight line distance between the points in a non-curved space.

2. Pythagoras
Pythagorean theoremThe idea is directly related to the Pythagorean theorem of right triangles (in any dimension).

In the image, the (red) vertical/rise y distance is 3, the (green) horizontal/run x distance is 4, and the (blue) hypotenuse distance is 5.
52 = 42 + 32


3. One dimension
The distance d between points x1 and x2 on a line is determined as follows.

1d distance formula
The above math formula can be written as the following coding expressions (as assignment statements).
d = sqrt( pow(x2-x1,2)) d = x2 - x1


4. Two dimensions
The distance d between points (x1, y1) and (x2, y2) in a plane is determined as follows.

2d distance formula
The above math formula can be written as the following coding expression (as an assignment statement).
d = sqrt( pow(x2-x1,2) + pow(y2-y1,2))

If intermediate variables are used, such as dx and dy, then the above can be written as the following assignment statements. Note: As is always the case, variable declarations may be required.
dx = x2 - x2 dy = y2 - y1 d = sqrt(dx*dx + dy*dy)

Note: Once dx and dy are defined, one can just square the distances instead of using the pow function to avoid repeating expressions.

5. Euclidean distances
The distance d between points (x1, y1, z1) and (x2, y2, z2) in a 3-D space is determined as follows.

3d distance formula
The above math formula can be written as the following coding expression (as an assignment statement) where sqrt is the square root function and pow is the power function.
d = sqrt( pow(x2-x1,2) + pow(y2-y1,2) + pow(z2-z1, 2))

This distance is called the Euclidean distance and uses the Pythagorean theorem. This distance idea is used in many areas of statistics in distributions, error analysis, etc.

6. Generalization
This idea can be generalized to n-dimensional spaces as needed.


7. End of page

by RS  admin@robinsnyder.com : 1024 x 640