Skip to content

Pitch

kloppy.domain.models.pitch.Point dataclass

Point on the pitch.

Attributes:

Name Type Description
x float

x coordinate in unit of PitchDimensions

y float

y coordinate in unit of PitchDimensions

Source code in kloppy/domain/models/pitch.py
class Point:
    """
    Point on the pitch.

    Attributes:
        x: x coordinate in unit of [`PitchDimensions`][kloppy.domain.models.pitch.PitchDimensions]
        y: y coordinate in unit of [`PitchDimensions`][kloppy.domain.models.pitch.PitchDimensions]
    """

    x: float
    y: float

    def distance_to(self, other: "Point") -> float:
        """
        Calculates the euclidean distance between the point and another provided point

        Arguments:
            other: See [`Point`][kloppy.domain.models.pitch.Point]
        """
        return sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)

distance_to(self, other)

Calculates the euclidean distance between the point and another provided point

Parameters:

Name Type Description Default
other Point

See Point

required
Source code in kloppy/domain/models/pitch.py
def distance_to(self, other: "Point") -> float:
    """
    Calculates the euclidean distance between the point and another provided point

    Arguments:
        other: See [`Point`][kloppy.domain.models.pitch.Point]
    """
    return sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)

kloppy.domain.models.pitch.Point3D (Point) dataclass

Point on the pitch that includes the z coordinate for height (e.g. of the ball).

Attributes:

Name Type Description
z Optional[float]

z coordinate in unit of PitchDimensions

Source code in kloppy/domain/models/pitch.py
class Point3D(Point):
    """
    Point on the pitch that includes the z coordinate for height (e.g. of the ball).

    Attributes:
        z: z coordinate in unit of [`PitchDimensions`][kloppy.domain.models.pitch.PitchDimensions]
    """

    z: Optional[float]

kloppy.domain.models.pitch.PitchDimensions dataclass

Attributes:

Name Type Description
x_dim Dimension

See Dimension

y_dim Dimension

See Dimension

x_per_meter

number of units per meter in the x dimension

y_per_meter

number of units per meter in the y dimension

Source code in kloppy/domain/models/pitch.py
class PitchDimensions:
    """
    Attributes:
        x_dim: See [`Dimension`][kloppy.domain.models.pitch.Dimension]
        y_dim: See [`Dimension`][kloppy.domain.models.pitch.Dimension]
        x_per_meter: number of units per meter in the x dimension
        y_per_meter: number of units per meter in the y dimension
    """

    x_dim: Dimension
    y_dim: Dimension
    length: float = None
    width: float = None

    def __eq__(self, other):
        if isinstance(self, PitchDimensions):
            return self.x_dim == other.x_dim and self.y_dim == other.y_dim

        return False

kloppy.domain.models.pitch.Dimension dataclass

Attributes:

Name Type Description
min float

Minimal possible value within this dimension

max float

Maximal possible value within this dimension

Source code in kloppy/domain/models/pitch.py
class Dimension:
    """
    Attributes:
        min: Minimal possible value within this dimension
        max: Maximal possible value within this dimension
    """

    min: float
    max: float

    def __eq__(self, other):
        if isinstance(self, Dimension):
            return self.min == other.min and self.max == other.max

        return False

    def to_base(self, value: float) -> float:
        return (value - self.min) / (self.max - self.min)

    def from_base(self, value: float) -> float:
        return value * (self.max - self.min) + self.min