This package provides spatial objects based on NumPy arrays, as well as
computations using these objects. The package includes computations for
2D, 3D, and higher-dimensional space.
The following spatial objects are provided:
Point
Points
Vector
Line
LineSegment
Plane
Circle
Sphere
Triangle
Cylinder
Most of the computations fall into the following categories:
Measurement
Comparison
Projection
Intersection
Fitting
Transformation
All spatial objects are equipped with plotting methods based on
matplotlib. Both 2D and 3D plotting are supported. Spatial
computations can be easily visualized by plotting multiple objects at
once.
Why this instead of scipy.spatial or sympy.geometry?
This package has little to no overlap with the functionality of
scipy.spatial. It can be viewed as an object-oriented extension.
While similar spatial objects and computations exist in the
sympy.geometry module, scikit-spatial is based on NumPy rather than
symbolic math. The primary objects of (,
, and ) are actually subclasses of the NumPy .
This gives them all the regular functionality of the , plus
additional methods from this package.
Because Point and Vector are both subclasses of ndarray, a Vector can be added to a Point. This produces a new Point.
>>> from skspatial.objects import Point
>>> Point([1, 2]) + Vector([3, 4])
Point([4, 6])
Point and Vector are based on a 1D NumPy array, and Points is
based on a 2D NumPy array, where each row represents a point in space.
The Line and Plane objects have Point and Vector objects as
attributes.
Note that most methods inherited from NumPy return a regular NumPy object,
instead of the spatial object class.
>>> vector.sum()
np.int64(2)
This is to avoid getting a spatial object with a forbidden shape, like a
zero dimension Vector. Trying to convert this back to a Vector
causes an exception.
>>> Vector(vector.sum())
Traceback (most recent call last):
ValueError: The array must be 1D.
Because the computations of scikit-spatial are also based on NumPy,
keyword arguments can be passed to NumPy functions. For example, a
tolerance can be specified while testing for collinearity. The tol
keyword is passed to numpy.linalg.matrix_rank.