78 const Eigen::MatrixBase<PointType>& point,
79 const Eigen::MatrixBase<PointType2>& V0,
80 const Eigen::MatrixBase<PointType2>& V1,
81 const Eigen::MatrixBase<PointType2>& V2,
82 Eigen::PlainObjectBase<PointType>& closest_point,
83 ScalarOf<PointType>& lambda0,
84 ScalarOf<PointType>& lambda1,
85 ScalarOf<PointType>& lambda2) -> ScalarOf<PointType>
87 using Scalar = ScalarOf<PointType>;
88 using DoublePointType =
89 Eigen::Matrix<double, PointType::RowsAtCompileTime, PointType::ColsAtCompileTime>;
94 double a00 = edge0.squaredNorm();
95 double a01 = edge0.dot(edge1);
96 double a11 = edge1.squaredNorm();
97 double b0 = diff.dot(edge0);
98 double b1 = diff.dot(edge1);
99 double c = diff.squaredNorm();
100 double det = std::fabs(a00 * a11 - a01 * a01);
101 double s = a01 * b1 - a11 * b0;
102 double t = a01 * b0 - a00 * b1;
108 PointType cur_closest;
113 closest_point = cur_closest;
118 if (cur_dist < result) {
120 closest_point = cur_closest;
126 if (cur_dist < result) {
128 closest_point = cur_closest;
143 sqr_distance = a00 + 2 * b0 + c;
146 sqr_distance = b0 * s + c;
153 }
else if (-b1 >= a11) {
155 sqr_distance = a11 + 2 * b1 + c;
158 sqr_distance = b1 * t + c;
166 }
else if (-b1 >= a11) {
168 sqr_distance = a11 + 2 * b1 + c;
171 sqr_distance = b1 * t + c;
179 }
else if (-b0 >= a00) {
181 sqr_distance = a00 + 2 * b0 + c;
184 sqr_distance = b0 * s + c;
188 double inv_det = double(1) / det;
191 sqr_distance = s * (a00 * s + a01 * t + 2 * b0) + t * (a01 * s + a11 * t + 2 * b1) + c;
194 double tmp0, tmp1, numer, denom;
201 denom = a00 - 2 * a01 + a11;
202 if (numer >= denom) {
205 sqr_distance = a00 + 2 * b0 + c;
210 s * (a00 * s + a01 * t + 2 * b0) + t * (a01 * s + a11 * t + 2 * b1) + c;
216 sqr_distance = a11 + 2 * b1 + c;
217 }
else if (b1 >= 0) {
222 sqr_distance = b1 * t + c;
230 denom = a00 - 2 * a01 + a11;
231 if (numer >= denom) {
234 sqr_distance = a11 + 2 * b1 + c;
239 s * (a00 * s + a01 * t + 2 * b0) + t * (a01 * s + a11 * t + 2 * b1) + c;
245 sqr_distance = a00 + 2 * b0 + c;
246 }
else if (b0 >= 0) {
251 sqr_distance = b0 * s + c;
255 numer = a11 + b1 - a01 - b0;
259 sqr_distance = a11 + 2 * b1 + c;
261 denom = a00 - 2 * a01 + a11;
262 if (numer >= denom) {
265 sqr_distance = a00 + 2 * b0 + c;
270 s * (a00 * s + a01 * t + 2 * b0) + t * (a01 * s + a11 * t + 2 * b1) + c;
277 if (sqr_distance < 0) {
282 lambda0 =
Scalar(1 - s - t);
285 return Scalar(sqr_distance);
SurfaceMesh< ToScalar, ToIndex > cast(const SurfaceMesh< FromScalar, FromIndex > &source_mesh, const AttributeFilter &convertible_attributes={}, std::vector< std::string > *converted_attributes_names=nullptr)
Cast a mesh to a mesh of different scalar and/or index type.
auto point_segment_squared_distance(const Eigen::MatrixBase< PointType > &point, const Eigen::MatrixBase< PointType2 > &V0, const Eigen::MatrixBase< PointType2 > &V1, Eigen::PlainObjectBase< PointType > &closest_point, ScalarOf< PointType > &lambda0, ScalarOf< PointType > &lambda1) -> ScalarOf< PointType >
Computes the point closest to a given point in a nd segment.
Definition point_segment_squared_distance.h:73
auto point_triangle_squared_distance(const Eigen::MatrixBase< PointType > &point, const Eigen::MatrixBase< PointType2 > &V0, const Eigen::MatrixBase< PointType2 > &V1, const Eigen::MatrixBase< PointType2 > &V2, Eigen::PlainObjectBase< PointType > &closest_point, ScalarOf< PointType > &lambda0, ScalarOf< PointType > &lambda1, ScalarOf< PointType > &lambda2) -> ScalarOf< PointType >
Computes the point closest to a given point in a nd triangle.
Definition point_triangle_squared_distance.h:77