math.hypot

Full name
math.hypot
Library
math
Syntax

math.hypot(*coordinates)

Description

The math.hypot function returns the Euclidean norm of the vector that, having the center of coordinates as its origin, ends at the coordinates indicated as an argument. The result is equivalent to math.sqrt(sum(x ** 2 for x in coordinates)).

 

Parameters
  • coordinates: position x and y of the end of the vector whose norm is to be obtained.
Result

We can obtain the norm of the vector that, having as origin the center of coordinates, ends at the point (1, 1) with the following code:

math.hypot(1, 1)
1.4142135623730951

Of course, this norm is the same as that of the vector that ends, for example, at the coordinates (-1, 1):

math.hypot(-1, 1)
1.4142135623730951
Examples

We can verify that the previous result is equivalent to calculating the square root of the sum of the squares of the coordinates:

coordinates = [1, 1]
math.sqrt(sum(x ** 2 for x in coordinates))
1.4142135623730951
Submitted by admin on Sun, 02/07/2021 - 11:27