calc_hypotenuse_distance

pyhelpers.geom.calc_hypotenuse_distance(pt1, pt2)[source]

Calculate the hypotenuse distance between two points.

See also [GEOM-CHD-1].

Parameters:
  • pt1 (shapely.geometry.Point | list | tuple | numpy.ndarray) – One point.

  • pt2 (shapely.geometry.Point | list | tuple | numpy.ndarray) – Another point.

Returns:

Hypotenuse distance between pt1 and pt2.

Return type:

float

Note

  • The hypotenuse distance is the straight-line distance between pt1 and pt2.

  • Calculated using the formula: sqrt((x2 - x1)^2 + (y2 - y1)^2)

  • Equivalent to numpy.hypot(x, y) which computes sqrt(x*x + y*y).

Examples:

>>> from pyhelpers.geom import calc_hypotenuse_distance
>>> from shapely.geometry import Point
>>> pt_1, pt_2 = (1.5429, 52.6347), (1.4909, 52.6271)
>>> hypot_distance = calc_hypotenuse_distance(pt_1, pt_2)
>>> hypot_distance
0.05255244999046248
>>> pt_1_, pt_2_ = map(Point, (pt_1, pt_2))
>>> pt_1_.wkt
'POINT (1.5429 52.6347)'
>>> pt_2_.wkt
'POINT (1.4909 52.6271)'
>>> hypot_distance = calc_hypotenuse_distance(pt_1_, pt_2_)
>>> hypot_distance
0.05255244999046248