{"id":15797259,"url":"https://github.com/ajhynes7/scikit-spatial","last_synced_at":"2025-05-16T12:07:14.864Z","repository":{"id":37597286,"uuid":"172586363","full_name":"ajhynes7/scikit-spatial","owner":"ajhynes7","description":"Spatial objects and computations based on NumPy arrays.","archived":false,"fork":false,"pushed_at":"2024-12-23T23:02:49.000Z","size":2196,"stargazers_count":93,"open_issues_count":2,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-01T13:09:47.215Z","etag":null,"topics":["3d-math","linear-algebra","matplotlib","numpy","python","spatial","visualization"],"latest_commit_sha":null,"homepage":"https://scikit-spatial.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajhynes7.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-25T21:17:48.000Z","updated_at":"2025-03-23T17:55:09.000Z","dependencies_parsed_at":"2023-11-17T00:11:46.363Z","dependency_job_id":"ab6fe6c1-bf5a-47e7-bc8f-a4bd3099a9a3","html_url":"https://github.com/ajhynes7/scikit-spatial","commit_stats":{"total_commits":1230,"total_committers":13,"mean_commits":94.61538461538461,"dds":"0.41056910569105687","last_synced_commit":"dbaac9eef3b6c09ec2ce79c083a91310aad2132e"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajhynes7%2Fscikit-spatial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajhynes7%2Fscikit-spatial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajhynes7%2Fscikit-spatial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajhynes7%2Fscikit-spatial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajhynes7","download_url":"https://codeload.github.com/ajhynes7/scikit-spatial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987184,"owners_count":21028891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-math","linear-algebra","matplotlib","numpy","python","spatial","visualization"],"created_at":"2024-10-05T00:05:48.632Z","updated_at":"2025-05-16T12:07:14.851Z","avatar_url":"https://github.com/ajhynes7.png","language":"Python","readme":"![](images/logo.svg)\n\n[![image](https://img.shields.io/pypi/v/scikit-spatial.svg)](https://pypi.python.org/pypi/scikit-spatial)\n[![image](https://anaconda.org/conda-forge/scikit-spatial/badges/version.svg)](https://anaconda.org/conda-forge/scikit-spatial)\n[![image](https://img.shields.io/pypi/pyversions/scikit-spatial.svg)](https://pypi.python.org/pypi/scikit-spatial)\n[![image](https://github.com/ajhynes7/scikit-spatial/actions/workflows/main.yml/badge.svg)](https://github.com/ajhynes7/scikit-spatial/actions/workflows/main.yml)\n[![Documentation Status](https://readthedocs.org/projects/scikit-spatial/badge/?version=latest)](https://scikit-spatial.readthedocs.io/en/latest/?badge=latest)\n[![image](https://codecov.io/gh/ajhynes7/scikit-spatial/branch/master/graph/badge.svg)](https://codecov.io/gh/ajhynes7/scikit-spatial)\n\n# Introduction\n\nThis package provides spatial objects based on NumPy arrays, as well as\ncomputations using these objects. The package includes computations for\n2D, 3D, and higher-dimensional space.\n\nThe following spatial objects are provided:\n\n- Point\n- Points\n- Vector\n- Line\n- LineSegment\n- Plane\n- Circle\n- Sphere\n- Triangle\n- Cylinder\n\nMost of the computations fall into the following categories:\n\n- Measurement\n- Comparison\n- Projection\n- Intersection\n- Fitting\n- Transformation\n\nAll spatial objects are equipped with plotting methods based on\n`matplotlib`. Both 2D and 3D plotting are supported. Spatial\ncomputations can be easily visualized by plotting multiple objects at\nonce.\n\n## Why this instead of `scipy.spatial` or `sympy.geometry`?\n\nThis package has little to no overlap with the functionality of\n`scipy.spatial`. It can be viewed as an object-oriented extension.\n\nWhile similar spatial objects and computations exist in the\n`sympy.geometry` module, `scikit-spatial` is based on NumPy rather than\nsymbolic math. The primary objects of `scikit-spatial` (`Point`,\n`Points`, and `Vector`) are actually subclasses of the NumPy _ndarray_.\nThis gives them all the regular functionality of the _ndarray_, plus\nadditional methods from this package.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Vector\n\n\u003e\u003e\u003e vector = Vector([2, 0, 0])\n\n```\n\nBehaviour inherited from NumPy:\n\n```py\n\u003e\u003e\u003e vector.size\n3\n\n\u003e\u003e\u003e vector.mean().round(3)\nnp.float64(0.667)\n\n```\n\nAdditional methods from `scikit-spatial`:\n\n```py\n\u003e\u003e\u003e vector.norm()\nnp.float64(2.0)\n\n\u003e\u003e\u003e vector.unit()\nVector([1., 0., 0.])\n\n```\n\nBecause `Point` and `Vector` are both subclasses of `ndarray`, a `Vector` can be added to a `Point`. This produces a new `Point`.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Point\n\n\u003e\u003e\u003e Point([1, 2]) + Vector([3, 4])\nPoint([4, 6])\n\n```\n\n`Point` and `Vector` are based on a 1D NumPy array, and `Points` is\nbased on a 2D NumPy array, where each row represents a point in space.\nThe `Line` and `Plane` objects have `Point` and `Vector` objects as\nattributes.\n\nNote that most methods inherited from NumPy return a regular NumPy object,\ninstead of the spatial object class.\n\n```py\n\u003e\u003e\u003e vector.sum()\nnp.int64(2)\n\n```\n\nThis is to avoid getting a spatial object with a forbidden shape, like a\nzero dimension `Vector`. Trying to convert this back to a `Vector`\ncauses an exception.\n\n```py\n\u003e\u003e\u003e Vector(vector.sum())\nTraceback (most recent call last):\nValueError: The array must be 1D.\n\n```\n\nBecause the computations of `scikit-spatial` are also based on NumPy,\nkeyword arguments can be passed to NumPy functions. For example, a\ntolerance can be specified while testing for collinearity. The `tol`\nkeyword is passed to `numpy.linalg.matrix_rank`.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Points\n\n\u003e\u003e\u003e points = Points([[1, 2, 3], [4, 5, 6], [7, 8, 8]])\n\n\u003e\u003e\u003e points.are_collinear()\nFalse\n\n\u003e\u003e\u003e points.are_collinear(tol=1)\nTrue\n\n```\n\n# Installation\n\nThe package can be installed with pip.\n\n```bash\n$ pip install scikit-spatial\n\n```\n\nIt can also be installed with conda.\n\n```bash\n$ conda install scikit-spatial -c conda-forge\n\n```\n\nThe `matplotlib` dependency is optional. To enable plotting, you can install scikit-spatial with the extra `plotting`.\n\n```bash\n   $ pip install 'scikit-spatial[plotting]'\n\n```\n\n# Example Usage\n\n## Measurement\n\nMeasure the cosine similarity between two vectors.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Vector\n\n\u003e\u003e\u003e Vector([1, 0]).cosine_similarity([1, 1]).round(3)\nnp.float64(0.707)\n\n```\n\n## Comparison\n\nCheck if multiple points are collinear.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Points\n\n\u003e\u003e\u003e points = Points([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])\n\n\u003e\u003e\u003e points.are_collinear()\nTrue\n\n```\n\n## Projection\n\nProject a point onto a line.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Line\n\n\u003e\u003e\u003e line = Line(point=[0, 0, 0], direction=[1, 1, 0])\n\n\u003e\u003e\u003e line.project_point([5, 6, 7])\nPoint([5.5, 5.5, 0. ])\n\n```\n\n## Intersection\n\nFind the intersection of two planes.\n\n```py\n\u003e\u003e\u003e from skspatial.objects import Plane\n\n\u003e\u003e\u003e plane_a = Plane(point=[0, 0, 0], normal=[0, 0, 1])\n\u003e\u003e\u003e plane_b = Plane(point=[5, 16, -94], normal=[1, 0, 0])\n\n\u003e\u003e\u003e plane_a.intersect_plane(plane_b)\nLine(point=Point([5., 0., 0.]), direction=Vector([0, 1, 0]))\n\n```\n\nAn error is raised if the computation is undefined.\n\n```py\n\u003e\u003e\u003e plane_b = Plane(point=[0, 0, 1], normal=[0, 0, 1])\n\n\u003e\u003e\u003e plane_a.intersect_plane(plane_b)\nTraceback (most recent call last):\nValueError: The planes must not be parallel.\n\n```\n\n## Fitting\n\nFind the plane of best fit for multiple points.\n\n```py\n\u003e\u003e\u003e points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]]\n\n\u003e\u003e\u003e Plane.best_fit(points)\nPlane(point=Point([0.5, 0.5, 0. ]), normal=Vector([0., 0., 1.]))\n\n```\n\n## Transformation\n\nTransform multiple points to 1D coordinates along a line.\n\n```py\n\u003e\u003e\u003e line = Line(point=[0, 0, 0], direction=[1, 2, 0])\n\u003e\u003e\u003e points = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n\n\u003e\u003e\u003e line.transform_points(points).round(3)\narray([ 2.236,  6.261, 10.286])\n\n```\n\n# Acknowledgment\n\nThis package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajhynes7%2Fscikit-spatial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajhynes7%2Fscikit-spatial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajhynes7%2Fscikit-spatial/lists"}