4

matplotlib を使用してポイント グループのドローネ三角形分割を生成する場合、生成された三角形の外心を取得する最も適切な方法は何ですか? これを行うための明白な方法を Triangulation ライブラリでまだ見つけることができませんでした。

4

2 に答える 2

3

次を使用して計算できるはずですmatplotlib.delaunay.triangulate.Triangulation

Triangulation(x, y) x, y -- float の 1-D 配列としての点の座標

. . .

属性: (一貫性を維持するために、すべて読み取り専用として扱う必要があります) x、y -- float の 1-D 配列としてのポイントの座標。

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

matplotlib の例の 1 つからの適応 (おそらくこれを行うよりクリーンな方法がありますが、動作するはずです):

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()
于 2011-04-08T14:37:50.383 に答える