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

2024-03-05

如果我使用 matplotlib 为一组点生成 delaunay 三角剖分,那么获取已生成的三角形的外心的最合适方法是什么?我尚未在三角测量库中找到明显的方法来执行此操作。


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

三角测量(x, y) x, y -- 作为一维浮点数数组的点的坐标

. . .

属性:(全部应视为 只读以保持一致性) x, y -- 作为一维浮点数数组的点的坐标。

  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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从使用 matplotlib 生成的 delaunay 三角剖分中获取外心 的相关文章

随机推荐