python - 从使用 matplotlib 生成的 delaunay 三角剖分获取外心

标签 python matplotlib delaunay

如果我使用 matplotlib 为一组点生成 delaunay 三角剖分,获取已生成的三角形的外心的最合适方法是什么?我还没有设法在 Triangulation 库中找到一个明显的方法来做到这一点。

最佳答案

您应该能够使用 matplotlib.delaunay.triangulate.Triangulation 计算它:

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

. . .

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 示例(可能有更简洁的方法来执行此操作,但它应该有效):

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()

关于python - 从使用 matplotlib 生成的 delaunay 三角剖分获取外心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5596317/

相关文章:

c++ - 从 edge_iterator 获取 vertex_handle

c++ - 淡化库 Delaunay Triangulation 站点邻居

python - 为什么 python 类属性的语义在分配给实例后会发生变化?

python - 优化嵌套 numpy 数组的逻辑运算

python - Python 中的特殊 ID,想在菜单中创建帮助部分

python-2.7 - 更改 mpld3 中的刻度标签颜色

r - 设置 R 中生成 Delaunay 图的最大长度

python - 如何用我自己的方法和函数扩展 pandas 的 Dataframe 类

python-3.x - Matplotlib 图例按升序排列

matplotlib - 描述 Julia 中二维空间中数据点密度的图