Getting a circle from delaunay triangulation created using matplotlib

If I use matplotlib to generate delaunay triangulation for a group of points, what is the most suitable way to get the circles of the triangles that were wrapped? I have not yet been able to find the obvious method in the triangulation library for this.

+4
source share
1 answer

You can calculate it using matplotlib.delaunay.triangulate.Triangulation :

Triangulation (x, y) x, y - coordinates of points in the form of 1-D arrays of floats

. ,.

Attributes: (all should be considered read-only to maintain consistency) x, y - coordinates of points in the form of 1-D arrays of floats.

  circumcenters -- (ntriangles, 2) array of floats giving the (x,y) coordinates of the circumcenters of each triangle (indexed by a triangle_id). 

Adapted from one of the matplotlib examples (maybe this is a cleaner way, but it should work):

 import matplotlib.pyplot as plt import matplotlib.delaunay import matplotlib.tri as tri import numpy as np import math # Creating a Triangulation without specifying the triangles results in the # Delaunay triangulation of the points. # First create the x and y coordinates of the points. n_angles = 36 n_radii = 8 min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False) angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1) angles[:,1::2] += math.pi/n_angles x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() tt = matplotlib.delaunay.triangulate.Triangulation(x,y) triang = tri.Triangulation(x, y) # Plot the triangulation. plt.figure() plt.gca().set_aspect('equal') plt.triplot(triang, 'bo-') plt.plot(tt.circumcenters[:,0],tt.circumcenters[:,1],'r.') plt.show() 
+3
source

Source: https://habr.com/ru/post/1347259/


All Articles