__init__.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. """
  2. =============================================================
  3. Spatial algorithms and data structures (:mod:`scipy.spatial`)
  4. =============================================================
  5. .. currentmodule:: scipy.spatial
  6. .. toctree::
  7. :hidden:
  8. spatial.distance
  9. spatial.transform
  10. Spatial transformations
  11. =======================
  12. These are contained in the `scipy.spatial.transform` submodule.
  13. Nearest-neighbor queries
  14. ========================
  15. .. autosummary::
  16. :toctree: generated/
  17. KDTree -- class for efficient nearest-neighbor queries
  18. cKDTree -- class for efficient nearest-neighbor queries (faster implementation)
  19. Rectangle
  20. Distance metrics
  21. ================
  22. Distance metrics are contained in the :mod:`scipy.spatial.distance` submodule.
  23. Delaunay triangulation, convex hulls, and Voronoi diagrams
  24. ==========================================================
  25. .. autosummary::
  26. :toctree: generated/
  27. Delaunay -- compute Delaunay triangulation of input points
  28. ConvexHull -- compute a convex hull for input points
  29. Voronoi -- compute a Voronoi diagram hull from input points
  30. SphericalVoronoi -- compute a Voronoi diagram from input points on the surface of a sphere
  31. HalfspaceIntersection -- compute the intersection points of input halfspaces
  32. Plotting helpers
  33. ================
  34. .. autosummary::
  35. :toctree: generated/
  36. delaunay_plot_2d -- plot 2-D triangulation
  37. convex_hull_plot_2d -- plot 2-D convex hull
  38. voronoi_plot_2d -- plot 2-D Voronoi diagram
  39. .. seealso:: :ref:`Tutorial <qhulltutorial>`
  40. Simplex representation
  41. ======================
  42. The simplices (triangles, tetrahedra, etc.) appearing in the Delaunay
  43. tessellation (N-D simplices), convex hull facets, and Voronoi ridges
  44. (N-1-D simplices) are represented in the following scheme::
  45. tess = Delaunay(points)
  46. hull = ConvexHull(points)
  47. voro = Voronoi(points)
  48. # coordinates of the jth vertex of the ith simplex
  49. tess.points[tess.simplices[i, j], :] # tessellation element
  50. hull.points[hull.simplices[i, j], :] # convex hull facet
  51. voro.vertices[voro.ridge_vertices[i, j], :] # ridge between Voronoi cells
  52. For Delaunay triangulations and convex hulls, the neighborhood
  53. structure of the simplices satisfies the condition:
  54. ``tess.neighbors[i,j]`` is the neighboring simplex of the ith
  55. simplex, opposite to the ``j``-vertex. It is -1 in case of no neighbor.
  56. Convex hull facets also define a hyperplane equation::
  57. (hull.equations[i,:-1] * coord).sum() + hull.equations[i,-1] == 0
  58. Similar hyperplane equations for the Delaunay triangulation correspond
  59. to the convex hull facets on the corresponding N+1-D
  60. paraboloid.
  61. The Delaunay triangulation objects offer a method for locating the
  62. simplex containing a given point, and barycentric coordinate
  63. computations.
  64. Functions
  65. ---------
  66. .. autosummary::
  67. :toctree: generated/
  68. tsearch
  69. distance_matrix
  70. minkowski_distance
  71. minkowski_distance_p
  72. procrustes
  73. geometric_slerp
  74. Warnings / Errors used in :mod:`scipy.spatial`
  75. ----------------------------------------------
  76. .. autosummary::
  77. :toctree: generated/
  78. QhullError
  79. """ # noqa: E501
  80. from ._kdtree import *
  81. from ._ckdtree import * # type: ignore[import-not-found]
  82. from ._qhull import *
  83. from ._spherical_voronoi import SphericalVoronoi
  84. from ._plotutils import *
  85. from ._procrustes import procrustes
  86. from ._geometric_slerp import geometric_slerp
  87. # Deprecated namespaces, to be removed in v2.0.0
  88. from . import ckdtree, kdtree, qhull
  89. __all__ = [s for s in dir() if not s.startswith('_')]
  90. from . import distance, transform
  91. __all__ += ['distance', 'transform']
  92. from scipy._lib._testutils import PytestTester
  93. test = PytestTester(__name__)
  94. del PytestTester