52#include <lagrange/common.h>
72template <
typename Po
intType>
74 const Eigen::MatrixBase<PointType>& point,
75 const Eigen::MatrixBase<PointType>& V0,
76 const Eigen::MatrixBase<PointType>& V1,
77 Eigen::PlainObjectBase<PointType>& closest_point,
78 ScalarOf<PointType>& lambda0,
79 ScalarOf<PointType>& lambda1) -> ScalarOf<PointType>
81 using Scalar = ScalarOf<PointType>;
83 auto l2 = (V0 - V1).squaredNorm();
84 auto t = (point - V0).dot(V1 - V0);
85 if (t <= Scalar(0) || l2 == Scalar(0)) {
89 return (point - V0).squaredNorm();
94 return (point - V1).squaredNorm();
97 lambda0 = Scalar(1) - lambda1;
98 closest_point = lambda0 * V0 + lambda1 * V1;
99 return (point - closest_point).squaredNorm();
113template <
typename Po
intType>
115 const Eigen::MatrixBase<PointType>& point,
116 const Eigen::MatrixBase<PointType>& V0,
117 const Eigen::MatrixBase<PointType>& V1) -> ScalarOf<PointType>
119 PointType closest_point;
120 ScalarOf<PointType> lambda0;
121 ScalarOf<PointType> lambda1;
Main namespace for Lagrange.
Definition: AABBIGL.h:30
auto point_segment_squared_distance(const Eigen::MatrixBase< PointType > &point, const Eigen::MatrixBase< PointType > &V0, const Eigen::MatrixBase< PointType > &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