## SciPy – 42 – strutture di dati spaziali e algoritmi – 1 Continuo da qui, copio qui.

`scipy.spatial` can compute triangulations, Voronoi diagrams, and convex hulls of a set of points, by leveraging the `Qhull` library.

Moreover, it contains `KDTree` implementations for nearest-neighbor point queries, and utilities for distance computations in various metrics.

Triangolazione Delaunay
The Delaunay triangulation is a subdivision of a set of points into a non-overlapping set of triangles, such that no point is inside the circumcircle of any triangle. In practice, such triangulations tend to avoid triangles with small angles.

Delaunay triangulation can be computed using `scipy.spatial` as follows: We can visualize it:  The structure of the triangulation is encoded in the following way: the `simplices` attribute contains the indices of the points in the `points` array that make up the triangle. For instance: Moreover, neighboring triangles can also be found out: What this tells us is that this triangle has triangle `#0` as a neighbor, but no other neighbors. Moreover, it tells us that neighbor `0` is opposite the vertex `1` of the triangle: Indeed, from the figure we see that this is the case.

`Qhull` can also perform tesselations to simplices also for higher-dimensional point sets (for instance, subdivision into tetrahedra in 3-D).

Punti coplanari
It is important to note that not all points necessarily appear as vertices of the triangulation, due to numerical precision issues in forming the triangulation. Consider the above with a duplicated point: Observe that point `#4`, which is a duplicate, does not occur as a vertex of the triangulation. That this happened is recorded: This means that point `4` resides near triangle `0` and vertex `3`, but is not included in the triangulation.

Note that such degeneracies can occur not only because of duplicated points, but also for more complicated geometrical reasons, even in point sets that at first sight seem well-behaved.

However, `Qhull` has the `"QJ"` option, which instructs it to perturb the input data randomly until degeneracies are resolved: Two new triangles appeared. However, we see that they are degenerate and have zero area. Posta un commento o usa questo indirizzo per il trackback.