geometer package

geometer.utils package

class geometer.utils.math.UFuncParameters[source]

Bases: TypedDict

Keyword parameters for numpy’s ufuncs.

axes: list[tuple[int]]
axis: int
casting: Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe']
dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]
keepdims: bool
order: Literal['K', 'A', 'C', 'F']
subok: bool
where: ndarray[Any, dtype[bool_]]
geometer.utils.math.adjugate(A)[source]

Calculates the adjugate matrix of A.

The resulting matrix is defined by

\[\textrm{adj}(A)_{ij} = (-1)^{i+j} M_{j i},\]

where \(M_{j i}\) is the determinant of the submatrix of \(A\) obtained by deleting the j-th row and the i-th column of \(A\).

For small matrices, this function uses the following formula (Einstein notation):

\[\textrm{adj}(A)_{ij} = \frac{1}{(n-1)!} \varepsilon_{i\ i_2 \ldots i_n} \varepsilon_{j\ j_2 \ldots j_n} A_{j_2 i_2} \ldots A_{j_n i_n}\]

Source (German): https://de.wikipedia.org/wiki/Levi-Civita-Symbol#Zusammenhang_mit_der_Determinante

Parameters:

A (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – (…, M, M) The input matrix.

Returns:

(…, M, M) The adjugate of A.

Return type:

ndarray[Any, dtype[number]]

geometer.utils.math.det(A)[source]

Computes the determinant of A.

Parameters:

A (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – (…, M, M) The input matrix.

Returns:

(…) The determinant of A.

Return type:

ndarray[Any, dtype[number]]

geometer.utils.math.hat_matrix(*args)[source]

Builds a skew symmetric matrix with the given scalars in the positions shown below.

\[\begin{split}\begin{pmatrix} 0 & c & -b\\ -c & 0 & a \\ b & -a & 0 \end{pmatrix}\end{split}\]
Parameters:
  • a – The scalars to use in the matrix.

  • b – The scalars to use in the matrix.

  • c – The scalars to use in the matrix.

Returns:

The resulting antisymmetric matrix.

Return type:

ndarray

geometer.utils.math.inv(A)[source]

Computes the inverse of A.

Parameters:

A (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – (…, M, M) The input matrix.

Returns:

(…, M, M) The inverse of A.

Return type:

ndarray[Any, dtype[number]]

geometer.utils.math.is_multiple(a, b, axis=None, rtol=1e-05, atol=1e-08)[source]

Returns a boolean array where two arrays are scalar multiples of each other along a given axis.

For documentation of the tolerance parameters see numpy.isclose().

Parameters:
  • a (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Numeric input arrays to compare.

  • b (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – Numeric input arrays to compare.

  • axis (int | tuple[int, ...] | None) – The axis or axes along which the two arrays are compared. The default axis=None will compare the whole arrays and return only a single boolean value.

  • rtol (float) – The relative tolerance parameter.

  • atol (float) – The absolute tolerance parameter.

Returns:

Returns a boolean array of where along the given axis the arrays are a scalar multiple of each other (within the given tolerance). If no axis is given, returns a single boolean value.

Return type:

bool_ | ndarray[Any, dtype[bool_]]

geometer.utils.math.is_numerical_dtype(dtype)[source]

Checks whether a dtype is a numerical dtype i.e. a number or a bool.

Parameters:

dtype (npt.DTypeLike) – The dtype to check.

Returns:

True if the dtype is a numeric dtype

Return type:

TypeGuard[NumericalDType]

geometer.utils.math.is_numerical_scalar(element)[source]

Checks whether an element is a numerical scalar, i.e. a number or a bool.

0-dimensional arrays are considered scalars, too.

Parameters:

element (npt.ArrayLike) – The element to check.

Returns:

True if the element is a numerical scalar

Return type:

TypeGuard[NumericalScalar]

geometer.utils.math.matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False, adjoint_b=False, out=None, **kwargs)[source]

Matrix product of two arrays.

Parameters:
  • a (npt.ArrayLike) – Input arrays, scalars not allowed.

  • b (npt.ArrayLike) – Input arrays, scalars not allowed.

  • transpose_a (bool) – If true, a is transposed before multiplication.

  • transpose_b (bool) – If true, b is transposed before multiplication.

  • adjoint_a (bool) – If true, a is conjugated and transposed before multiplication.

  • adjoint_b (bool) – If true, b is conjugated and transposed before multiplication.

  • out (np.ndarray | None) – Output array.

  • **kwargs (Unpack[UFuncParameters]) – Additional keyword arguments for numpy.matmul.

Returns:

The matrix product of the inputs.

Return type:

npt.NDArray[np.number]

geometer.utils.math.matvec(a, b, transpose_a=False, adjoint_a=False, out=None, **kwargs)[source]

Matrix-vector product of two arrays.

Parameters:
  • a (npt.ArrayLike) – Input arrays, scalars not allowed.

  • b (npt.ArrayLike) – Input arrays, scalars not allowed.

  • transpose_a (bool) – If true, a is transposed before multiplication.

  • adjoint_a (bool) – If true, a is conjugated and transposed before multiplication.

  • out (np.ndarray | None) – Output array.

  • **kwargs (Unpack[UFuncParameters]) – Additional keyword arguments for numpy.matmul.

Returns:

The matrix-vector product of the inputs.

Return type:

npt.NDArray[np.number]

geometer.utils.math.null_space(A, dim=None)[source]

Constructs an orthonormal basis for the null space of a matrix A using SVD.

Parameters:
  • A (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – (…, M, N) The input matrix.

  • dim (int | None) – The dimension of the null space if previously known.

Returns:

(…, N, K) Orthonormal basis for the null space of A (as column vectors in the returned matrix).

Return type:

ndarray[Any, dtype[number]]

geometer.utils.math.orth(A, dim=None)[source]

Constructs an orthonormal basis for the range of A using SVD.

Parameters:
  • A (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – (…, M, N) The input matrix.

  • dim (int | None) – The dimension of the image space if previously known.

Returns:

(…, M, K) Orthonormal basis for the range of A (as column vectors in the returned matrix).

Return type:

ndarray[Any, dtype[number]]

geometer.utils.math.outer(a, b, out=None, **kwargs)[source]

Outer product of two arrays.

Parameters:
  • a (npt.ArrayLike) – (…, M) The first input array.

  • b (npt.ArrayLike) – (…, N) The second input array.

  • out (np.ndarray | None) – (…, M, N) Output array.

Returns:

(…, M, N) The outer product of a and b.

Return type:

out

geometer.utils.math.roots(p)[source]

Calculates the roots of a polynomial for the given coefficients.

The polynomial is defined as

\[p[0] x^n + p[1] x^{n-1} + \ldots + p[n-1] x + p[n].\]
Parameters:

p (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – The coefficients of the polynomial.

Returns:

The roots of the polynomial.

Return type:

ndarray[Any, dtype[number]]

geometer.base module

class geometer.base.BoundTensor(*args, covariant=True, tensor_rank=None, **kwargs)[source]

Bases: Tensor

A tensor without free indices.

class geometer.base.KroneckerDelta(n, p=1)[source]

Bases: BoundTensor

This class can be used to construct a (p, p)-tensor representing the Kronecker delta tensor.

The following generalized definition of the Kronecker delta is used:

\[\begin{split}\delta_{\nu_{1} \ldots \nu_{p}}^{\mu_{1} \ldots \mu_{p}} = \begin{cases} +1 & \text{ if } (\nu_{1}, \ldots, \nu_{p}) \text{ are an even permutation of } (\mu_{1}, \ldots, \mu_{p})\\ -1 & \text{ if } (\nu_{1}, \ldots, \nu_{p}) \text{ are an odd permutation of } (\mu_{1}, \ldots, \mu_{p})\\ 0 & \text{ else} \end{cases}\end{split}\]
Parameters:
  • n (int) – The dimension of the tensor.

  • p (int) – The number of covariant and contravariant indices of the tensor, default is 1.

References

class geometer.base.LeviCivitaTensor(size, covariant=True)[source]

Bases: BoundTensor

This class can be used to construct a tensor representing the Levi-Civita symbol.

The Levi-Civita symbol is also called \(\varepsilon\)-Tensor and is defined as follows:

\[\begin{split}\varepsilon_{\nu_{1} \ldots \nu_{n}} = \begin{cases} +1 & \text{ if } (\nu_{1}, \ldots, \nu_{n}) \text{ are an even permutation of } (1, \ldots, n)\\ -1 & \text{ if } (\nu_{1}, \ldots, \nu_{n}) \text{ are an odd permutation of } (1, \ldots, n)\\ 0 & \text{ else} \end{cases}\end{split}\]
Parameters:
  • size (int) – The number of indices of the tensor.

  • covariant (bool) – If true, the tensor will only have covariant indices. Default: True

References

class geometer.base.ProjectiveTensor(*args, covariant=True, tensor_rank=None, **kwargs)[source]

Bases: Tensor, ABC

Base class for all projective tensors, i.e. all objects that identify scalar multiples.

property dim: int

The ambient dimension of the tensor.

class geometer.base.Tensor(*args, covariant=True, tensor_rank=None, **kwargs)[source]

Bases: object

Wrapper class around a numpy array that keeps track of covariant and contravariant indices.

Covariant indices are the lower indices (subscripts) and contravariant indices are the upper indices (superscripts) of a tensor.

Parameters:
  • *args (Tensor | npt.ArrayLike) – A single iterable, numpy array, tensor or multiple coordinate numbers, arrays, tensors.

  • covariant (bool | Iterable[int]) – If False, all indices are contravariant. If a list of indices is supplied, the specified indices of the array will be covariant indices and all others contravariant indices. By default, all indices are covariant. If the first argument is a tensor then its indices are copied.

  • tensor_rank (int | None) – If the Tensor object contains multiple tensors, this parameter specifies the rank of the tensors contained in it. By default, only a single tensor is contained in a Tensor object.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

array

The underlying numpy array.

Type:

numpy.ndarray[Any, numpy.dtype[numpy.number | numpy.bool_]]

References

property T: Tensor

The transposed tensor, same as self.transpose().

array: ndarray[Any, dtype[number | bool_]]
copy()[source]
property dtype: dtype[number | bool_]

The dtype of the underlying numpy array, same as self.array.dtype.

property free_indices: int

Number of free indices, i.e. indices that are not covariant and not contravariant.

is_zero(tol=1e-08)[source]

Test whether the tensor is zero with respect to covariant and contravariant indices.

Parameters:

tol (float) – The accepted tolerance.

Returns:

True if the tensor is zero. If there are more indices than the covariant and contravariant indices, a boolean array is returned.

Return type:

ndarray[Any, dtype[bool_]]

property rank: int

The rank of the Tensor, same as self.array.ndim.

property shape: tuple[int, ...]

The shape of the underlying numpy array, same as self.array.shape.

tensor_product(other)[source]

Return a new tensor that is the tensor product of this and the other tensor.

This method will also reorder the indices of the resulting tensor, to ensure that covariant indices are in front of the contravariant indices.

Parameters:

other (Tensor) – The other tensor.

Returns:

The tensor product.

Return type:

Tensor

property tensor_shape: tuple[int, int]

The shape or type of the tensor.

The first number is the number of covariant indices, the second the number of contravariant indices.

transpose(perm=None)[source]

Permute the indices of the tensor. Free indices are not permuted.

Parameters:

perm (Iterable[int] | None) – A list of permuted indices or a shorter list representing a permutation in cycle notation. By default, the indices are reversed.

Returns:

The tensor with permuted indices.

Return type:

Tensor

class geometer.base.TensorCollection(*args, covariant=True, tensor_rank=1, **kwargs)[source]

Bases: Tensor, Generic[T], Sized, Iterable[T]

A collection of tensors.

expand_dims(axis)[source]

Add a new index as a free index.

Parameters:

axis (int) – Position in the new shape where the new axis is placed.

Returns:

The tensor collection with an additional free index.

Return type:

Self

classmethod from_array(array, **kwargs)[source]

Try to construct a new collection from an array. If the rank is too low, an object of type T is returned.

By default the array is not copied.

Parameters:
  • array (npt.ArrayLike) – A numpy array to use for the new tensor.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

Returns:

A new tensor.

Return type:

Self | T

classmethod from_tensor(tensor, **kwargs)[source]

Construct an object from another tensor. If the tensor has no free indices, an object of type T is returned.

By default the array in the tensor is not copied.

Parameters:
  • tensor (Tensor) – A tensor to use for the new tensor.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

Returns:

A new tensor.

Return type:

Self | T

property size: ndarray[Any, dtype[int64]]

The number of tensors in the tensor collection, i.e. the product of the size of all collection axes.

class geometer.base.TensorDiagram(*edges)[source]

Bases: object

A class used to specify and calculate tensor diagrams (also called Penrose Graphical Notation).

Each edge in the diagram represents a contraction of two indices of the tensors connected by that edge. In Einstein-notation that would mean that an edge from tensor A to tensor B is equivalent to the expression \(A_{i j}B^{i k}_l\), where \(j, k, l\) are free indices. The indices to contract are chosen from front to back from contravariant and covariant indices of the tensors that are connected by an edge.

Parameters:

*edges (tuple[Tensor, Tensor]) – Variable number of tuples, that represent the edge from one tensor to another.

References

add_edge(source, target)[source]

Add an edge to the diagram.

Parameters:
  • source (Tensor) – The source tensor of the edge in the diagram.

  • target (Tensor) – The target tensor of the edge in the diagram.

Raises:

TensorComputationError – If the tensors have no unused indices or the dimensions do not match.

add_node(node)[source]

Add a node to the tensor diagram without adding an edge/contraction.

A diagram of nodes where none are connected is equivalent to calculating the tensor product with the method Tensor.tensor_product().

Parameters:

node (Tensor) – The node to add.

calculate()[source]

Calculates the result of the diagram.

Returns:

The tensor resulting from the specified tensor diagram.

Return type:

Tensor

copy()[source]

geometer.curve module

class geometer.curve.Circle(center=Point(0, 0), radius=1, **kwargs)[source]

Bases: Ellipse

A circle in 2D.

Parameters:
  • center (Point) – The center point of the circle, default is Point(0, 0).

  • radius (float) – The radius of the circle, default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property area: float

The area of the circle.

property center: Point

The center of the circle.

intersection_angle(other)[source]

Calculates the angle of intersection of two circles using its Lie coordinates.

Parameters:

other (Circle) – The circle to intersect this circle with.

Returns:

The angle of intersection.

Return type:

float

References

property lie_coordinates: ndarray

The normalized Lie coordinates of the circle in R4.

property radius: float

The radius of the circle.

class geometer.curve.Cone(vertex=Point(0, 0, 0), base_center=Point(0, 0, 1), radius=1, **kwargs)[source]

Bases: Quadric

A quadric that forms a circular double cone in 3D.

Parameters:
  • vertex (Point) – The vertex or apex of the cone. Default is (0, 0, 0).

  • base_center (Point) – The center of the circle that forms the base of the cone. Default is (0, 0, 1)

  • radius (float) – The radius of the circle forming the base of the cone. Default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

class geometer.curve.Conic(matrix, is_dual=False, normalize_matrix=False, **kwargs)[source]

Bases: Quadric

A two-dimensional conic.

property foci: tuple[Point, ...]

The foci of the conic.

classmethod from_crossratio(cr, a, b, c, d)[source]

Construct a conic from a cross ratio and four other points.

This method relies on the fact that a point lies on a conic with five other points, if and only of the cross ratio seen from this point is the same as the cross ratio of four of the other points seen from the fifth point.

Parameters:
  • cr (float) – The crossratio of the other points that defines the conic.

  • a (Point) – The points lying on the conic.

  • b (Point) – The points lying on the conic.

  • c (Point) – The points lying on the conic.

  • d (Point) – The points lying on the conic.

Returns:

The resulting conic.

Return type:

Conic

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Section 10.2

classmethod from_foci(f1, f2, bound)[source]

Construct a conic with the given focal points that passes through the boundary point.

Parameters:
  • f1 (Point) – The two focal points.

  • f2 (Point) – The two focal points.

  • bound (Point) – A boundary point that lies on the conic.

Returns:

The resulting conic.

Return type:

Conic

classmethod from_lines(g, h)[source]

Construct a degenerate conic from two lines.

Parameters:
  • g (Line) – The two lines the conic consists of.

  • h (Line) – The two lines the conic consists of.

Returns:

The resulting conic.

Return type:

Conic

classmethod from_points(a, b, c, d, e)[source]

Construct a conic through five points.

Parameters:
  • a (Point) – The points lying on the conic.

  • b (Point) – The points lying on the conic.

  • c (Point) – The points lying on the conic.

  • d (Point) – The points lying on the conic.

  • e (Point) – The points lying on the conic.

Returns:

The resulting conic.

Return type:

Conic

classmethod from_tangent(tangent, a, b, c, d)[source]

Construct a conic through four points and tangent to a line.

Parameters:
  • tangent (Line) – The line tangent to the conic.

  • a (Point) – The points lying on the conic.

  • b (Point) – The points lying on the conic.

  • c (Point) – The points lying on the conic.

  • d (Point) – The points lying on the conic.

Returns:

The resulting conic.

Raises:

IncidenceError – If one of the points lies on the tangent.

Return type:

Conic

intersect(other)[source]

Calculates points of intersection with the conic.

Parameters:

other (Line | Conic) – The object to intersect this conic with.

Returns:

The points of intersection.

Return type:

list[Point]

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Section 11.4

polar(pt)[source]

Calculates the polar line of the conic at a given point.

Parameters:

pt (Point) – The point to calculate the polar at.

Returns:

The polar line.

Return type:

Line

tangent(at)[source]

Calculates the tangent line at a given point or the tangent lines between a point and the conic.

Parameters:

at (Point) – The point to calculate the tangent at.

Returns:

The tangent line(s).

Return type:

Line | tuple[Line, Line]

class geometer.curve.Cylinder(center=Point(0, 0, 0), direction=Point(0, 0, 1), radius=1, **kwargs)[source]

Bases: Cone

An infinite circular cylinder in 3D.

Parameters:
  • center (Point) – The center of the cylinder. Default is (0, 0, 0).

  • direction (Point) – The direction of the axis of the cylinder. Default is (0, 0, 1).

  • radius (float) – The radius of the cylinder. Default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

class geometer.curve.Ellipse(center=Point(0, 0), hradius=1, vradius=1, **kwargs)[source]

Bases: Conic

Represents an ellipse in 2D.

Parameters:
  • center (Point) – The center of the ellipse, default is Point(0, 0).

  • hradius (float) – The horizontal radius (along the x-axis), default is 1.

  • vradius (float) – The vertical radius (along the y-axis), default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

class geometer.curve.Quadric(matrix, is_dual=False, normalize_matrix=False, **kwargs)[source]

Bases: QuadricTensor, BoundTensor

class geometer.curve.QuadricCollection(matrix, is_dual=False, normalize_matrix=False, **kwargs)[source]

Bases: QuadricTensor, TensorCollection[Quadric]

class geometer.curve.QuadricTensor(matrix, is_dual=False, normalize_matrix=False, **kwargs)[source]

Bases: ProjectiveTensor, ABC

Represents a quadric, i.e. the zero set of a polynomial of degree 2, in any dimension.

The quadric is defined by a symmetric matrix of size \(n+1\) where \(n\) is the dimension of the projective space. If \(A \in \mathbb{R}^{(n+1) \times (n+1)}\), the quadric contains all points \(x \in \mathbb{R}^{n+1}\) such that \(x^T A x = 0\).

Parameters:
  • matrix (Tensor | npt.ArrayLike) – A two-dimensional array defining the (n+1)x(n+1) symmetric matrix of the quadric.

  • is_dual (bool) – If true, the quadric represents a dual quadric, i.e. all hyperplanes tangent to the non-dual quadric.

  • normalize_matrix (bool) – If true, normalize matrix using the (n+1)-th root of the absolute value of its pseudo-determinant.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

is_dual

True if the quadric is a dual quadric i.e. contains all hyperplanes tangent to the non-dual quadric.

Type:

bool

property components: list[PointTensor | LineTensor | PlaneTensor]

The components of a degenerate quadric.

contains(other, tol=1e-08)[source]

Tests if a given point lies on the quadric.

Parameters:
Returns:

True if the quadric contains the point.

Return type:

ndarray[Any, dtype[bool_]]

property dual: QuadricTensor

The dual quadric.

classmethod from_planes(e, f)[source]

Construct a degenerate quadric from two hyperplanes.

Parameters:
  • e (PlaneTensor) – The two planes the quadric consists of.

  • f (PlaneTensor) – The two planes the quadric consists of.

Returns:

The resulting quadric.

Return type:

QuadricTensor

intersect(other)[source]

Calculates points of intersection of a line with the quadric.

This method also returns complex points of intersection, even if the quadric and the line do not intersect in any real points.

Parameters:

other (LineTensor) – The line to intersect this quadric with.

Returns:

The points of intersection.

Return type:

list[PointTensor] | list[LineTensor]

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Section 11.3

property is_degenerate: ndarray[Any, dtype[bool_]]

True if the quadric is degenerate.

is_tangent(plane)[source]

Tests if a given hyperplane is tangent to the quadric.

Parameters:

plane (SubspaceTensor) – The hyperplane to test.

Returns:

True if the given hyperplane is tangent to the quadric.

Return type:

ndarray[Any, dtype[bool_]]

tangent(at)[source]

Returns the hyperplane defining the tangent space at a given point.

Parameters:

at (PointTensor) – A point on the quadric at which the tangent plane is calculated.

Returns:

The tangent plane at the given point.

Return type:

PlaneTensor

class geometer.curve.Sphere(center=Point(0, 0, 0), radius=1, **kwargs)[source]

Bases: Quadric

A sphere in any dimension.

Parameters:
  • center (Point) – The center of the sphere, default is Point(0, 0, 0).

  • radius (float) – The radius of the sphere, default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property area: float

The surface area of the sphere.

property center: Point

The center of the sphere.

property radius: float

The radius of the sphere.

property volume: float

The volume of the sphere.

geometer.exceptions module

exception geometer.exceptions.GeometryException[source]

Bases: Exception

A general geometric error occurred.

exception geometer.exceptions.IncidenceError[source]

Bases: GeometryException, ValueError

The given point is incident with the subspace.

exception geometer.exceptions.IncompatibleShapeError[source]

Bases: ValueError

The given tensor has a shape that is not compatible.

exception geometer.exceptions.LinearDependenceError(message, dependent_values=True)[source]

Bases: GeometryException, ValueError

The given values were linearly dependent, making the computation impossible.

dependent_values

The indices of the sets of linearly dependent vectors.

Type:

numpy.ndarray

exception geometer.exceptions.NoIncidence[source]

Bases: GeometryException, ValueError

The given point is not incident with the subspace.

exception geometer.exceptions.NotCollinear[source]

Bases: GeometryException, ValueError

The given values are not collinear.

exception geometer.exceptions.NotConcurrent[source]

Bases: GeometryException, ValueError

The given values are not concurrent.

exception geometer.exceptions.NotCoplanar[source]

Bases: GeometryException, ValueError

The given values are not coplanar.

exception geometer.exceptions.NotReducible[source]

Bases: GeometryException, ValueError

The given geometric object is not reducible.

exception geometer.exceptions.TensorComputationError[source]

Bases: GeometryException

An error during a tensor computation occurred.

geometer.operators module

geometer.operators.angle(*args)[source]

Calculates the (oriented) angle between given points, lines or planes.

The function uses the Laguerre formula to calculate angles in two or three-dimensional projective space using cross ratios. To calculate the angle between two planes, two additional planes tangent to the absolute conic are constructed.

Since the Laguerre formula uses the complex logarithm (which gives values between \(-\pi i\) and \(\pi i\)) and multiplies it with \(1/2i\), this function can only calculate angles between \(-\pi / 2\) and \(\pi / 2\).

The sign of the angle is determined by the order of the arguments. The points passed to the cross ratio are in the same order as the arguments to this function. When three points are given as arguments, the first point is the point at which the angle is calculated.

Parameters:

*args (PointTensor | LineTensor | PlaneTensor) – The objects of which the function calculates the angle. These can be 2 or 3 points, 2 lines or 2 planes.

Returns:

The oriented angle(s) between the given objects.

Return type:

ndarray[Any, dtype[float64]]

References

  • Olivier Faugeras, Three-dimensional Computer Vision, Page 30

geometer.operators.angle_bisectors(l, m)[source]

Constructs the angle bisectors of two given lines.

Parameters:
Returns:

The two angle bisectors.

Return type:

tuple[LineTensor, LineTensor]

geometer.operators.crossratio(a, b, c, d, from_point=None)[source]

Calculates the cross ratio of points or lines.

Parameters:
  • a (PointTensor | SubspaceTensor) – The points, lines or planes (any dimension) to calculate the cross ratio of.

  • b (PointTensor | SubspaceTensor) – The points, lines or planes (any dimension) to calculate the cross ratio of.

  • c (PointTensor | SubspaceTensor) – The points, lines or planes (any dimension) to calculate the cross ratio of.

  • d (PointTensor | SubspaceTensor) – The points, lines or planes (any dimension) to calculate the cross ratio of.

  • from_point (PointTensor | None) – A 2D point, only accepted if the other arguments are also 2D points.

Returns:

The cross ratio(s) of the given objects.

Raises:
  • NotConcurrent – If four lines are supplied that are not concurrent.

  • NotCollinear – If four points are supplied that are not collinear.

Return type:

ndarray

geometer.operators.dist(p, q)[source]

Calculates the (euclidean) distance between two objects.

Instead of the usual formula for the euclidean distance this function uses the following formula that is projectively invariant (in P and Q):

\[\textrm{dist}(P, Q) = 4 \left|\frac{\sqrt{[P, Q, I][P, Q, J]}}{[P, I, J][Q, I, J]}\right|\]
Parameters:
Returns:

The distance between the given objects.

Return type:

npt.NDArray[np.float_]

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Section 18.8

geometer.operators.harmonic_set(a, b, c)[source]

Constructs a fourth point that forms a harmonic set with the given points.

The three given points must be collinear.

If the returned point is d, the points {{a, b}, {c, d}} will be in harmonic position.

Parameters:
  • a (PointTensor) – The points (any dimension) that are used to construct the fourth point in the harmonic set.

  • b (PointTensor) – The points (any dimension) that are used to construct the fourth point in the harmonic set.

  • c (PointTensor) – The points (any dimension) that are used to construct the fourth point in the harmonic set.

Returns:

The point that forms a harmonic set with the given points.

Return type:

PointTensor

geometer.operators.is_cocircular(a, b, c, d, rtol=1e-15, atol=1e-08)[source]

Tests whether four points lie on a circle.

Parameters:
  • a (PointTensor) – Four points in RP2 or CP1.

  • b (PointTensor) – Four points in RP2 or CP1.

  • c (PointTensor) – Four points in RP2 or CP1.

  • d (PointTensor) – Four points in RP2 or CP1.

  • rtol (float) – The relative tolerance parameter.

  • atol (float) – The absolute tolerance parameter.

Returns:

True if the four points lie on a circle.

Return type:

ndarray[Any, dtype[bool_]]

geometer.operators.is_collinear(*args, tol=1e-08)[source]

Tests whether the given points or lines are collinear, coplanar or concurrent. Works in any dimension.

Due to line point duality this function has dual versions is_collinear and is_concurrent.

Parameters:
  • *args (PointTensor | LineTensor) – The points or lines to test.

  • tol (float) – The accepted tolerance.

Returns:

True if the given points are coplanar (in 3D) or collinear (in 2D) or if the given lines are concurrent.

Return type:

ndarray[Any, dtype[bool_]]

geometer.operators.is_concurrent(*args, tol=1e-08)[source]

Tests whether the given points or lines are collinear, coplanar or concurrent. Works in any dimension.

Due to line point duality this function has dual versions is_collinear and is_concurrent.

Parameters:
  • *args (PointTensor | LineTensor) – The points or lines to test.

  • tol (float) – The accepted tolerance.

Returns:

True if the given points are coplanar (in 3D) or collinear (in 2D) or if the given lines are concurrent.

Return type:

ndarray[Any, dtype[bool_]]

geometer.operators.is_coplanar(*args, tol=1e-08)[source]

Tests whether the given points or lines are collinear, coplanar or concurrent. Works in any dimension.

Due to line point duality this function has dual versions is_collinear and is_concurrent.

Parameters:
  • *args (PointTensor | LineTensor) – The points or lines to test.

  • tol (float) – The accepted tolerance.

Returns:

True if the given points are coplanar (in 3D) or collinear (in 2D) or if the given lines are concurrent.

Return type:

ndarray[Any, dtype[bool_]]

geometer.operators.is_perpendicular(l, m, rtol=1e-15, atol=1e-08)[source]

Tests whether two lines/planes are perpendicular.

Parameters:
  • l (LineTensor | PlaneTensor) – Two lines in any dimension or two planes in 3D.

  • m (LineTensor | PlaneTensor) – Two lines in any dimension or two planes in 3D.

  • rtol (float) – The relative tolerance parameter.

  • atol (float) – The absolute tolerance parameter.

Returns:

True if the two lines/planes are perpendicular.

Return type:

ndarray[Any, dtype[bool_]]

geometer.point module

class geometer.point.Line(*args, **kwargs)[source]

Bases: LineTensor, Subspace

class geometer.point.LineCollection(*args, **kwargs)[source]

Bases: LineTensor, SubspaceCollection[Line]

class geometer.point.LineTensor(*args, **kwargs)[source]

Bases: SubspaceTensor, ABC

Represents a line in a projective space of arbitrary dimension.

Parameters:
  • *args (Tensor | npt.ArrayLike) – Two points or the coordinates of the line. Instead of all coordinates separately, a single iterable can also be supplied.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property base_point: PointTensor

Base points for the lines, arbitrarily chosen.

property basis_matrix: ndarray

A matrix with orthonormal basis vectors as rows.

property contravariant_tensor: LineTensor

The contravariant tensors of lines in 3D.

property covariant_tensor: LineTensor

The covariant tensors of lines in 3D.

property direction: PointTensor

The direction of the lines (not normalized).

is_coplanar(other)[source]

Tests whether another line lies in the same plane as this line, i.e. whether two lines intersect.

Parameters:

other (LineTensor) – A line in 3D to test.

Returns:

True if the two lines intersect (i.e. they lie in the same plane).

Return type:

ndarray[Any, dtype[bool_]]

References

  • Jim Blinn, Lines in Space: Back to the Diagrams, Line Intersections

meet(other)[source]
mirror(pt)[source]

Construct the reflection of points at the lines.

Parameters:

pt (PointTensor) – The point to reflect.

Returns:

The mirror points.

Return type:

PointTensor

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Section 19.1

perpendicular(through, plane=None)[source]

Construct the perpendicular line though a point.

Parameters:
  • through (PointTensor) – The point through which the perpendicular is constructed.

  • plane (PlaneTensor | None) – In three or higher dimensional spaces, the 2-dimensional subspace that the perpendicular line is supposed to lie in, can be specified.

Returns:

The perpendicular line.

Return type:

LineTensor

class geometer.point.Plane(*args, **kwargs)[source]

Bases: PlaneTensor, Subspace

class geometer.point.PlaneCollection(*args, **kwargs)[source]

Bases: PlaneTensor, SubspaceCollection[Plane]

class geometer.point.PlaneTensor(*args, **kwargs)[source]

Bases: SubspaceTensor

Represents a hyperplane in a projective space of arbitrary dimension.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The points/lines spanning the plane or the coordinates of the hyperplane. Instead of separate coordinates, a single iterable can be supplied.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property basis_matrix: ndarray
property isinf: ndarray[Any, dtype[bool_]]

Boolean array that indicates whether the plane is the hyperplane at infinity.

mirror(pt)[source]

Construct the reflections of a point at the plane.

Only works in 3D.

Parameters:

pt (PointTensor) – The points to reflect.

Returns:

The mirror points.

Return type:

PointTensor

perpendicular(through: PointTensor) LineTensor[source]
perpendicular(through: LineTensor) PlaneTensor

Construct the perpendicular lines though the given points or the perpendicular planes through the given lines.

Only works for lines in 3D.

Parameters:

through – The points or lines through which the perpendiculars are constructed.

Returns:

The perpendicular lines or planes.

class geometer.point.Point(*args, homogenize=False, tensor_rank=1, **kwargs)[source]

Bases: PointTensor, BoundTensor

class geometer.point.PointCollection(*args, homogenize=False, tensor_rank=1, **kwargs)[source]

Bases: PointTensor, TensorCollection[Point]

class geometer.point.PointLikeTensor(*args, homogenize=False, tensor_rank=1, **kwargs)[source]

Bases: ProjectiveTensor, ABC

Base class for point tensors and polytopes implementing arithmetic operations.

property normalized_array: ndarray

The coordinate array of the points with the last coordinates normalized to 1.

class geometer.point.PointTensor(*args, homogenize=False, tensor_rank=1, **kwargs)[source]

Bases: PointLikeTensor, ABC

Represents points in a projective space of arbitrary dimension.

The number of supplied coordinates determines the dimension of the space that the point lives in. If the coordinates are given as scalar arguments (not in a single iterable), the coordinates will automatically be transformed into homogeneous coordinates, i.e. a one added as an additional coordinate.

Addition and subtraction of finite and infinite points will always give a finite result if one of the points was finite beforehand.

Parameters:
  • *args (Tensor | npt.ArrayLike) – A single iterable object or tensor or multiple (affine) coordinates.

  • homogenize (bool) – If True, and the first argument is an array of points, all points in the array will be converted to homogeneous coordinates, i.e. 1 will be added to the coordinates of each point. By default, homogenize is False.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property isinf: ndarray[Any, dtype[bool_]]

Boolean array that indicates which points lie at infinity.

property isreal: ndarray[Any, dtype[bool_]]

Boolean array that indicates which points are real.

join(*others: Unpack[tuple[PointTensor, PointTensor]]) LineTensor[source]
join(*others: Unpack[tuple[PointTensor, SubspaceTensor]] | Unpack[tuple[SubspaceTensor, PointTensor]]) SubspaceTensor
class geometer.point.Subspace(*args, tensor_rank=1, **kwargs)[source]

Bases: SubspaceTensor, BoundTensor, ABC

class geometer.point.SubspaceCollection(*args, tensor_rank=1, **kwargs)[source]

Bases: SubspaceTensor, TensorCollection[SubspaceT], ABC

class geometer.point.SubspaceTensor(*args, tensor_rank=1, **kwargs)[source]

Bases: ProjectiveTensor, ABC

Abstract base class for subspaces of a projective space. Line and Plane are subclasses.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The coordinates of the subspace. Instead of separate coordinates, a single iterable can be supplied.

  • tensor_rank (int) – The rank of the tensors that represent the subspace(s). Default is 1.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property basis_matrix: ndarray
contains(other, tol=1e-08)[source]

Tests whether given points or lines lie in the subspaces.

Parameters:
Returns:

Boolean array that indicates which of given points/lines lies in the subspaces.

Return type:

ndarray[Any, dtype[bool_]]

property general_point: PointTensor

Point in general position i.e. not in the subspaces.

is_parallel(other)[source]

Tests whether the given subspace is parallel to this subspace.

Parameters:

other (SubspaceTensor) – The other space to test.

Returns:

True, if the two subspaces are parallel.

Return type:

ndarray[Any, dtype[bool_]]

join(*others)[source]
meet(other: LineTensor) PointTensor[source]
meet(other: SubspaceTensor) PointTensor | SubspaceTensor
abstract mirror(pt)[source]

Construct the reflection of a point at the subspace.

Parameters:

pt (PointTensor) – The point to reflect.

Returns:

The mirror point.

Return type:

PointTensor

parallel(through)[source]

Returns the subspace through given point that is parallel to this subspace.

Parameters:

through (PointTensor) – The point through which the parallel subspace is to be constructed.

Returns:

The parallel subspace.

Return type:

SubspaceTensor

abstract perpendicular(through)[source]

Construct the perpendicular subspace though the given point or line.

Parameters:

through (PointTensor | LineTensor) – The point or line through which the perpendicular is constructed.

Returns:

The perpendicular subspace.

Return type:

SubspaceTensor

project(pt)[source]

The orthogonal projection of a point onto the subspace.

Parameters:

pt (PointTensor) – The point to project.

Returns:

The projected point.

Return type:

PointTensor

geometer.point.infty_hyperplane(dimension)[source]
geometer.point.join(*args: Unpack[tuple[PointTensor, PointTensor]], _check_dependence: bool = True, _normalize_result: bool = True) LineTensor[source]
geometer.point.join(*args: PointTensor | SubspaceTensor, _check_dependence: bool = True, _normalize_result: bool = True) SubspaceTensor

Joins a number of objects to form a line, plane or subspace.

Parameters:

*args – Objects to join, e.g. 2 points, lines, a point and a line or 3 points.

Returns:

The resulting line, plane or subspace.

Raises:
geometer.point.meet(*args: LineTensor, _check_dependence: bool = True, _normalize_result: bool = True) PointTensor[source]
geometer.point.meet(*args: Unpack[tuple[SubspaceTensor, LineTensor]], _check_dependence: bool = True, _normalize_result: bool = True) PointTensor
geometer.point.meet(*args: Unpack[tuple[LineTensor, SubspaceTensor]], _check_dependence: bool = True, _normalize_result: bool = True) PointTensor

Intersects a number of given objects.

Parameters:

*args – Objects to intersect, e.g. two lines, planes, a plane and a line or 3 planes.

Returns:

The resulting point, line or subspace.

Raises:

geometer.shapes module

class geometer.shapes.Cuboid(a, b, c, d, **kwargs)[source]

Bases: Polyhedron

A class that can be used to construct a cuboid/box or a cube.

Parameters:
  • a (Point) – The base point of the cuboid.

  • b (Point) – The vertex that determines the first direction of the edges.

  • c (Point) – The vertex that determines the second direction of the edges.

  • d (Point) – The vertex that determines the third direction of the edges.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

class geometer.shapes.Polygon(*args, **kwargs)[source]

Bases: PolygonTensor, Polytope

property centroid: Point

The centroid (center of mass) of the polygon.

class geometer.shapes.PolygonCollection(*args, **kwargs)[source]

Bases: PolygonTensor, PolytopeCollection[Polygon]

class geometer.shapes.PolygonTensor(*args, **kwargs)[source]

Bases: PolytopeTensor

A flat polygon with vertices in any dimension.

The vertices of the polygon must be given either in clockwise or counterclockwise order.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The coplanar points that are the vertices of the polygon. They will be connected sequentially by line segments.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property angles: list[ndarray[Any, dtype[float64]]]

The interior angles of the polygon.

property area: ndarray[Any, dtype[float64]]

The area of the polygon.

contains(other)[source]

Tests whether a point is contained in the polygon.

Points on an edge of the polygon are considered True.

Parameters:

other (PointTensor) – The point to test.

Returns:

True if the point is contained in the polygon.

Return type:

ndarray[Any, dtype[bool_]]

References

property edges: SegmentCollection

The edges of the polygon.

property facets: list[SegmentTensor]

The facets of the polytope.

intersect(other)[source]

Intersect the polygon with another object.

Parameters:

other (LineTensor | SegmentTensor) – The object to intersect the polygon with.

Returns:

The points of intersection.

Return type:

list[PointTensor]

property vertices: list[PointTensor]

The vertices of the polytope.

class geometer.shapes.Polyhedron(*args, **kwargs)[source]

Bases: Polytope

A class representing polyhedra (3-polytopes).

property area: ndarray[Any, dtype[float64]] | float64

The surface area of the polyhedron.

property edges: list[SegmentTensor]

The edges of the polyhedron.

property faces: PolygonCollection

The faces of the polyhedron.

intersect(other)[source]

Intersect the polyhedron with another object.

Parameters:

other (LineTensor | SegmentTensor) – The object to intersect the polyhedron with.

Returns:

The points of intersection.

Return type:

list[PointTensor]

class geometer.shapes.Polytope(*args, pdim=0, **kwargs)[source]

Bases: PolytopeTensor, ABC

class geometer.shapes.PolytopeCollection(*args, pdim=0, **kwargs)[source]

Bases: PolytopeTensor, TensorCollection[SubspaceT], ABC

class geometer.shapes.PolytopeTensor(*args, pdim=0, **kwargs)[source]

Bases: PointLikeTensor, ABC

A class representing polytopes in arbitrary dimension.

A (n+1)-polytope is a collection of n-polytopes that have some (n-1)-polytopes in common, where 3-polytopes are polyhedra, 2-polytopes are polygons, 1-polytopes are line segments and 0-polytopes are points.

The polytope is stored as a multidimensional numpy array. Hence, all facets of the polytope must have the same number of vertices and facets.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The polytopes defining the facets ot the polytope.

  • pdim (int) – The dimension of the polytope. Default is 0, i.e. an instance of this class is a point.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

array

The underlying numpy array.

Type:

numpy.ndarray

pdim

The dimension of the polytope.

Type:

int

property facets: list[PolytopeTensor]

The facets of the polytope.

pdim: int
property vertices: list[PointTensor]

The vertices of the polytope.

class geometer.shapes.Rectangle(*args, **kwargs)[source]

Bases: Polygon

A class representing rectangles.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The vertices of the rectangle.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

class geometer.shapes.RegularPolygon(center, radius, n, axis=None, **kwargs)[source]

Bases: Polygon

A class that can be used to construct regular polygon from a radius and a center point.

Parameters:
  • center (Point) – The center of the polygon.

  • radius (float) – The distance from the center to the vertices of the polygon.

  • n (int) – The number of vertices of the regular polygon.

  • axis (Point | None) – If constructed in higher-dimensional spaces, an axis vector is required to orient the polygon.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property center: Point

The center of the polygon.

property inradius: ndarray[Any, dtype[float64]]

The inradius of the regular polygon.

property radius: ndarray[Any, dtype[float64]]

The circumradius of the regular polygon.

class geometer.shapes.Segment(*args, **kwargs)[source]

Bases: SegmentTensor, Polytope

class geometer.shapes.SegmentCollection(*args, **kwargs)[source]

Bases: SegmentTensor, PolytopeCollection[Segment]

expand_dims(axis)[source]

Add a new index as a free index.

Parameters:

axis (int) – Position in the new shape where the new axis is placed.

Returns:

The tensor collection with an additional free index.

Return type:

SegmentCollection

class geometer.shapes.SegmentTensor(*args, **kwargs)[source]

Bases: PolytopeTensor

Represents a line segment in an arbitrary projective space.

Segments with one point at infinity represent rays/half-lines in a traditional sense.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The start and endpoint of the line segment, either as two Point objects or a single coordinate array.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

contains(other, tol=1e-08)[source]

Tests whether a point is contained in the segment.

Parameters:
  • other (PointTensor) – The point to test.

  • tol (float) – The accepted tolerance.

Returns:

True if the point is contained in the segment.

Return type:

ndarray[Any, dtype[bool_]]

property facets: list[PointTensor]

The facets of the polytope.

intersect(other)[source]

Intersect the line segment with another object.

Parameters:

other (LineTensor | PlaneTensor | SegmentTensor | PolygonTensor | Polyhedron) – The object to intersect the line segment with.

Returns:

The points of intersection.

Return type:

list[PointTensor]

property length: ndarray[Any, dtype[float64]]

The length of the segment.

property midpoint: PointTensor

The midpoint of the segment.

property vertices: list[PointTensor]

The start and endpoint of the line segment.

class geometer.shapes.Simplex(*args, **kwargs)[source]

Bases: Polytope

Represents a simplex in any dimension, i.e. a k-polytope with k+1 vertices where k is the dimension.

The simplex determined by k+1 points is given by the convex hull of these points.

Parameters:
  • *args (Point) – The points that are the vertices of the simplex.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property volume: float

The volume of the simplex, calculated using the Cayley-Menger determinant.

class geometer.shapes.Triangle(*args, **kwargs)[source]

Bases: Polygon, Simplex

A class representing triangles.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The vertices of the triangle.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

property circumcenter: Point

The circumcenter of the triangle.

contains(other)[source]

Tests whether a point is contained in the polygon.

Points on an edge of the polygon are considered True.

Parameters:

other (PointTensor) – The point to test.

Returns:

True if the point is contained in the polygon.

Return type:

ndarray[Any, dtype[bool_]]

References

geometer.transformation module

class geometer.transformation.Transformation(*args, **kwargs)[source]

Bases: TransformationTensor, BoundTensor

class geometer.transformation.TransformationCollection(*args, **kwargs)[source]

Bases: TransformationTensor, TensorCollection[Transformation]

class geometer.transformation.TransformationTensor(*args, **kwargs)[source]

Bases: ProjectiveTensor, ABC

Represents a projective transformation in an arbitrary projective space.

The underlying array is the matrix representation of the projective transformation. The matrix must be a non-singular square matrix of size n+1 when n is the dimension of the projective space. The transformation can be applied to a point or another object by multiplication.

Parameters:
  • *args (Tensor | npt.ArrayLike) – The array that defines the matrix representing the transformation.

  • **kwargs (Unpack[NDArrayParameters]) – Additional keyword arguments for the constructor of the numpy array as defined in numpy.array.

T = ~T
apply(other)[source]

Apply the transformation to another object.

Parameters:

other (T) – The object to apply the transformation to.

Returns:

The result of applying this transformation to the supplied object.

Return type:

T

classmethod from_points(*args)[source]

Constructs a projective transformation in n-dimensional projective space from the image of n + 2 points in general position.

For two dimensional transformations, 4 pairs of points are required, of which no three points are collinear. For three dimensional transformations, 5 pairs of points are required, of which no four points are coplanar.

Parameters:

*args (tuple[PointTensor, PointTensor]) – Pairs of points, where in each pair one point is mapped to the other.

Returns:

The transformation mapping each of the given points to the specified points.

Return type:

TransformationTensor

References

    1. Richter-Gebert: Perspectives on Projective Geometry, Proof of Theorem 3.4

classmethod from_points_and_conics(points1, points2, conic1, conic2)[source]

Constructs a projective transformation from two conics and the image of pairs of 3 points on the conics.

Parameters:
  • points1 (Sequence[PointTensor]) – Source points on conic1.

  • points2 (Sequence[PointTensor]) – Target points on conic2.

  • conic1 (Conic) – Source quadric.

  • conic2 (Conic) – Target quadric.

Returns:

The transformation that maps the points to each other and the conic to the other conic.

Return type:

TransformationTensor

References

inverse()[source]

Calculates the inverse projective transformation.

Returns:

The inverse transformation.

Return type:

TransformationTensor

geometer.transformation.affine_transform(matrix=None, offset=0)[source]

Returns a projective transformation for the given affine transformation.

Parameters:
  • matrix (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None) – The transformation matrix.

  • offset (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – The translation.

Returns:

The projective transformation that represents the affine transformation.

Return type:

Transformation

geometer.transformation.identity(dim: int, collection_dims: Literal[None] = None) Transformation[source]
geometer.transformation.identity(dim: int, collection_dims: tuple[int, ...] | None = None) TransformationCollection

Returns the identity transformation.

Parameters:
  • dim – The dimension of the projective space that the transformation acts on.

  • collection_dims – Collection dimensions for a collection of identity transformations. By default, only a single transformation is returned.

Returns:

The identity transformation(s).

geometer.transformation.reflection(axis)[source]

Returns a projective transformation that represents a reflection at the given axis/hyperplane.

Parameters:

axis (Subspace) – The 2D-line or hyperplane to reflect points at.

Returns:

The reflection.

Return type:

Transformation

References

geometer.transformation.rotation(angle, axis=None)[source]

Returns a projective transformation that represents a rotation by the specified angle (and axis).

Parameters:
  • angle (float | float64) – The angle to rotate by.

  • axis (Point | None) – The axis to rotate around when rotating points in 3D.

Returns:

The rotation.

Return type:

Transformation

References

geometer.transformation.scaling(*factors)[source]

Returns a projective transformation that represents general scaling by given factors in each dimension.

Parameters:

*factors (_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – The scaling factors by which each dimension is scaled.

Returns:

The scaling transformation.

Return type:

Transformation

geometer.transformation.translation(*coordinates)[source]

Returns a projective transformation that represents a translation by the given coordinates.

Parameters:

*coordinates (Tensor | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) – The coordinates by which points are translated when applying the resulting transformation.

Returns:

The translation.

Return type:

Transformation