algolib.maths.geometry package

Submodules

algolib.maths.geometry.geometry module

A professional-grade \(N\)-dimensional geometry module.

It implements:

  • Point: a location in \(\mathbb{R}^N\).

  • Vector: a displacement in \(\mathbb{R}^N\).

  • Line: parametric line \(P(t) = P_0 + t\,d\).

  • Plane: hyperplane \(\{X:\; n\cdot(X-P_0)=0\}\).

  • GeometryUtils: utility routines.

All classes validate dimensions and numeric inputs, and raise algolib.exceptions.InvalidTypeError or algolib.exceptions.InvalidValueError on invalid usage.

class algolib.maths.geometry.geometry.GeometryUtils[source]

Bases: object

Common geometry utilities.

static distance(p1: Point, p2: Point) float[source]

Euclidean distance \(\\sqrt{\\sum_i (x_{1i}-x_{2i})^2}\).

class algolib.maths.geometry.geometry.Line(point: Point, direction: Vector)[source]

Bases: object

Parametric line \(P(t) = P_0 + t\\,d\) in \(\\mathbb{R}^N\).

Parameters:
  • point (Point) – A point on the line (\(P_0\)).

  • direction (Vector) – Direction vector \(d\) (must be non-zero).

contains(p: Point, tol: float = 1e-12) bool[source]

Return True if p lies on the line (within tolerance).

We check that \(p - P_0\) is colinear with \(d\) by comparing ratios; component pairs with \(|d_i| \le \text{tol}\) are skipped.

point_at(t: int | float) Point[source]

Return the point \(P_0 + t\,d\).

class algolib.maths.geometry.geometry.Plane(point: Point, normal: Vector)[source]

Bases: object

Hyperplane \(\\{X:\\; n\\cdot(X-P_0)=0\\}\) in \(\\mathbb{R}^N\).

Parameters:
  • point (Point) – A reference point \(P_0\) on the plane.

  • normal (Vector) – Normal vector \(n\) (must be non-zero).

contains(p: Point, tol: float = 1e-12) bool[source]

Return True if |n·(p-P0)| <= tol * ||n||.

signed_distance(p: Point) float[source]

Return signed distance \(\\frac{n\\cdot (p-P_0)}{\\lVert n\\rVert}\).

class algolib.maths.geometry.geometry.Point(coords: Sequence[int | float])[source]

Bases: object

Point in \(N\)-dimensional Euclidean space.

Parameters:

coords (Sequence[Number]) – Coordinates of the point; length defines the dimension.

Notes

A point has location but no direction or magnitude: \(P=(x_1,x_2,\\dots,x_N)\).

dimension() int[source]

Return the dimension (number of coordinates).

class algolib.maths.geometry.geometry.Vector(comps: Sequence[int | float])[source]

Bases: object

Vector in \(N\)-dimensional Euclidean space.

Parameters:

comps (Sequence[Number]) – Components of the vector.

Notes

A vector represents both magnitude and direction.

dimension() int[source]

Return the dimension (number of components).

dot(other: Vector) float[source]

Return the dot product with another vector.

Formula

\(v\\cdot w = \\sum_i v_i w_i\).

norm() float[source]

Return the Euclidean norm \(\lVert v \rVert = \sqrt{\sum_i v_i^2}\).

Notes

  • Non-finite inputs are handled explicitly: if any component is NaN, the result is NaN; if any component has infinite magnitude, the result is inf.

  • Uses a scaling strategy for numerical stability to avoid overflow and underflow with mixed-magnitude components.

Module contents