Skip to content

Commit 786e248

Browse files
author
Teseo Schneider
committed
added util for distance
1 parent 2b08a67 commit 786e248

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/SimpleBVH/BVH.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class BVH {
104104
if (nearest_facet < 0) {
105105
get_nearest_facet_hint(p, nearest_facet, nearest_point, sq_dist);
106106
}
107+
107108
facet_in_envelope_recursive(
108109
p, sq_epsilon, nearest_facet, nearest_point, sq_dist, 1, 0,
109110
n_corners);
@@ -119,6 +120,29 @@ class BVH {
119120
getPoint = callback;
120121
}
121122

123+
inline void point_facet_distance(
124+
const VectorMax3d& p,
125+
const int facet,
126+
VectorMax3d& closest_point,
127+
double& sq_d) const
128+
{
129+
const int f = new2old[facet];
130+
131+
if (faces.cols() == 2) {
132+
point_segment_squared_distance(
133+
p, { { vertices.row(faces(f, 0)), vertices.row(faces(f, 1)) } },
134+
closest_point, sq_d);
135+
return;
136+
} else if (faces.cols() == 3) {
137+
point_triangle_squared_distance(
138+
p,
139+
{ { vertices.row(faces(f, 0)), vertices.row(faces(f, 1)),
140+
vertices.row(faces(f, 2)) } },
141+
closest_point, sq_d);
142+
return;
143+
}
144+
}
145+
122146
private:
123147
void init_boxes_recursive(
124148
const std::vector<std::array<VectorMax3d, 2>>& cornerlist,

0 commit comments

Comments
 (0)