squared_distance
squared_distance(P, V, F=None, use_aabb=False)
Squared distances from a set of points in space.
General-purpose function which computes the squared distance from a set of points to a mesh, point cloud or polyline, in two or three dimensions. Optionally, uses an aabb tree for efficient computation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
P |
(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, default None)
|
Matrix of mesh/polyline/pointcloud indices into V. If None, input is assumed to be point cloud. |
None
|
use_aabb |
bool, optional (default False)
|
Whether to use an AABB tree for logarithmic computation |
False
|
Returns:
Name | Type | Description |
---|---|---|
squared_distances |
(p,) numpy double array
|
Vector of minimum squared 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_to_element, initialize_aabb.
Examples:
v,f = gpytoolbox.read_mesh("bunny.obj") # Read a mesh
v = gpytoolbox.normalize_points(v) # Normalize mesh
# Generate query points
P = 2*np.random.rand(num_samples,3)-4
# Compute distances
sqrD_gt,ind = gpytoolbox.squared_distance(P,v,F=f,use_aabb=True)
Source code in src/gpytoolbox/squared_distance.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|