50 const Eigen::MatrixBase<PointType>& U0,
51 const Eigen::MatrixBase<PointType>& U1,
52 const Eigen::MatrixBase<PointType>& V0,
53 const Eigen::MatrixBase<PointType>& V1,
54 Eigen::PlainObjectBase<PointType>& closest_pointU,
55 Eigen::PlainObjectBase<PointType>& closest_pointV,
56 ScalarOf<PointType>& lambdaU,
57 ScalarOf<PointType>& lambdaV) -> ScalarOf<PointType>
59 using Scalar = ScalarOf<PointType>;
60 using Vector =
typename PointType::PlainObject;
64 constexpr Scalar EPS = std::numeric_limits<Scalar>::epsilon();
67 constexpr bool is_lineU =
false;
68 constexpr bool is_lineV =
false;
73 Scalar a = d1.squaredNorm();
74 Scalar e = d2.squaredNorm();
78 if (std::abs(a) < EPS) {
79 if (std::abs(e) < EPS) {
81 lambdaU = lambdaV = 0;
84 return (closest_pointU - closest_pointV).dot(closest_pointU - closest_pointV);
90 if (!is_lineV) lambdaV = std::clamp(lambdaV, ZERO, ONE);
94 if (std::abs(e) < EPS) {
100 lambdaU = std::clamp(lambdaU, ZERO, ONE);
104 Scalar denom = a * e - b * b;
108 if (std::abs(denom) >= EPS) {
109 lambdaU = (b * f - c * e) / denom;
111 if (!is_lineU) lambdaU = std::clamp(lambdaU, ZERO, ONE);
117 lambdaV = (b * lambdaU + f) / e;
128 if (!is_lineU) lambdaU = std::clamp(lambdaU, ZERO, ONE);
129 }
else if (lambdaV > 1) {
131 lambdaU = (b - c) / a;
133 if (!is_lineU) lambdaU = std::clamp(lambdaU, ZERO, ONE);
139 closest_pointU = U0 + lambdaU * d1;
140 closest_pointV = V0 + lambdaV * d2;
141 return (closest_pointU - closest_pointV).squaredNorm();
auto segment_segment_squared_distance(const Eigen::MatrixBase< PointType > &U0, const Eigen::MatrixBase< PointType > &U1, const Eigen::MatrixBase< PointType > &V0, const Eigen::MatrixBase< PointType > &V1, Eigen::PlainObjectBase< PointType > &closest_pointU, Eigen::PlainObjectBase< PointType > &closest_pointV, ScalarOf< PointType > &lambdaU, ScalarOf< PointType > &lambdaV) -> ScalarOf< PointType >
Computes the squared distance between two N-d line segments, and the closest pair of points whose sep...
Definition segment_segment_squared_distance.h:49
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Type alias for one-dimensional column Eigen vectors.
Definition views.h:79