Skip to main content

Python geometry package based on projective geometry and numpy.

Project description

geometer

version license python tests docs codecov black

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.

Installation

You can install the package directly from PyPI:

pip install geometer

Usage

from geometer import *
import numpy as np

# Meet and Join operations
p = Point(2, 4)
q = Point(3, 5)
l = Line(p, q)
m = Line(0, 1, 0)
l.meet(m)
# Point(-2, 0)

# Parallel and perpendicular lines
m = l.parallel(through=Point(1, 1))
n = l.perpendicular(through=Point(1, 1))
is_perpendicular(m, n)
# True

# Angles and distances (euclidean)
a = angle(l, Point(1, 0))
p + 2*dist(p, q)*Point(np.cos(a), np.sin(a))
# Point(4, 6)

# Transformations
t1 = translation(0, -1)
t2 = rotation(-np.pi)
t1*t2*p
# Point(-2, -5)

# Collections of points and lines
coordinates = np.random.randint(100, size=(1000, 2))
points = PointCollection([Point(x, y) for x, y in coordinates])
lines = points.join(-points)
zero = PointCollection(np.zeros((1000, 2)), homogenize=True)
lines.meet(rotation(np.pi/2)*lines) == zero
# True

# Ellipses/Quadratic forms
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)
ellipse = Conic.from_foci(c, d, bound=b)

# Geometric shapes
o = Point(0, 0)
x, y = Point(1, 0), Point(0, 1)
r = Rectangle(o, x, x+y, y)
r.area
# 1

# 3-dimensional objects
p1 = Point(1, 1, 0)
p2 = Point(2, 1, 0)
p3 = Point(3, 4, 0)
l = p1.join(p2)
A = join(l, p3)
A.project(Point(3, 4, 5))
# Point(3, 4, 0)

l = Line(Point(1, 2, 3), Point(3, 4, 5))
A.meet(l)
# Point(-2, -1, 0)

p3 = Point(1, 2, 0)
p4 = Point(1, 1, 1)
c = Cuboid(p1, p2, p3, p4)
c.area
# 6

# Cross ratios
t = rotation(np.pi/16)
crossratio(q, t*q, t**2 * q, t**3 * q, p)
# 1.4408954235712448

# Higher dimensions
p1 = Point(1, 1, 4, 0)
p2 = Point(2, 1, 5, 0)
p3 = Point(3, 4, 6, 0)
p4 = Point(0, 2, 7, 0)
E = Plane(p1, p2, p3, p4)
l = Line(Point(0, 0, 0, 0), Point(1, 2, 3, 4))
E.meet(l)
# Point(0, 0, 0, 0)

References

Many of the algorithms and formulas implemented in the package are taken from the following books and papers:

  • Jürgen Richter-Gebert, Perspectives on Projective Geometry
  • Jürgen Richter-Gebert and Thorsten Orendt, Geometriekalküle
  • Olivier Faugeras, Three-Dimensional Computer Vision
  • Jim Blinn, Lines in Space: The 4D Cross Product
  • Jim Blinn, Lines in Space: The Line Formulation
  • Jim Blinn, Lines in Space: The Two Matrices
  • Jim Blinn, Lines in Space: Back to the Diagrams
  • Jim Blinn, Lines in Space: A Tale of Two Lines
  • Jim Blinn, Lines in Space: Our Friend the Hyperbolic Paraboloid
  • Jim Blinn, Lines in Space: The Algebra of Tinkertoys
  • Jim Blinn, Lines in Space: Line(s) through Four Lines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geometer-0.4.1.tar.gz (114.4 kB view details)

Uploaded Source

Built Distribution

geometer-0.4.1-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file geometer-0.4.1.tar.gz.

File metadata

  • Download URL: geometer-0.4.1.tar.gz
  • Upload date:
  • Size: 114.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for geometer-0.4.1.tar.gz
Algorithm Hash digest
SHA256 1701124dea9f748f00b50adad91a1a471af96571ae8d5ff9b73858a1cbdb9822
MD5 c911b0f5dfa0c8af2396fc196bd008b4
BLAKE2b-256 73a8c615ffcf1148cbab4c79794d8b1466bb79d7d38283dbf9c969616f1ace4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for geometer-0.4.1.tar.gz:

Publisher: release-please.yaml on jan-mue/geometer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geometer-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: geometer-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for geometer-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5288f10ef3a3b328b3471db8d5ca6dc06445112dd240b7c110c3cd8102a6ef1c
MD5 1ece236327584f7571608814b853357a
BLAKE2b-256 1b04dc5802a3f6b09fc670a03058a0b7a9df95861591efd819b155a3c76c3a4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for geometer-0.4.1-py3-none-any.whl:

Publisher: release-please.yaml on jan-mue/geometer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page