porepy.geometry.distances module

The module contains functions for distance computations.

point_pointset(p, pset, exponent=2)[source]

Compute distance between a point and a set of points.

Parameters:
  • p (ndarray) –

    shape=(nd, 1)

    Point from which distances will be computed.

  • pset (ndarray) –

    shape=(nd, num_points)

    Point cloud to which we compute distances.

  • exponent (float | int) –

    default=2

    Exponent of the norm used.

Returns:

Array of distances (shape=(num_points,)).

Return type:

ndarray

points_polygon(p, poly, tol=1e-5)[source]

Compute distance from points to a polygon. Also find closest point on the polygon.

Parameters:
  • p (ndarray) –

    shape=(nd, num_points)

    Points for which we will compute distances.

  • poly (ndarray) –

    shape=(nd, num_vertexes)

    Vertexes of polygon. Edges are formed by subsequent points.

  • tol (float) –

    default=1e-5

    Tolerance to be used.

Returns:

A tuple of 3 elements.

ndarray: shape=(num_points,)

Distance from points to polygon.

ndarray: shape=(nd, num_points,)

For each point, the closest point on the polygon.

ndarray: shape=(num_points)

True if the point is found in the interior, False if on a bounding segment.

Return type:

tuple[ndarray, ndarray, ndarray]

points_segments(p, start, end)[source]

Compute distances between points and line segments.

The function also returns the closest points on the segments.

Parameters:
  • p (ndarray) –

    shape=(nd, num_points)

    Individual points.

  • start (ndarray) –

    shape=(nd, num_segments)

    Start points of segments.

  • end (ndarray) –

    shape=(nd, num_segments)

    End point of segments.

Returns:

A tuple of 2 elements.

ndarray: shape=(num_points, num_segments)

Distances.

ndarray: shape=(num_points, num_segments, nd)

Points on the segments closest to the individual points.

Return type:

tuple[ndarray, ndarray]

pointset(p, max_diag=False)[source]

Compute mutual distance between all points in a point set.

Parameters:
  • p (ndarray) –

    shape=(nd, num_points)

    A set of points.

  • max_diag (bool) –

    default=False

    If True, the diagonal value corresponding to each point is set to twice the maximum of the distances for that point, rather than 0.

Returns:

Array of distances between points (shape=(num_points, num_points)).

Return type:

ndarray

segment_overlap_segment_set(start, end, start_set, end_set, return_indices=False, tol=1e-5)[source]

Detects whether a given segment overlaps the segments in a set.

The function currently works only for 2D geometries: nd == 2.

Parameters:
  • start (ndarray) –

    shape=(nd,)

    Start point of a segment.

  • end (ndarray) –

    shape=(nd,)

    End point of a segment.

  • start_set (ndarray) –

    shape=(nd, num_segments)

    Start points of the set of segments.

  • end_set (ndarray) –

    shape=(nd, num_segments)

    End points of the set of segments.

  • return_indices (bool) –

    default=False

    Whether the function should also return indices of overlappings.

  • tol (float) –

    default=1e-5

    Tolerance to be used.

Returns:

If return_indices==True, we return a tuple of 2 elements.

bool:

True if the segment overlaps any of the segments in the set, False otherwise.

ndarray: shape=(num_overlapping,)

Indices of overlappings.

Otherwise, the 0th element of the tuple is returned.

Return type:

bool | tuple[bool, ndarray]

segment_segment_set(start, end, start_set, end_set)[source]

Compute distance and closest points between a segment and a set of segments.

Note

Algorithm can be found at http://geomalgorithms.com/code.html (see file “C07_Line_Line_Distance.cpp”, function dist3D_Segment_to_Segment()).

Parameters:
  • start (ndarray) –

    shape=(nd, 1)

    Start point of the main segment.

  • end (ndarray) –

    shape=(nd, 1)

    End point of the main segment.

  • start_set (ndarray) –

    shape=(nd, num_segments)

    Start points for the segment set.

  • end_set (ndarray) –

    shape=(nd, num_segments)

    End points for the segment set.

Returns:

A tuple of 3 elements.

ndarray: shape=(num_segments,)

The distance from the main segment to each of the segments in the set.

ndarray: shape=(nd, num_segments)

For each segment in the segment set, the point closest on the main segment.

ndarray: shape=(nd, num_segments)

For each segment in the segment set, the point closest on the secondary segment.

Return type:

tuple[ndarray, ndarray, ndarray]

segment_set(start, end)[source]

Compute distance and closest points between sets of line segments.

Parameters:
  • start (ndarray) –

    shape=(nd, num_segments)

    Start points of segments.

  • end (ndarray) –

    shape=(nd, num_segments)

    End points of segments.

Returns:

A tuple of 2 elements.

ndarray: shape=(num_segments, num_segments)

Distances between segments.

ndarray: shape=(num_segments, num_segments, nd)

For segment i and j, element [i, j] gives the point on i closest to segment j.

Return type:

tuple[ndarray, ndarray]

segments_polygon(start, end, poly, tol=1e-5)[source]

Compute the distance from line segments to a polygon.

Parameters:
  • start (ndarray) –

    shape=(nd, num_segments)

    One endpoint of segments.

  • end (ndarray) –

    shape=(nd, num_segments)

    Other endpoint of segments.

  • poly (ndarray) –

    shape=(nd, n_vert)

    Vertexes of polygon.

  • tol (float) –

    default=1e-5

    Tolerance to be used.

Returns:

A tuple of 2 elements.

ndarray: (shape=(num_segments,), dtype=double)

Distance from segment to polygon.

ndarray: shape=(nd, num_segments)

Closest point.

Return type:

tuple[ndarray, ndarray]