Skip to content

unsigned_distance

unsigned_distance(Q, V, F=None, use_cpp=True, cpp_aabb=None)

Unsigned distances from a set of points in space.

General-purpose function which computes the unsigned distance from a set of points to a mesh (in 3D) or polyline (in 2D). In 3D, this uses an AABB tree for efficient computation.

Parameters:

Name Type Description Default
Q (p,dim) numpy double array

Matrix of query point positions

required
V (v,dim) numpy double array

Matrix of mesh/polyline/pointcloud coordinates

required
F (f,s) numpy int array (optional

Matrix of mesh/polyline/pointcloud indices into V. If None, input is assumed to be an ordered closed polyline in 2D.

None)
use_cpp bool, optional (default False)

If True, uses a C++ implementation to compute the squared distances. This is much faster but requires compilation of the C++ code.

True
cpp_aabb gpytoolbox.squared_distance_precompute, optional (default None)

Precomputed AABB tree built via gpytoolbox.squared_distance_precompute(V, F). Only used when use_cpp=True. Reuses the tree across calls instead of rebuilding it, avoiding the O(n) construction cost on every query.

None

Returns:

Name Type Description
unsigned_distances (p,) numpy double array

Vector of minimum unsigned distances

indices (p,) numpy int array

Indices into F (or V, if F is None) of closest elements to each query point

lmbs (p,s) numpy double array

Barycentric coordinates into the closest element of each closest mesh point to each query point

See Also

squared_distance, squared_distance_precompute

Source code in src/gpytoolbox/unsigned_distance.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def unsigned_distance(Q,V,F=None,use_cpp=True,cpp_aabb=None):
    """Unsigned distances from a set of points in space.

    General-purpose function which computes the unsigned distance from a set of points to a mesh (in 3D) or polyline (in 2D). In 3D, this uses an AABB tree for efficient computation.

    Parameters
    ----------
    Q : (p,dim) numpy double array
        Matrix of query point positions
    V : (v,dim) numpy double array
        Matrix of mesh/polyline/pointcloud coordinates
    F : (f,s) numpy int array (optional, default None)
        Matrix of mesh/polyline/pointcloud indices into V. If None, input is assumed to be an ordered *closed* polyline in 2D.
    use_cpp : bool, optional (default False)
        If True, uses a C++ implementation to compute the squared distances. This is much faster but requires compilation of the C++ code.
    cpp_aabb : gpytoolbox.squared_distance_precompute, optional (default None)
        Precomputed AABB tree built via `gpytoolbox.squared_distance_precompute(V, F)`.
        Only used when `use_cpp=True`. Reuses the tree across calls instead of
        rebuilding it, avoiding the O(n) construction cost on every query.

    Returns
    -------
    unsigned_distances : (p,) numpy double array
        Vector of minimum unsigned distances
    indices : (p,) numpy int array
        Indices into F (or V, if F is None) of closest elements to each query point
    lmbs : (p,s) numpy double array
        Barycentric coordinates into the closest element of each closest mesh point to each query point

    See Also
    --------
    squared_distance, squared_distance_precompute
    """
    # Step 1: Get squared distances
    dim = V.shape[1]
    if F is None:
        # Assume polyline
        assert dim==2
        F = edge_indices(V.shape[0],closed=True)
    sqrD, I, lmbd =  squared_distance(Q,V,F,use_cpp=use_cpp,use_aabb=True,cpp_aabb=cpp_aabb)

    # Step 2: Compute unsigned distance
    dist = np.sqrt(sqrD)

    return dist, I, lmbd