scikit-spatial 7.2.0__tar.gz → 8.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scikit_spatial-8.0.0/AUTHORS.rst +16 -0
- scikit_spatial-8.0.0/PKG-INFO +276 -0
- scikit_spatial-8.0.0/README.md +249 -0
- scikit_spatial-8.0.0/pyproject.toml +104 -0
- scikit_spatial-8.0.0/setup.cfg +4 -0
- scikit_spatial-8.0.0/src/scikit_spatial.egg-info/PKG-INFO +276 -0
- scikit_spatial-8.0.0/src/scikit_spatial.egg-info/SOURCES.txt +32 -0
- scikit_spatial-8.0.0/src/scikit_spatial.egg-info/dependency_links.txt +1 -0
- scikit_spatial-8.0.0/src/scikit_spatial.egg-info/requires.txt +3 -0
- scikit_spatial-8.0.0/src/scikit_spatial.egg-info/top_level.txt +1 -0
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/_functions.py +3 -3
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/measurement.py +13 -13
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/__init__.py +1 -0
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/_base_array.py +27 -31
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/_base_line_plane.py +2 -5
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/_base_spatial.py +0 -3
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/_base_sphere.py +1 -2
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/_mixins.py +2 -3
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/circle.py +11 -11
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/cylinder.py +30 -35
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/line.py +14 -15
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/line_segment.py +2 -4
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/plane.py +17 -21
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/point.py +6 -6
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/points.py +13 -13
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/sphere.py +8 -8
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/triangle.py +13 -14
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/objects/vector.py +28 -25
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/plotting.py +2 -2
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/transformation.py +2 -2
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/typing.py +2 -3
- scikit_spatial-7.2.0/PKG-INFO +0 -255
- scikit_spatial-7.2.0/README.rst +0 -224
- scikit_spatial-7.2.0/pyproject.toml +0 -70
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/LICENSE +0 -0
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/__init__.py +0 -0
- {scikit_spatial-7.2.0 → scikit_spatial-8.0.0}/src/skspatial/py.typed +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
=======
|
|
2
|
+
Credits
|
|
3
|
+
=======
|
|
4
|
+
|
|
5
|
+
Development Lead
|
|
6
|
+
----------------
|
|
7
|
+
|
|
8
|
+
* Andrew Hynes (https://github.com/ajhynes7)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Contributors
|
|
12
|
+
------------
|
|
13
|
+
|
|
14
|
+
* Marcelo Moreno (https://github.com/martxelo)
|
|
15
|
+
|
|
16
|
+
* Cristiano Pizzamiglio (https://github.com/CristianoPizzamiglio)
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: scikit-spatial
|
|
3
|
+
Version: 8.0.0
|
|
4
|
+
Summary: Spatial objects and computations based on NumPy arrays.
|
|
5
|
+
Author-email: Andrew Hynes <andrewjhynes@gmail.com>
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: repository, https://github.com/ajhynes7/scikit-spatial
|
|
8
|
+
Project-URL: documentation, https://scikit-spatial.readthedocs.io
|
|
9
|
+
Keywords: NumPy,matplotlib,visualization,spatial,linear algebra
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: AUTHORS.rst
|
|
24
|
+
Requires-Dist: matplotlib>=3
|
|
25
|
+
Requires-Dist: numpy>=1.24
|
|
26
|
+
Requires-Dist: scipy>=1.9
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
[](https://pypi.python.org/pypi/scikit-spatial)
|
|
31
|
+
[](https://anaconda.org/conda-forge/scikit-spatial)
|
|
32
|
+
[](https://pypi.python.org/pypi/scikit-spatial)
|
|
33
|
+
[](https://github.com/ajhynes7/scikit-spatial/actions/workflows/main.yml)
|
|
34
|
+
[](https://results.pre-commit.ci/latest/github/ajhynes7/scikit-spatial/master)
|
|
35
|
+
[](https://scikit-spatial.readthedocs.io/en/latest/?badge=latest)
|
|
36
|
+
[](https://codecov.io/gh/ajhynes7/scikit-spatial)
|
|
37
|
+
|
|
38
|
+
# Introduction
|
|
39
|
+
|
|
40
|
+
This package provides spatial objects based on NumPy arrays, as well as
|
|
41
|
+
computations using these objects. The package includes computations for
|
|
42
|
+
2D, 3D, and higher-dimensional space.
|
|
43
|
+
|
|
44
|
+
The following spatial objects are provided:
|
|
45
|
+
|
|
46
|
+
- Point
|
|
47
|
+
- Points
|
|
48
|
+
- Vector
|
|
49
|
+
- Line
|
|
50
|
+
- LineSegment
|
|
51
|
+
- Plane
|
|
52
|
+
- Circle
|
|
53
|
+
- Sphere
|
|
54
|
+
- Triangle
|
|
55
|
+
- Cylinder
|
|
56
|
+
|
|
57
|
+
Most of the computations fall into the following categories:
|
|
58
|
+
|
|
59
|
+
- Measurement
|
|
60
|
+
- Comparison
|
|
61
|
+
- Projection
|
|
62
|
+
- Intersection
|
|
63
|
+
- Fitting
|
|
64
|
+
- Transformation
|
|
65
|
+
|
|
66
|
+
All spatial objects are equipped with plotting methods based on
|
|
67
|
+
`matplotlib`. Both 2D and 3D plotting are supported. Spatial
|
|
68
|
+
computations can be easily visualized by plotting multiple objects at
|
|
69
|
+
once.
|
|
70
|
+
|
|
71
|
+
## Why this instead of `scipy.spatial` or `sympy.geometry`?
|
|
72
|
+
|
|
73
|
+
This package has little to no overlap with the functionality of
|
|
74
|
+
`scipy.spatial`. It can be viewed as an object-oriented extension.
|
|
75
|
+
|
|
76
|
+
While similar spatial objects and computations exist in the
|
|
77
|
+
`sympy.geometry` module, `scikit-spatial` is based on NumPy rather than
|
|
78
|
+
symbolic math. The primary objects of `scikit-spatial` (`Point`,
|
|
79
|
+
`Points`, and `Vector`) are actually subclasses of the NumPy _ndarray_.
|
|
80
|
+
This gives them all the regular functionality of the _ndarray_, plus
|
|
81
|
+
additional methods from this package.
|
|
82
|
+
|
|
83
|
+
```py
|
|
84
|
+
>>> from skspatial.objects import Vector
|
|
85
|
+
|
|
86
|
+
>>> vector = Vector([2, 0, 0])
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Behaviour inherited from NumPy:
|
|
91
|
+
|
|
92
|
+
```py
|
|
93
|
+
>>> vector.size
|
|
94
|
+
3
|
|
95
|
+
|
|
96
|
+
>>> vector.mean().round(3)
|
|
97
|
+
np.float64(0.667)
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Additional methods from `scikit-spatial`:
|
|
102
|
+
|
|
103
|
+
```py
|
|
104
|
+
>>> vector.norm()
|
|
105
|
+
np.float64(2.0)
|
|
106
|
+
|
|
107
|
+
>>> vector.unit()
|
|
108
|
+
Vector([1., 0., 0.])
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Because `Point` and `Vector` are both subclasses of `ndarray`, a `Vector` can be added to a `Point`. This produces a new `Point`.
|
|
113
|
+
|
|
114
|
+
```py
|
|
115
|
+
>>> from skspatial.objects import Point
|
|
116
|
+
|
|
117
|
+
>>> Point([1, 2]) + Vector([3, 4])
|
|
118
|
+
Point([4, 6])
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`Point` and `Vector` are based on a 1D NumPy array, and `Points` is
|
|
123
|
+
based on a 2D NumPy array, where each row represents a point in space.
|
|
124
|
+
The `Line` and `Plane` objects have `Point` and `Vector` objects as
|
|
125
|
+
attributes.
|
|
126
|
+
|
|
127
|
+
Note that most methods inherited from NumPy return a regular NumPy object,
|
|
128
|
+
instead of the spatial object class.
|
|
129
|
+
|
|
130
|
+
```py
|
|
131
|
+
>>> vector.sum()
|
|
132
|
+
np.int64(2)
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This is to avoid getting a spatial object with a forbidden shape, like a
|
|
137
|
+
zero dimension `Vector`. Trying to convert this back to a `Vector`
|
|
138
|
+
causes an exception.
|
|
139
|
+
|
|
140
|
+
```py
|
|
141
|
+
>>> Vector(vector.sum())
|
|
142
|
+
Traceback (most recent call last):
|
|
143
|
+
ValueError: The array must be 1D.
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Because the computations of `scikit-spatial` are also based on NumPy,
|
|
148
|
+
keyword arguments can be passed to NumPy functions. For example, a
|
|
149
|
+
tolerance can be specified while testing for collinearity. The `tol`
|
|
150
|
+
keyword is passed to `numpy.linalg.matrix_rank`.
|
|
151
|
+
|
|
152
|
+
```py
|
|
153
|
+
>>> from skspatial.objects import Points
|
|
154
|
+
|
|
155
|
+
>>> points = Points([[1, 2, 3], [4, 5, 6], [7, 8, 8]])
|
|
156
|
+
|
|
157
|
+
>>> points.are_collinear()
|
|
158
|
+
False
|
|
159
|
+
|
|
160
|
+
>>> points.are_collinear(tol=1)
|
|
161
|
+
True
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
# Installation
|
|
166
|
+
|
|
167
|
+
The package can be installed with pip.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
$ pip install scikit-spatial
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
It can also be installed with conda.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
$ conda install scikit-spatial -c conda-forge
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
# Example Usage
|
|
182
|
+
|
|
183
|
+
## Measurement
|
|
184
|
+
|
|
185
|
+
Measure the cosine similarity between two vectors.
|
|
186
|
+
|
|
187
|
+
```py
|
|
188
|
+
>>> from skspatial.objects import Vector
|
|
189
|
+
|
|
190
|
+
>>> Vector([1, 0]).cosine_similarity([1, 1]).round(3)
|
|
191
|
+
np.float64(0.707)
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Comparison
|
|
196
|
+
|
|
197
|
+
Check if multiple points are collinear.
|
|
198
|
+
|
|
199
|
+
```py
|
|
200
|
+
>>> from skspatial.objects import Points
|
|
201
|
+
|
|
202
|
+
>>> points = Points([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
|
|
203
|
+
|
|
204
|
+
>>> points.are_collinear()
|
|
205
|
+
True
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Projection
|
|
210
|
+
|
|
211
|
+
Project a point onto a line.
|
|
212
|
+
|
|
213
|
+
```py
|
|
214
|
+
>>> from skspatial.objects import Line
|
|
215
|
+
|
|
216
|
+
>>> line = Line(point=[0, 0, 0], direction=[1, 1, 0])
|
|
217
|
+
|
|
218
|
+
>>> line.project_point([5, 6, 7])
|
|
219
|
+
Point([5.5, 5.5, 0. ])
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Intersection
|
|
224
|
+
|
|
225
|
+
Find the intersection of two planes.
|
|
226
|
+
|
|
227
|
+
```py
|
|
228
|
+
>>> from skspatial.objects import Plane
|
|
229
|
+
|
|
230
|
+
>>> plane_a = Plane(point=[0, 0, 0], normal=[0, 0, 1])
|
|
231
|
+
>>> plane_b = Plane(point=[5, 16, -94], normal=[1, 0, 0])
|
|
232
|
+
|
|
233
|
+
>>> plane_a.intersect_plane(plane_b)
|
|
234
|
+
Line(point=Point([5., 0., 0.]), direction=Vector([0, 1, 0]))
|
|
235
|
+
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
An error is raised if the computation is undefined.
|
|
239
|
+
|
|
240
|
+
```py
|
|
241
|
+
>>> plane_b = Plane(point=[0, 0, 1], normal=[0, 0, 1])
|
|
242
|
+
|
|
243
|
+
>>> plane_a.intersect_plane(plane_b)
|
|
244
|
+
Traceback (most recent call last):
|
|
245
|
+
ValueError: The planes must not be parallel.
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Fitting
|
|
250
|
+
|
|
251
|
+
Find the plane of best fit for multiple points.
|
|
252
|
+
|
|
253
|
+
```py
|
|
254
|
+
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]
|
|
255
|
+
|
|
256
|
+
>>> Plane.best_fit(points)
|
|
257
|
+
Plane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Transformation
|
|
262
|
+
|
|
263
|
+
Transform multiple points to 1D coordinates along a line.
|
|
264
|
+
|
|
265
|
+
```py
|
|
266
|
+
>>> line = Line(point=[0, 0, 0], direction=[1, 2, 0])
|
|
267
|
+
>>> points = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
268
|
+
|
|
269
|
+
>>> line.transform_points(points).round(3)
|
|
270
|
+
array([ 2.236, 6.261, 10.286])
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
# Acknowledgment
|
|
275
|
+
|
|
276
|
+
This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/scikit-spatial)
|
|
4
|
+
[](https://anaconda.org/conda-forge/scikit-spatial)
|
|
5
|
+
[](https://pypi.python.org/pypi/scikit-spatial)
|
|
6
|
+
[](https://github.com/ajhynes7/scikit-spatial/actions/workflows/main.yml)
|
|
7
|
+
[](https://results.pre-commit.ci/latest/github/ajhynes7/scikit-spatial/master)
|
|
8
|
+
[](https://scikit-spatial.readthedocs.io/en/latest/?badge=latest)
|
|
9
|
+
[](https://codecov.io/gh/ajhynes7/scikit-spatial)
|
|
10
|
+
|
|
11
|
+
# Introduction
|
|
12
|
+
|
|
13
|
+
This package provides spatial objects based on NumPy arrays, as well as
|
|
14
|
+
computations using these objects. The package includes computations for
|
|
15
|
+
2D, 3D, and higher-dimensional space.
|
|
16
|
+
|
|
17
|
+
The following spatial objects are provided:
|
|
18
|
+
|
|
19
|
+
- Point
|
|
20
|
+
- Points
|
|
21
|
+
- Vector
|
|
22
|
+
- Line
|
|
23
|
+
- LineSegment
|
|
24
|
+
- Plane
|
|
25
|
+
- Circle
|
|
26
|
+
- Sphere
|
|
27
|
+
- Triangle
|
|
28
|
+
- Cylinder
|
|
29
|
+
|
|
30
|
+
Most of the computations fall into the following categories:
|
|
31
|
+
|
|
32
|
+
- Measurement
|
|
33
|
+
- Comparison
|
|
34
|
+
- Projection
|
|
35
|
+
- Intersection
|
|
36
|
+
- Fitting
|
|
37
|
+
- Transformation
|
|
38
|
+
|
|
39
|
+
All spatial objects are equipped with plotting methods based on
|
|
40
|
+
`matplotlib`. Both 2D and 3D plotting are supported. Spatial
|
|
41
|
+
computations can be easily visualized by plotting multiple objects at
|
|
42
|
+
once.
|
|
43
|
+
|
|
44
|
+
## Why this instead of `scipy.spatial` or `sympy.geometry`?
|
|
45
|
+
|
|
46
|
+
This package has little to no overlap with the functionality of
|
|
47
|
+
`scipy.spatial`. It can be viewed as an object-oriented extension.
|
|
48
|
+
|
|
49
|
+
While similar spatial objects and computations exist in the
|
|
50
|
+
`sympy.geometry` module, `scikit-spatial` is based on NumPy rather than
|
|
51
|
+
symbolic math. The primary objects of `scikit-spatial` (`Point`,
|
|
52
|
+
`Points`, and `Vector`) are actually subclasses of the NumPy _ndarray_.
|
|
53
|
+
This gives them all the regular functionality of the _ndarray_, plus
|
|
54
|
+
additional methods from this package.
|
|
55
|
+
|
|
56
|
+
```py
|
|
57
|
+
>>> from skspatial.objects import Vector
|
|
58
|
+
|
|
59
|
+
>>> vector = Vector([2, 0, 0])
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Behaviour inherited from NumPy:
|
|
64
|
+
|
|
65
|
+
```py
|
|
66
|
+
>>> vector.size
|
|
67
|
+
3
|
|
68
|
+
|
|
69
|
+
>>> vector.mean().round(3)
|
|
70
|
+
np.float64(0.667)
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Additional methods from `scikit-spatial`:
|
|
75
|
+
|
|
76
|
+
```py
|
|
77
|
+
>>> vector.norm()
|
|
78
|
+
np.float64(2.0)
|
|
79
|
+
|
|
80
|
+
>>> vector.unit()
|
|
81
|
+
Vector([1., 0., 0.])
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Because `Point` and `Vector` are both subclasses of `ndarray`, a `Vector` can be added to a `Point`. This produces a new `Point`.
|
|
86
|
+
|
|
87
|
+
```py
|
|
88
|
+
>>> from skspatial.objects import Point
|
|
89
|
+
|
|
90
|
+
>>> Point([1, 2]) + Vector([3, 4])
|
|
91
|
+
Point([4, 6])
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`Point` and `Vector` are based on a 1D NumPy array, and `Points` is
|
|
96
|
+
based on a 2D NumPy array, where each row represents a point in space.
|
|
97
|
+
The `Line` and `Plane` objects have `Point` and `Vector` objects as
|
|
98
|
+
attributes.
|
|
99
|
+
|
|
100
|
+
Note that most methods inherited from NumPy return a regular NumPy object,
|
|
101
|
+
instead of the spatial object class.
|
|
102
|
+
|
|
103
|
+
```py
|
|
104
|
+
>>> vector.sum()
|
|
105
|
+
np.int64(2)
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This is to avoid getting a spatial object with a forbidden shape, like a
|
|
110
|
+
zero dimension `Vector`. Trying to convert this back to a `Vector`
|
|
111
|
+
causes an exception.
|
|
112
|
+
|
|
113
|
+
```py
|
|
114
|
+
>>> Vector(vector.sum())
|
|
115
|
+
Traceback (most recent call last):
|
|
116
|
+
ValueError: The array must be 1D.
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Because the computations of `scikit-spatial` are also based on NumPy,
|
|
121
|
+
keyword arguments can be passed to NumPy functions. For example, a
|
|
122
|
+
tolerance can be specified while testing for collinearity. The `tol`
|
|
123
|
+
keyword is passed to `numpy.linalg.matrix_rank`.
|
|
124
|
+
|
|
125
|
+
```py
|
|
126
|
+
>>> from skspatial.objects import Points
|
|
127
|
+
|
|
128
|
+
>>> points = Points([[1, 2, 3], [4, 5, 6], [7, 8, 8]])
|
|
129
|
+
|
|
130
|
+
>>> points.are_collinear()
|
|
131
|
+
False
|
|
132
|
+
|
|
133
|
+
>>> points.are_collinear(tol=1)
|
|
134
|
+
True
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
# Installation
|
|
139
|
+
|
|
140
|
+
The package can be installed with pip.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
$ pip install scikit-spatial
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
It can also be installed with conda.
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
$ conda install scikit-spatial -c conda-forge
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
# Example Usage
|
|
155
|
+
|
|
156
|
+
## Measurement
|
|
157
|
+
|
|
158
|
+
Measure the cosine similarity between two vectors.
|
|
159
|
+
|
|
160
|
+
```py
|
|
161
|
+
>>> from skspatial.objects import Vector
|
|
162
|
+
|
|
163
|
+
>>> Vector([1, 0]).cosine_similarity([1, 1]).round(3)
|
|
164
|
+
np.float64(0.707)
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Comparison
|
|
169
|
+
|
|
170
|
+
Check if multiple points are collinear.
|
|
171
|
+
|
|
172
|
+
```py
|
|
173
|
+
>>> from skspatial.objects import Points
|
|
174
|
+
|
|
175
|
+
>>> points = Points([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
|
|
176
|
+
|
|
177
|
+
>>> points.are_collinear()
|
|
178
|
+
True
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Projection
|
|
183
|
+
|
|
184
|
+
Project a point onto a line.
|
|
185
|
+
|
|
186
|
+
```py
|
|
187
|
+
>>> from skspatial.objects import Line
|
|
188
|
+
|
|
189
|
+
>>> line = Line(point=[0, 0, 0], direction=[1, 1, 0])
|
|
190
|
+
|
|
191
|
+
>>> line.project_point([5, 6, 7])
|
|
192
|
+
Point([5.5, 5.5, 0. ])
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Intersection
|
|
197
|
+
|
|
198
|
+
Find the intersection of two planes.
|
|
199
|
+
|
|
200
|
+
```py
|
|
201
|
+
>>> from skspatial.objects import Plane
|
|
202
|
+
|
|
203
|
+
>>> plane_a = Plane(point=[0, 0, 0], normal=[0, 0, 1])
|
|
204
|
+
>>> plane_b = Plane(point=[5, 16, -94], normal=[1, 0, 0])
|
|
205
|
+
|
|
206
|
+
>>> plane_a.intersect_plane(plane_b)
|
|
207
|
+
Line(point=Point([5., 0., 0.]), direction=Vector([0, 1, 0]))
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
An error is raised if the computation is undefined.
|
|
212
|
+
|
|
213
|
+
```py
|
|
214
|
+
>>> plane_b = Plane(point=[0, 0, 1], normal=[0, 0, 1])
|
|
215
|
+
|
|
216
|
+
>>> plane_a.intersect_plane(plane_b)
|
|
217
|
+
Traceback (most recent call last):
|
|
218
|
+
ValueError: The planes must not be parallel.
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Fitting
|
|
223
|
+
|
|
224
|
+
Find the plane of best fit for multiple points.
|
|
225
|
+
|
|
226
|
+
```py
|
|
227
|
+
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]
|
|
228
|
+
|
|
229
|
+
>>> Plane.best_fit(points)
|
|
230
|
+
Plane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Transformation
|
|
235
|
+
|
|
236
|
+
Transform multiple points to 1D coordinates along a line.
|
|
237
|
+
|
|
238
|
+
```py
|
|
239
|
+
>>> line = Line(point=[0, 0, 0], direction=[1, 2, 0])
|
|
240
|
+
>>> points = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
241
|
+
|
|
242
|
+
>>> line.transform_points(points).round(3)
|
|
243
|
+
array([ 2.236, 6.261, 10.286])
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
# Acknowledgment
|
|
248
|
+
|
|
249
|
+
This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scikit-spatial"
|
|
7
|
+
version = "8.0.0"
|
|
8
|
+
description = "Spatial objects and computations based on NumPy arrays."
|
|
9
|
+
|
|
10
|
+
license = { text = "BSD-3-Clause" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Andrew Hynes", email = "andrewjhynes@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
keywords = ["NumPy", "matplotlib", "visualization", "spatial", "linear algebra"]
|
|
17
|
+
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 5 - Production/Stable",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"License :: OSI Approved :: BSD License",
|
|
22
|
+
"Natural Language :: English",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Topic :: Scientific/Engineering",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
requires-python = ">=3.8"
|
|
32
|
+
|
|
33
|
+
dependencies = [
|
|
34
|
+
"matplotlib>=3",
|
|
35
|
+
"numpy>=1.24",
|
|
36
|
+
"scipy>=1.9",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
repository = "https://github.com/ajhynes7/scikit-spatial"
|
|
41
|
+
documentation = "https://scikit-spatial.readthedocs.io"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
packages = { find = { where = ["src"] } }
|
|
45
|
+
|
|
46
|
+
[tool.uv]
|
|
47
|
+
dev-dependencies = [
|
|
48
|
+
"pytest-cov>=5.0.0",
|
|
49
|
+
"pytest>=8.3.3",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
pythonpath = ["src"]
|
|
54
|
+
|
|
55
|
+
[tool.ruff]
|
|
56
|
+
line-length = 120
|
|
57
|
+
|
|
58
|
+
[tool.ruff.lint]
|
|
59
|
+
select = [
|
|
60
|
+
# pydocstyle
|
|
61
|
+
"D",
|
|
62
|
+
# flake8-bugbear
|
|
63
|
+
"B",
|
|
64
|
+
# flake8-builtins
|
|
65
|
+
"A",
|
|
66
|
+
# flake8-commas
|
|
67
|
+
"COM",
|
|
68
|
+
# flake8-comprehensions
|
|
69
|
+
"C4",
|
|
70
|
+
# flake8-eradicate
|
|
71
|
+
"ERA",
|
|
72
|
+
# flake8-print
|
|
73
|
+
"T20",
|
|
74
|
+
# flake8-pytest-style
|
|
75
|
+
"PT",
|
|
76
|
+
# flake8-simplify
|
|
77
|
+
"SIM",
|
|
78
|
+
# flake8-unused-arguments
|
|
79
|
+
"ARG",
|
|
80
|
+
# isort
|
|
81
|
+
"I",
|
|
82
|
+
# pycodestyle
|
|
83
|
+
"E", "W",
|
|
84
|
+
# pyflakes
|
|
85
|
+
"F",
|
|
86
|
+
# NumPy 2 deprecation
|
|
87
|
+
"NPY201",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
ignore = [
|
|
91
|
+
"D104",
|
|
92
|
+
"D105",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[tool.ruff.lint.pydocstyle]
|
|
96
|
+
convention = "numpy"
|
|
97
|
+
|
|
98
|
+
[tool.ruff.lint.per-file-ignores]
|
|
99
|
+
"tests/*" = ["D"]
|
|
100
|
+
"examples/*" = ["D"]
|
|
101
|
+
"docs/*" = ["D"]
|
|
102
|
+
|
|
103
|
+
[tool.ruff.format]
|
|
104
|
+
quote-style = "preserve"
|