squared_distance
squared_distance(P, V, F=None, use_cpp=False, use_aabb=False, C=None, W=None, CH=None, tri_ind=None, split_dir=None)
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
|
Matrix of mesh/polyline/pointcloud indices into V. If None, input is assumed to be point cloud. |
None)
|
use_cpp |
bool, optional (default False)
|
Whether to use the C++ libigl implementation of the AABB tree (much faster). If True, the following parameters are ignored. |
False
|
use_aabb |
bool, optional (default False)
|
Whether to use an AABB tree for logarithmic computation |
False
|
C |
numpy double array, optional (default None)
|
Matrix of AABB box centers (if None, will be computed) |
None
|
W |
numpy double array, optional (default None)
|
Matrix of AABB box widths (if None, will be computed) |
None
|
CH |
numpy int array, optional (default None)
|
Matrix of child indeces (-1 if leaf node). If None, will be computed |
None
|
tri_indices |
numpy int array, optional (default None)
|
Vector of AABB element indices (-1 if not leaf node). If None, will be computed |
required |
split_dir |
numpy double array, optional (default None)
|
Vector of AABB split directions (if None, will be computed) |
None
|
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,b = gpytoolbox.squared_distance(P,v,F=f,use_aabb=True)
Source code in src/gpytoolbox/squared_distance.py
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|