triangle
triangle copied to clipboard
i cannot establish a restrictive triangulation network
how can I modify my code to make it work,Here's the code: import matplotlib.pyplot as plt import numpy as np
import triangle as tr
def circle(N, R): i = np.arange(N) theta = i * 2 * np.pi / N pts = np.stack([np.cos(theta), np.sin(theta)], axis=1) * R seg = np.stack([i, i + 1], axis=1) % N return pts, seg
pts0, seg0 = circle(30, 1.4) pts1, seg1 = circle(16, 1.2) pts2, seg2 = circle(17, 1) pts = np.vstack([pts0, pts1, pts2]) seg = np.vstack([seg0, seg1 + seg0.shape[0]])
A = dict(vertices=pts, segments=seg1 + seg0.shape[0]) B = tr.triangulate(A) tr.compare(plt, A, B) plt.show()
@huang-GD; Is this what you want?
def circle(N, R):
i = np.arange(N)
theta = i * 2 * np.pi / N
pts = np.stack([np.cos(theta), np.sin(theta)], axis=1) * R
seg = np.stack([i, i + 1], axis=1) % N
return pts, seg
pts0, seg0 = circle(30, 1.4)
pts1, seg1 = circle(16, 1.2)
pts2, seg2 = circle(17, 1)
ptst = np.vstack([pts0, pts1, pts2])
seg = np.vstack([seg0, seg1 + seg0.shape[0], seg2 + seg0.shape[0] + seg1.shape[0]])
At = dict(vertices=ptst, segments=seg, holes=[[0, 0]])
Bt = tr.triangulate(At, 'p')
tr.compare(plt, At, Bt)
plt.show()

thank you