Skip to content

Point Distances and Vector Lengths

Euclidean Norm

Measuring the distance between points and computing the length of vectors is most frequently based on the Euclidean notion of distance: the square root of the sum of squares. The Euclidean distance is also often referred to as the Euclidean or L2 norm. Specifically, suppose the following points and vector are defined:

p = Point3d( px, py, pz )
q = Point3d( qx, qy, qz )

u = Vector3d( q.X - p.X,
              q.Y - p.Y,
              q.Z - p.Z )

Computing distances and lengths is presented below. The distance between points p and q is often denoted as |q - p| and the vector's u length as |u|.

Vector Euclidean Distance Figure

""" Euclidean Point Distance
"""
d = math.sqrt( ( q.X - p.X ) ** 2 +
               ( q.Y - p.Y ) ** 2 +
               ( q.Z - p.Z ) ** 2 )

""" Euclidean Vector Length
"""
d = math.sqrt(
    u.X ** 2 +
    u.Y ** 2 +
    u.Z ** 2 )

""" Shortcuts
"""
d = p.DistanceTo( q )
d = u.Length

Note that the distance between two points |p - q| is equal to the length of the vector u = q - p defined by the same two points because |u| = |q - p| = |p - q|.

Additionally, the Euclidean distance is symmetric |p - q| = |q - p| and |u| = |-u|, because squaring removes the directionality of the difference.

Manhattan Norm

The Manhattan or taxi driver or L1 norm is another form of distance / length measured as the sum of the absolute values of coordinates / components. It represents the sum of the motions from point p to q as if motion is only valid along an orthogonal grid.

Vector Manhattan Distance Figure

""" Manhattan Distance
"""
d = ( abs( q.X - p.X ) +
      abs( q.Y - p.Y ) +
      abs( q.Z - p.Z ) )

""" Manhattan Length
"""
d = ( abs( u.X ) +
      abs( u.Y ) +
      abs( u.Z ) )