def __init__(self, x, y): self.x = np.asarray(x, dtype=np.float64) self.y = np.asarray(y, dtype=np.float64) if self.x.shape != self.y.shape or len(self.x.shape) != 1: raise ValueError("x,y must be equal-length 1-D arrays") self.old_shape = self.x.shape duplicates = self._get_duplicate_point_indices() if len(duplicates) > 0: warnings.warn( "Input data contains duplicate x,y points; some values are " "ignored.", DuplicatePointWarning, ) # self.j_unique is the array of non-duplicate indices, in # increasing order. self.j_unique = np.delete(np.arange(len(self.x)), duplicates) self.x = self.x[self.j_unique] self.y = self.y[self.j_unique] else: self.j_unique = None # If there are duplicate points, need a map of point indices used # by delaunay to those used by client. If there are no duplicate # points then the map is not needed. Either way, the map is # conveniently the same as j_unique, so share it. self._client_point_index_map = self.j_unique self.circumcenters, self.edge_db, self.triangle_nodes, \ self.triangle_neighbors = delaunay(self.x, self.y) self.hull = self._compute_convex_hull()
def __init__(self, x, y): self.x = np.asarray(x, dtype=np.float64) self.y = np.asarray(y, dtype=np.float64) if self.x.shape != self.y.shape or len(self.x.shape) != 1: raise ValueError("x,y must be equal-length 1-D arrays") self.old_shape = self.x.shape j_unique = self._collapse_duplicate_points() if j_unique.shape != self.x.shape: warnings.warn( "Input data contains duplicate x,y points; some values are ignored.", DuplicatePointWarning, ) self.j_unique = j_unique self.x = self.x[self.j_unique] self.y = self.y[self.j_unique] else: self.j_unique = None self.circumcenters, self.edge_db, self.triangle_nodes, \ self.triangle_neighbors = delaunay(self.x, self.y) self.hull = self._compute_convex_hull()
def __init__(self, x, y): self.x = np.asarray(x, dtype=np.float64) self.y = np.asarray(y, dtype=np.float64) if self.x.shape != self.y.shape or len(self.x.shape) != 1: raise ValueError("x,y must be equal-length 1-D arrays") self.old_shape = self.x.shape duplicates = self._get_duplicate_point_indices() if len(duplicates) > 0: warnings.warn( "Input data contains duplicate x,y points; some values are ignored.", DuplicatePointWarning, ) # self.j_unique is the array of non-duplicate indices, in # increasing order. self.j_unique = np.delete(np.arange(len(self.x)), duplicates) self.x = self.x[self.j_unique] self.y = self.y[self.j_unique] else: self.j_unique = None # If there are duplicate points, need a map of point indices used # by delaunay to those used by client. If there are no duplicate # points then the map is not needed. Either way, the map is # conveniently the same as j_unique, so share it. self._client_point_index_map = self.j_unique self.circumcenters, self.edge_db, self.triangle_nodes, \ self.triangle_neighbors = delaunay(self.x, self.y) self.hull = self._compute_convex_hull()
def vor(pnts, plot=True): """ : D delaunay triangulation : tr triangles : C """ x = pnts[:, 0] y = pnts[:, 1] lbl = np.arange(len(x)) #D = tri.Triangulation(x, y) #tr = D.triangles #n = tr.shape[0] #C = circumcircle2(pnts[tr]) Dd = dy.delaunay(x, y) # for version 3.5 c_cents, edges, tri_pnts, tri_nbrs = Dd if plot: # Mask off unwanted triangles. min_radius = 0.25 xmid = x[tri_pnts].mean(axis=1) ymid = y[tri_pnts].mean(axis=1) mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) # Plot the triangulation. plt.figure() plt.gca().set_aspect('equal') #plt.triplot(D, 'bo-') for label, xpt, ypt in zip(lbl, x, y): plt.text(xpt, ypt, label) plt.triplot(x, y, tri_pnts, mask=mask) plt.scatter(x, y, s=20, c='b', marker='o') plt.scatter(c_cents[:, 0], c_cents[:, 1], s=40, c='r', marker='x') plt.title('triplot of Delaunay triangulation') plt.show() plt.close() return Dd, c_cents, edges, tri_pnts, tri_nbrs #D, tr, n, Dd