porepy.geometry.geometry_property_checks module
This module contains functions for (boolean) inquiries about geometric objects, and relations between objects.
- is_ccw_polygon(poly)[source]
Determine if the vertices of a polygon are sorted counterclockwise.
The method computes the winding number of the polygon, see below references.
The algorithm should work for non-convex polygons. If the polygon is self-intersecting (e.g. shaped like the number 8), the number returned will reflect whether the method is ‘mostly’ cw or ccw.
Note
The test can not be used to determine whether the vertexes of a polygon are ordered in a natural fashion, that is, not self-intersecting.
Examples
>>> is_ccw_polygon(np.array([[0, 1, 0], [0, 0, 1]])) True >>> is_ccw_polygon(np.array([[0, 0, 1], [0, 1, 0]])) False
See also
- is_ccw_polyline(p1, p2, p3, tol=0, default=False)[source]
Checks if a polyline of three points goes in a counterclockwise direction.
The line segment going from
p1
top2
is tested vs. a third point to determine whether the combined line segments (polyline) is part of a counterclockwise circle. The function can test both one and several points vs. the same line segment.The test is positive if the test point lies to left of the line running from
p1
top2
.The function is intended for 2D points; higher-dimensional coordinates will be ignored.
Extensions to lines with more than three points should be straightforward, the input points should be merged into a 2d array.
Examples
>>> p1 = np.array([0, 0]) >>> p2 = np.array([1, 1]) >>> p3 = np.array([[0.5, 0.3, 0.5], [0.2, 0.7, 0.1]]) >>> is_ccw_polyline(p1, p2, p3) [False True False]
>>> p1 = np.array([0, 0]) >>> p2 = np.array([1, 1]) >>> p3 = np.array([0.5, 0.3]) >>> is_ccw_polyline(p1, p2, p3) False
See also
- Parameters
p1 (ndarray) –
shape=(2,)
First point on dividing line.
p2 (ndarray) –
shape=(2,)
Second point on dividing line.
p3 (ndarray) –
(shape=(2,) or shape=(2, n))
Point(s) to be tested. For one point, only arrays of
shape=(2,)
is accepted. For two or more points the array will haveshape=(2, n)
, where the first row corresponds to x-coordinates and the second row corresponds to y-coordinates. See examples.tol (float) –
default=0
Tolerance used in the comparison, can be used to account for rounding errors.
default (bool) –
default=False
Mode returned if the point is within the tolerance. Should be set according to what is desired behavior of the function (will vary with application).
- Returns
An array of booleans, with one entry for each point in
p3
. True if the point is to the left of the line segmentp1-p2
.- Return type
- point_in_cell(poly, p, if_make_planar=True)[source]
Check whether a point is inside a cell.
Note
A similar behavior could be reached using
is_inside_polygon()
, however the current implementation deals with concave cells as well. Not sure which is the best, in terms of performance, for convex cells.- Parameters
poly (ndarray) –
shape=(3, n)
Vertexes of polygon. The segments are formed by connecting subsequent columns of poly.
p (ndarray) –
shape=(3, 1)
Point to be tested.
if_make_planar (bool) –
default=True
The cell needs to lie on (s, t) plane. If not already done, this flag need to be used. Projects the points to the plane of the polygon.
- Returns
True
if the point is inside the cell. If a point is on the boundary of the cell the result may be eitherTrue
orFalse
.- Return type
- point_in_polygon(poly, p, default=False)[source]
Check if a set of points are inside a polygon.
The polygon need not be convex.
References
- Parameters
- Returns
A boolean array containing
True
for each of the points that are inside polygon.- Return type
- point_in_polyhedron(polyhedron, test_points, tol=1e-10)[source]
Test whether a set of point is inside a polyhedron.
- Parameters
polyhedron (Union[ndarray, list[numpy.ndarray]]) –
shape=(num_sides, 3, num_polygon_vertices)
Each outer element represents a side of the polyhedron, and each side is assumed to be a convex polygon.
test_points (ndarray) –
shape=(3, np)
Points to be tested.
tol (float) –
default=1e-10
Geometric tolerance, used in comparison of points.
- Returns
For each point, element
i
isTrue
iftest_points[:, i]
is inside the polygon, else it isFalse
.- Return type
- polygon_hanging_nodes(p, edges, tol=1e-8)[source]
Find hanging nodes of a polygon.
- Parameters
p (ndarray) –
shape=(nd, n_pt)
Point coordinates. Number of rows is number of dimensions, number of columns is number of points.
edges (ndarray) –
shape=(2, num_edges)
Indices, referring to columns in p, of edges in the polygon. Should be ordered so that
edges[1, i] == edges[0, i+1]
, andedges[0, 0] == edges[1, -1]
.tol (float) –
default=1e-8
Tolerance for when two segments will be considered parallel.
- Returns
Index of edges with hanging nodes. For an index i, the lines defined by
edges[:, i]
andedges[:, i+1]
(oredges[:, 0]
ifi == edges.shape[1]
- 1) are parallel.- Return type