Spatial objects and computations based on NumPy arrays.
Project description
Introduction
This package provides spatial objects based on NumPy arrays, as well as computations using these objects. The package includes computations for 2D, 3D, and higherdimensional space.
The following spatial objects are provided:
 Point
 Points
 Vector
 Line
 Plane
 Circle
 Sphere
 Triangle
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 objectoriented extension.
While similar spatial objects and computations exist in the sympy.geometry module, scikitspatial is based on NumPy rather than symbolic math. The primary objects of scikitspatial (Point, Points, and Vector) are actually subclasses of the NumPy ndarray. This gives them all the regular functionality of the ndarray, plus additional methods from this package.
>>> from skspatial.objects import Vector
>>> vector = Vector([2, 0, 0])
Behaviour inherited from NumPy:
>>> vector.size 3 >>> vector.mean().round(3) 0.667
Additional methods from scikitspatial:
>>> vector.norm() 2.0 >>> vector.unit() Vector([1., 0., 0.])
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.
Because the computations of scikitspatial 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.
>>> from skspatial.objects import Points
>>> points = Points([[1, 2, 3], [4, 5, 6], [7, 8, 8]])
>>> points.are_collinear() False >>> points.are_collinear(tol=1) True
Installation
The package can be installed via pip.
$ pip install scikitspatial
Example Usage
Measurement
Measure the cosine similarity between two vectors.
>>> from skspatial.objects import Vector
>>> Vector([1, 0]).cosine_similarity([1, 1]).round(3) 0.707
Comparison
Check if multiple points are collinear.
>>> from skspatial.objects import Points
>>> points = Points([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
>>> points.are_collinear() True
Projection
Project a point onto a line.
>>> from skspatial.objects import Line
>>> line = Line(point=[0, 0, 0], direction=[1, 1, 0])
>>> line.project_point([5, 6, 7]) Point([5.5, 5.5, 0. ])
Intersection
Find the intersection of two planes.
>>> from skspatial.objects import Plane
>>> plane_a = Plane([0, 0, 0], [0, 0, 1]) >>> plane_b = Plane([5, 16, 94], [1, 0, 0])
>>> plane_a.intersect_plane(plane_b) Line(point=Point([5., 0., 0.]), direction=Vector([0, 1, 0]))
An error is raised if the computation is undefined.
>>> plane_b = Plane([0, 0, 1], [0, 0, 1])
>>> plane_a.intersect_plane(line_b) Traceback (most recent call last): ... ValueError: The planes must not be parallel.
Fitting
Find the plane of best fit for multiple points.
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]
>>> Plane.best_fit(points) Plane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))
Transformation
Transform multiple points to 1D coordinates along a line.
>>> line = Line(point=[0, 0, 0], direction=[1, 2, 0]) >>> points = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> line.transform_points(points).round(3) array([ 2.236, 6.261, 10.286])
Acknowledgment
This package was created with Cookiecutter and the audreyr/cookiecutterpypackage project template.
Project details
Release history Release notifications
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size scikit_spatial4.0.1py2.py3noneany.whl (63.3 kB)  File type Wheel  Python version py2.py3  Upload date  Hashes View hashes 
Filename, size scikitspatial4.0.1.tar.gz (58.5 kB)  File type Source  Python version None  Upload date  Hashes View hashes 
Hashes for scikit_spatial4.0.1py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  0e73e937f321c0b8915fc1479f16e0433f1222c0d5bdbc169c65f1f8803c941f 

MD5  cb95f3c8dd1bc9b0b23f456e7d3f3c98 

BLAKE2256  e04998d481826df8956d7551bf52689db779fc9d047086e51964bcd9be155a7d 