algolib.maths.geometry 包

子模块

algolib.maths.geometry.geometry 模块

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[源代码]

基类:object

Common geometry utilities.

static distance(p1: Point, p2: Point) float[源代码]

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

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

基类:object

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

参数:
  • 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[源代码]

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[源代码]

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

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

基类:object

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

参数:
  • 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[源代码]

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

signed_distance(p: Point) float[源代码]

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

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

基类:object

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

参数:

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

备注

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

dimension() int[源代码]

Return the dimension (number of coordinates).

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

基类:object

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

参数:

comps (Sequence[Number]) -- 向量的分量。

备注

向量同时表示大小和方向。

dimension() int[源代码]

Return the dimension (number of components).

dot(other: Vector) float[源代码]

Return the dot product with another vector.

Formula

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

norm() float[源代码]

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

备注

  • 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.

模块内容