Archive
In [7]:
Copied!
import numpy as np
import scipy
import matplotlib.pyplot as plt
import numpy as np
import scipy
import matplotlib.pyplot as plt
In [8]:
Copied!
path = "./data/p1_swanPolygon.txt"
boundaries = np.loadtxt(path, delimiter='\t') # (x, y) pairs
path = "./data/p1_swanPolygon.txt"
boundaries = np.loadtxt(path, delimiter='\t') # (x, y) pairs
In [70]:
Copied!
def triangle_mesh(boundaries):
x_max, x_min = np.max(boundaries[:,0]), np.min(boundaries[:,0])
y_max, y_min = np.max(boundaries[:,1]), np.min(boundaries[:,1])
vertices = np.array([[x_min - 1, y_min - 1],
[x_min - 1, y_max + 1],
[x_max + 1, y_min - 1],
[x_max + 1, y_max + 1]])
vertices = np.concatenate((vertices, boundaries), axis=0)
tri = scipy.spatial.Delaunay(vertices).simplices
tri = tri[np.all(tri > 4, axis=1)]
vertices = vertices[4:]
tri = tri - 4
return vertices, tri
def triangle_mesh(boundaries):
x_max, x_min = np.max(boundaries[:,0]), np.min(boundaries[:,0])
y_max, y_min = np.max(boundaries[:,1]), np.min(boundaries[:,1])
vertices = np.array([[x_min - 1, y_min - 1],
[x_min - 1, y_max + 1],
[x_max + 1, y_min - 1],
[x_max + 1, y_max + 1]])
vertices = np.concatenate((vertices, boundaries), axis=0)
tri = scipy.spatial.Delaunay(vertices).simplices
tri = tri[np.all(tri > 4, axis=1)]
vertices = vertices[4:]
tri = tri - 4
return vertices, tri
In [72]:
Copied!
vertices, tri = triangle_mesh(boundaries)
plt.plot(vertices[:,0], vertices[:,1], 'o')
plt.triplot(vertices[:,0], vertices[:,1], tri)
vertices, tri = triangle_mesh(boundaries)
plt.plot(vertices[:,0], vertices[:,1], 'o')
plt.triplot(vertices[:,0], vertices[:,1], tri)
In [54]:
Copied!
plt.triplot(vertices[:,0], vertices[:,1], lines)
plt.gca().axis('equal')
plt.triplot(vertices[:,0], vertices[:,1], lines)
plt.gca().axis('equal')
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[54], line 1 ----> 1 plt.triplot(vertices[:,0], vertices[:,1], lines) 2 plt.gca().axis('equal') File ~/Source/tiankaima/Notebooks/venv/lib/python3.11/site-packages/matplotlib/pyplot.py:4021, in triplot(*args, **kwargs) 4019 @_copy_docstring_and_deprecators(Axes.triplot) 4020 def triplot(*args, **kwargs): -> 4021 return gca().triplot(*args, **kwargs) File ~/Source/tiankaima/Notebooks/venv/lib/python3.11/site-packages/matplotlib/tri/_triplot.py:40, in triplot(ax, *args, **kwargs) 8 """ 9 Draw an unstructured triangular grid as lines and/or markers. 10 (...) 36 The drawn marker nodes. 37 """ 38 import matplotlib.axes ---> 40 tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args, **kwargs) 41 x, y, edges = (tri.x, tri.y, tri.edges) 43 # Decode plot format string, e.g., 'ro-' File ~/Source/tiankaima/Notebooks/venv/lib/python3.11/site-packages/matplotlib/tri/_triangulation.py:167, in Triangulation.get_from_args_and_kwargs(*args, **kwargs) 164 else: 165 x, y, triangles, mask, args, kwargs = \ 166 Triangulation._extract_triangulation_params(args, kwargs) --> 167 triangulation = Triangulation(x, y, triangles, mask) 168 return triangulation, args, kwargs File ~/Source/tiankaima/Notebooks/venv/lib/python3.11/site-packages/matplotlib/tri/_triangulation.py:80, in Triangulation.__init__(self, x, y, triangles, mask) 75 raise ValueError( 76 'triangles are indices into the points and must be in the ' 77 f'range 0 <= i < {len(self.x)} but found value ' 78 f'{self.triangles.max()}') 79 if self.triangles.min() < 0: ---> 80 raise ValueError( 81 'triangles are indices into the points and must be in the ' 82 f'range 0 <= i < {len(self.x)} but found value ' 83 f'{self.triangles.min()}') 85 # Underlying C++ object is not created until first needed. 86 self._cpp_triangulation = None ValueError: triangles are indices into the points and must be in the range 0 <= i < 87 but found value -3
In [ ]:
Copied!