从使用 matplotlib 生成的 delaunay 三角剖分中获取外心 [英] Getting the circumcentres from a delaunay triangulation generated using matplotlib
问题描述
如果我使用 matplotlib 为一组点生成 delaunay 三角剖分,那么获取已生成三角形的外心的最合适的方法是什么?我还没有设法在 Triangulation 库中找到一个明显的方法来做到这一点.
If I use matplotlib to generate a delaunay triangulation for a group of points, what is the most appropraite way of getting the circumcentres of the triangles that have been geenrated? I haven't yet managed to find an obvious method in the Triangulation library to do this.
推荐答案
您应该可以使用 matplotlib.delaunay.triangulate.Triangulation
进行计算:
You should be able to calculate it using matplotlib.delaunay.triangulate.Triangulation
:
三角剖分(x, y)x,y-点的坐标为浮点数的一维数组
Triangulation(x, y) x, y -- the coordinates of the points as 1-D arrays of floats
...
属性:(所有应视为只读以保持一致性)x, y -- 一维浮点数组形式的点坐标.
Attributes: (all should be treated as read-only to maintain consistency) x, y -- the coordinates of the points as 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).
从其中一个matplotlib示例改编(可能有一种更简洁的方法,但是应该可以):
Adapted from one of the matplotlib examples (there is probably a cleaner way to do this, 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()
这篇关于从使用 matplotlib 生成的 delaunay 三角剖分中获取外心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!