1namespace muda::distance
3template <
class T,
int dim>
4MUDA_GENERIC
void point_point_distance(
const Eigen::Vector<T, dim>& a,
5 const Eigen::Vector<T, dim>& b,
8 dist2 = (a - b).squaredNorm();
11template <
class T,
int dim>
12MUDA_GENERIC
void point_point_distance_gradient(
const Eigen::Vector<T, dim>& a,
13 const Eigen::Vector<T, dim>& b,
14 Eigen::Vector<T, dim * 2>& grad)
16 grad.template segment<dim>(0) = 2.0 * (a - b);
17 grad.template segment<dim>(dim) = -grad.template segment<dim>(0);
20template <
class T,
int dim>
21MUDA_GENERIC
void point_point_distance_hessian(
const Eigen::Vector<T, dim>& a,
22 const Eigen::Vector<T, dim>& b,
23 Eigen::Matrix<T, dim * 2, dim * 2>& Hessian)
26 Hessian.diagonal().setConstant(2.0);
27 if constexpr(dim == 2)
29 Hessian(0, 2) = Hessian(1, 3) = Hessian(2, 0) = Hessian(3, 1) = -2.0;
33 Hessian(0, 3) = Hessian(1, 4) = Hessian(2, 5) = Hessian(3, 0) =
34 Hessian(4, 1) = Hessian(5, 2) = -2.0;