Skip to content

geometry

calculate_distance(x1, y1, x2, y2)

Calculate the distance between two points.

Parameters:

Name Type Description Default
x1 float

The x-coordinate of the first point.

required
y1 float

The y-coordinate of the first point.

required
x2 float

The x-coordinate of the second point.

required
y2 float

The y-coordinate of the second point.

required

Returns:

Type Description
float

The distance between the two points.

Source code in layerforge/utils/geometry.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def calculate_distance(x1: float, y1: float, x2: float, y2: float) -> float:
    """Calculate the distance between two points.

    Parameters
    ----------
    x1 : float
        The x-coordinate of the first point.
    y1 : float
        The y-coordinate of the first point.
    x2 : float
        The x-coordinate of the second point.
    y2 : float
        The y-coordinate of the second point.

    Returns
    -------
    float
        The distance between the two points.
    """
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5