The scikit-geometry package contains a whole lot of geometric algorithms. For the moment, scikit-geometry derives most of it’s functionality from the mature and stable Computational Geometry Algorithms Library (CGAL) package, a collection of geometric algorithms written in C++.

Basic Geometric Types

We aim to cleanly encapsulate the important building blocks of a geometric library. As such we have implementations for the basic geometric types:

  • Point2, Point3

  • Segment2, Ray2, Line2, Segment3, Ray3, Line3

  • Vector2, Vector3

  • Circle2

  • IsoRectangle2, Bbox2

  • Plane3, Triangle3

  • Polyhedron3

All sorts of operations can be performed with these basic building blocks. For example, one can construct a new segment from two points, then test against intersection with another segment, or a line.

import skgeom as sg
a = sg.Point2(5, 3)
b = sg.Point2(10, 8)
print(a, b)
PointC2(5, 3) PointC2(10, 8)

Now we can create a vector from two points by subtracting one from another.

v = a - b
VectorC2(-5, -5)

Or a segment between two points, where a is the source and b the target.

s = sg.Segment2(a, b)
Segment_2(PointC2(5, 3), PointC2(10, 8))

And a ray from a point and a vector which indicates the direction.

r = sg.Ray2(a, v)
RayC2(PointC2(5, 3), PointC2(-0, -2))

Finding intersections

It’s possible to find intersections between two geometric primitives by using the intersection function:

a = sg.Segment2(sg.Point2(3, 5), sg.Point2(0, -2))
b = sg.Segment2(sg.Point2(5, 3), sg.Point2(-2, -2))
i = sg.intersection(a, b)
PointC2(0.882353, 0.0588235)

Note: depending on the type of intersection, the return type could also be None or Segment2 if there is a complete overlap between the two elements.

Drawing functions

We have functionality to draw some of the geometric primitives presented here.

from skgeom.draw import draw
from random import random as r
import itertools
segments = []
for i in range(10):
    segments.append(sg.Segment2(sg.Point2(r(), r()),
                                sg.Point2(r(), r())))

intersections = []
for s1, s2 in itertools.permutations(segments, 2):
    isect = sg.intersection(s1, s2)
    if isect:

for s in segments:
for i in intersections:

Further functionality

Of course, scikit-geometry comes with much more functionality.

  • Compute convex hulls from points

  • Visibility polygons from two-dimensional arrangements

  • Compute the Minkowski sum of two polygons

[ ]: