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:
Segment2, Ray2, Line2, Segment3, Ray3, Line3
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 print(v)
Or a segment between two points, where
a is the source and
b the target.
s = sg.Segment2(a, b) print(s)
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) print(r)
RayC2(PointC2(5, 3), PointC2(-0, -2))
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) print(i)
Note: depending on the type of intersection, the return type could also be
Segment2 if there is a complete overlap between the two elements.
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: intersections.append(isect) for s in segments: draw(s) for i in intersections: draw(i)
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