porepy.geometry.map_geometry module
Collection of functions related to geometry mappings, rotations etc.
- compute_normal(pts, tol=1e-5)[source]
Compute the normal of a set of points.
The sign of the normal is arbitrary The algorithm assumes that the points lie on a plane. Three non-aligned points are needed. If the points are almost collinear, the algorithm will attempt to find a combination of points that minimizes rounding errors. To ensure stable results, make sure to provide points that truly span a 2d plane.
- Parameters
- Raises
ValueError – If less than three points are provided.
ValueError – If all points provided are collinear (relative to the specified tolerance)
- Returns
An array with
shape=(3,)
representing the normal.- Return type
- compute_normals_1d(pts)[source]
Compute the normals of a set of points aligned along a 1d line.
The sign and direction of the two normal vectors are arbitrary. The algorithm assumes that the points lie on a line.
Example
>>> pts = = np.array([[1,0,0],[0,1,0],[0,0,1]]).T >>> x=pp.map_geometry.compute_normals_1d(pts) >>> x >>> array([[-0.4472136 , -0.36514837], >>> [-0.89442719, 0.18257419], >>> [ 0. , -0.91287093]])
See also
- compute_tangent(pts, check=True)[source]
Compute a tangent vector of a set of points that are aligned along a 1d line.
- force_point_collinearity(pts)[source]
Given a set of points, return them aligned on a line.
Useful to enforce collinearity for almost collinear points. The order of the points remain the same.
- map_grid(g, tol=1e-5, R=None)[source]
Map a grid to a local coordinate system.
If a 2d or a 1d grid is passed, the function returns the cell_centers, face_normals, and face_centers using local coordinates. If a 3d grid is passed nothing is applied. The return vectors have a reduced number of rows.
- Parameters
g (Grid) – The subdomain grid.
tol (float) –
default=1e-5
Tolerance used to check that the grid is linear or planar.
R (Optional[ndarray[Any, dtype[float64]]]) –
default=None
Rotation matrix (shape=(3, 3)). The first dim rows should map vectors onto the tangential space of the grid.
If not provided, a rotation matrix will be computed.
- Returns
Mapped attributes of the grid.
ndarray
:shape=(g.dim, g.num_cells)
The mapped centers of the cells.
ndarray
:shape=(g.dim, g.num_faces)
The mapped normals of the faces.
ndarray
:shape=(g.dim, g.num_faces)
The mapped centers of the faces.
ndarray
:shape=(3, 3)
The rotation matrix used.
Indices of the active dimensions
ndarray
:shape=(g.dim, g.num_nodes)
The mapped nodes.
- Return type
tuple[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.int64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]]
- normal_matrix(pts=None, normal=None)[source]
Compute the normal projection matrix of a plane.
The algorithm assume that the points lie on a plane. Three non-aligned points are required.
Note
Either
pts
ornormal
are mandatory.- Parameters
- Raises
ValueError – If neither
pts
nornormal
is provided.- Returns
An array with
shape=(3, 3)
representing the normal matrix.- Return type
- project_line_matrix(pts, tangent=None, reference=None)[source]
Project the points on a line using local coordinates.
The projected points are computed by a dot product.
Example
>>> pts = np.array([[1,0,0],[0,1,0],[0,0,1]]).T >>> R = project_line_matrix(pts) >>> projection_points=np.dot(R,pts)
- Parameters
pts (ndarray[Any, dtype[float64]]) –
shape=(3, n)
An array, representing the points.
tangent (
optional
) –default=None
The tangent unit vector of the plane, otherwise two points are required.
reference (Optional[ndarray[Any, dtype[float64]]]) –
(shape=(3,), default=None)
Reference vector to compute the angles. Defaults to
[0, 0, 1]
.
- Returns
An array (shape=(3, 3)), representing the projection matrix.
- Return type
- project_plane_matrix(pts, normal=None, tol=1e-5, reference=None, check_planar=True)[source]
Project the points on a plane using local coordinates.
The projected points are computed by a dot product.
- Parameters
pts (ndarray[Any, dtype[float64]]) –
shape=(3, n)
A matrix representing the points.
normal (Optional[ndarray[Any, dtype[float64]]]) –
default=None
The normal of the plane, otherwise three points are required.
tol (float) –
default=1e-5
Tolerance to assert the planarity of the cloud of points.
reference (Optional[ndarray[Any, dtype[float64]]]) –
(shape=(3,), default=None)
Reference array to compute the angles. Defaults to
[0, 0, 1]
.check_planar (bool) –
default=True
Whether to check for planarity. Defaults to True
- Returns
An array with
shape=(3, 3)
representing the projection matrix.- Return type
- project_points_to_line(p, tol=1e-4)[source]
Project a set of colinear points onto a line.
The points should be co-linear such that a 1d description is meaningful.
- Parameters
- Raises
ValueError – If the points are not aligned on a line.
- Returns
ndarray
:(shape=(np,))
One-dimensional coordinates of the points, sorted along the line.
ndarray
:(shape=(3, 3)
Rotation matrix used for mapping the points onto a coordinate axis.
int
:The dimension onto which the point coordinates were mapped.
ndarray
:(shape=(np,))
Index array used to sort the points onto the line.
- Return type
Information on the projected points
- rotation_matrix(a, vect)[source]
Compute the rotation matrix about a vector by an angle using the matrix form of Rodrigues’ formula.
- Parameters
- Returns
An array with
shape=(3, 3)
representing the rotation matrix.If vect is a zero vector, the returned rotation matrix will be the identity matrix.
- Return type
- sort_points_on_line(pts, tol=1e-5)[source]
Return the indexes of the point according to their position on a line.
- tangent_matrix(pts=None, normal=None)[source]
Compute the tangential projection matrix of a plane.
The algorithm assume that the points lie on a plane. Three non-aligned points are required.
Note
Either points or normal are mandatory.
- Parameters
- Raises
ValueError – If neither
pts
nornormal
is provided.- Returns
An array with
shape=(3, 3)
representing the tangential matrix.- Return type