grains.cad.branches2boundary¶
-
grains.cad.branches2boundary(branches, orientation='ccw')[source]¶ Joins connecting branches so that they form the boundary of a surface.
This function assumes that you already know that a set of branches form the boundary of a surface, but you want to know the ordering. Clockwise or counterclockwise orientation is supported. A branch is given by its two end points but it can also contain intermediate points in between, as in the general case. The points on the branches are assumed to be ordered. If certain branches are not used in forming the boundary of a surface, they are excluded from the output lists.
- Parameters
branches (list) – Each element of the list gives N>=2 points on the branch, ordered from one end point to the other. If N=2, the two end points are meant. The points are provided as an Nx2 ndarray, the first column giving the x, the second column giving the y coordinates of the points.
orientation ({‘cw’, ‘ccw’}, optional) – Clockwise (‘cw’) or counterclockwise (‘ccw’) orientation of the surface boundary. The default is ‘ccw’.
- Returns
order (list) – Order of the branches so that they form the boundary of a surface.
redirected (list) – A list of bool with True value if the orientation of the corresponding branch had to be swapped to form the surface boundary.
polygon (ndarray) – The polygon formed by connecting the points of the branches along the boundary. It is given given as an Mx2 ndarray, where M is the number of unique points on the boundary (i.e. only one end point is kept for two connecting branches). This auxiliary data is not essential as it can be restored from the set of branches, and their ordering. However, it is computed as temporary data needed for determining the orientation of the boundary.
Examples
>>> import numpy as np >>> branches = [np.array([[1, 1], [1.5, 2], [2, 3]]), np.array([[1, 1], [-1, 2]]), ... np.array([[1.5, -3], [2, 3]]), np.array([[1.5, -3], [-1, 2]])] >>> order, redirected, polygon = branches2boundary(branches, orientation='cw') >>> order [0, 2, 3, 1] >>> redirected [False, True, True, False] >>> polygon array([[ 1. , 1. ], [ 1.5, 2. ], [ 2. , 3. ], [ 1.5, -3. ], [-1. , 2. ]])