discretize.utils.extend_surface_boundary#
- discretize.utils.extend_surface_boundary(xyz, max_miter=5.0)[source]#
Extend a triangulated surface outward from every node on its boundary.
A new point is added for every node along the boundary of the triangulation (not just the convex hull). Each new point starts at the same location as the node it comes from, and is offset horizontally along the outward bisector of the boundary edges adjacent to that node. The new points are triangulated with the original ones once, so extending the surface by a distance
d(a nearest neighbor extrapolation of the surface) is just a scaling of the returned directions.- Parameters:
- xyz(
n_points,dim) array_like ortuple Surface points, where
dimis 2 or 3. The last column is the vertical coordinate. A point cloud is triangulated (Delaunay) along the horizontal dimensions (in 2D it is sorted along x and connected as a line). Alternatively supply your own connectivity as a tuple of(xyz, simplices), wheresimplicesare line segments (2D) or triangles (3D) indexingxyz.- max_miter
float,optional Maximum length of the offset direction, which limits how far the extension of very sharp boundary corners can reach.
- xyz(
- Returns:
- xyz_ext(
n_points+n_new,dim)numpy.ndarray The original (sorted, in 2D) points followed by the new points, which have the vertical coordinate of the node they extend.
- simplices_ext(
n_simplices+n_new_simplices,dim)numpy.ndarray The simplices connecting the original and new points.
- directions(
n_points+n_new,dim- 1)numpy.ndarray Horizontal offset directions, which are zero for the original points. The extended surface for a distance
d(a scalar, or one value per horizontal dimension) isxyz_ext[:, :-1] + d * directions. The directions are scaled such that boundary edges move out by a perpendicular distanced.
- xyz_ext(
- Raises:
ValueErrorIf
xyzhas 2 columns and all of its points have the same x location.
Notes
For surfaces with a non-convex boundary, the outward bisectors of different boundary nodes can intersect if the distance is large compared to the size of local features of the boundary (e.g. notches or concavities). The extended surface can then fold over itself and be unreliable.
Examples
>>> import numpy as np >>> from discretize.utils import extend_surface_boundary >>> x, y = np.mgrid[0:1:3j, 0:1:3j] >>> xyz = np.stack([x, y, x + y], axis=-1).reshape(-1, 3) >>> xyz_ext, simps, dirs = extend_surface_boundary(xyz) >>> padded = xyz_ext[:, :-1] + 0.1 * dirs >>> padded.shape (17, 2)