
geometer Documentation Release 0.2.3 Jan Müller Sep 27, 2021 Contents: 1 Installation 3 1.1 Quickstart................................................3 1.2 API Reference..............................................5 1.3 Changelog................................................ 36 2 Indices and tables 41 2.1 References................................................ 41 Python Module Index 43 Index 45 i ii geometer Documentation, Release 0.2.3 Geometer is a geometry library for Python that uses projective geometry and numpy for fast geometric computation. In projective geometry every point in 2D is represented by a three-dimensional vector and every point in 3D is represented by a four-dimensional vector. This has the following advantages: • There are points at infinity that can be treated just like normal points. • Projective transformations are described by matrices but they can also represent translations and general affine transformations. • Two lines have a unique point of intersection if they lie in the same plane. Parallel lines have a point of intersection at infinity. • Points of intersection, planes or lines through given points can be calculated using simple cross products or tensor diagrams. • Special complex points at infinity and cross ratios can be used to calculate angles and to construct perpendicular geometric structures. • Collections of points and lines can be represented by tensors. Their connecting lines and intersections can be calculated using fast matrix multiplications. Most of the computation in the library is done via tensor diagrams (using numpy.einsum). The source code of the package can be found on GitHub and the documentation on Read the Docs. Contents: 1 geometer Documentation, Release 0.2.3 2 Contents: CHAPTER 1 Installation You can install the package directly from PyPI: pip install geometer 1.1 Quickstart 1.1.1 Geometry in Two Dimensions The elementary objects of projective geometry, points and lines can be created using the Point and Line classes without having to specify the dimension: from geometer import * p= Point(2,4) q= Point(3,5) l= Line(p, q) m= Line(0,1,0) Here we specified a line once by two base points and once using the homogeneous coordinates of the line. The two elementary operations meet and join can also be called called exactly as one would expect: l= join(p, q) r= meet(l, m) Geometer can also construct parallel and perpendicular lines: m=l.parallel(through=Point(1,1)) n=l.perpendicular(through=Point(1,1)) is_perpendicular(m, n) The function is_perpendicular() returns True when two lines are perpendicular. Other angles an distances can also be calculated: 3 geometer Documentation, Release 0.2.3 a= angle(l, Point(1,0)) dist(l, p) import numpy as np p+2 *dist(p, q)*Point(np.cos(a), np.sin(a)) Projective transformations can be easily created using the methods rotation and translation or by supplying a matrix to the Transformation class: t1= translation(0,-1) t2= rotation(-np.pi) t3= Transformation([[0,1,0], [1,0,0], [0,0,1]]) t1*t2*p Geometer also includes tools to work with conics. They can be created using the classes Conic or Circle: a= Point(-1,0) b= Point(0,3) c= Point(1,2) d= Point(2,1) e= Point(0,-1) conic= Conic.from_points(a, b, c, d, e) To calculate cross ratios of points or lines, the function crossratio() can be used: t= rotation(np.pi/16) crossratio(q, t*q, t**2 * q, t**3 * q, p) Other interesting operators are harmonic_set(), angle_bisectors(), is_cocircular() and is_collinear(). 1.1.2 Geometry in Three Dimensions Creating points and lines in 3D works the same as in the two dimensional case: p1= Point(1,1,0) p2= Point(2,1,0) p3= Point(3,4,0) l= Line(p1, p2) In addition to points and lines, in three dimensions we can use the Plane class or the join operation to create planes: A= join(l, p3) A.project(Point(3,4,5)) Points can be projected onto planes and lines. The result is still a point in 3D but now lying on the plane. The point of intersection of a plane and a line can be calculated with the meet operation: l= Line(Point(1,2,3), Point(3,4,5)) A.meet(l) All other operations such as angles, distances, perpendicular lines, cross ratios are also compatible with objects in 3D. For information on their usage, you can look at the two dimensional example. 4 Chapter 1. Installation geometer Documentation, Release 0.2.3 1.2 API Reference 1.2.1 geometer package geometer.utils package geometer.utils.math.adjugate(A) Calculates the adjugate matrix of A. The resulting matrix is defined by i+j adj(A)ij = (−1) Mji; where Mji 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): 1 adj(A) = " " A :::A ij (n − 1)! i i2:::in j j2:::jn j2i2 jnin Source (German): https://de.wikipedia.org/wiki/Levi-Civita-Symbol#Zusammenhang_mit_der_Determinante ParametersA ((. , M, M) array_like) – The input matrix. Returns The adjugate of A. Return type (.., M, M) numpy.ndarray geometer.utils.math.det(A) Computes the determinant of A. ParametersA ((. , M, M) array_like) – The input matrix. Returns The determinant of A. Return type (..) array_like geometer.utils.math.hat_matrix(*args) Builds a skew symmetric matrix with the given scalars in the positions shown below. 0 0 c −b1 @−c 0 a A b −a 0 Parameters a, b, c (float) – The scalars to use in the matrix. Returns The resulting antisymmetric matrix. Return type numpy.ndarray geometer.utils.math.inv(A) Computes the inverse of A. ParametersA ((. , M, M) array_like) – The input matrix. Returns The inverse of A. Return type (.., M, M) numpy.ndarray geometer.utils.math.is_multiple(a, b, axis=None, rtol=1e-15, atol=1e-08) Returns a boolean array where two arrays are scalar multiples of each other along a given axis. 1.2. API Reference 5 geometer Documentation, Release 0.2.3 This function compares the absolute value of the scalar product and the product of the norm of the arrays (along an axis). The Cauchy-Schwarz inequality guarantees in its edge case that this equality holds if and only if one of the vectors is a scalar multiple of the other. For documentation of the tolerance parameters see numpy.isclose(). Parameters • a, b (array_like) – Input arrays to compare. • axis (None or int or tuple of ints, optional) – 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, optional) – The relative tolerance parameter. • atol (float, optional) – 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 array_like geometer.utils.math.matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=False, ad- joint_b=False, **kwargs) Matrix product of two arrays. Parameters • a, b (array_like) – 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. • **kwargs – Additional keyword arguments for numpy.matmul. Returns The matrix product of the inputs. Return type numpy.ndarray geometer.utils.math.matvec(a, b, transpose_a=False, adjoint_a=False, **kwargs) Matrix-vector product of two arrays. Parameters • a, b (array_like) – 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. • **kwargs – Additional keyword arguments for numpy.matmul. Returns The matrix-vector product of the inputs. Return type numpy.ndarray geometer.utils.math.null_space(A, dim=None) Constructs an orthonormal basis for the null space of a A using SVD. Parameters • A ((. , M, N) array_like) – The input matrix. 6 Chapter 1. Installation geometer Documentation, Release 0.2.3 • dim (int or None, optional) – The dimension of the null space if previously known. Returns Orthonormal basis for the null space of A (as column vectors in the returned matrix). Return type (.., N, K) numpy.ndarray geometer.utils.math.orth(A, dim=None) Constructs an orthonormal basis for the range of A using SVD. Parameters • A ((. , M, N) array_like) – The input matrix. • dim (int or None, optional) – The dimension of the image space if previously known. Returns Orthonormal basis for the range of A (as column vectors in the returned matrix). Return type (.., M, K) numpy.ndarray geometer.utils.math.roots(p) Calculates the roots of a polynomial for the given coefficients. The polynomial is defined as p[0]xn + p[1]xn−1 + ::: + p[n − 1]x + p[n]: Parametersp (array_like) – The coefficients of the polynomial. Returns The roots of the polynomial. Return type array_like geometer.base module class geometer.base.KroneckerDelta(n, p=1) Bases: geometer.base.Tensor 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: 8 +1 if (휈 ; : : : ; 휈 ) are an even permutation of (휇 ; : : : ; 휇 ) <> 1 p 1 p 훿휇1...휇p = 휈1...휈p −1 if (휈1; : : : ; 휈p) are an odd permutation of (휇1; : : : ; 휇p) :>0 else Parameters • n (int) – The dimension of the tensor. • p (int, optional) – The number of covariant and contravariant indices of the tensor, default is 1. References class geometer.base.LeviCivitaTensor(size, covariant=True) Bases: geometer.base.Tensor This class can be used to construct a tensor representing the Levi-Civita symbol.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages52 Page
-
File Size-