MUDA
Loading...
Searching...
No Matches
point_point.inl
1namespace muda::distance
2{
3template <class T, int dim>
4MUDA_GENERIC void point_point_distance(const Eigen::Vector<T, dim>& a,
5 const Eigen::Vector<T, dim>& b,
6 T& dist2)
7{
8 dist2 = (a - b).squaredNorm();
9}
10
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)
15{
16 grad.template segment<dim>(0) = 2.0 * (a - b);
17 grad.template segment<dim>(dim) = -grad.template segment<dim>(0);
18}
19
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)
24{
25 Hessian.setZero();
26 Hessian.diagonal().setConstant(2.0);
27 if constexpr(dim == 2)
28 {
29 Hessian(0, 2) = Hessian(1, 3) = Hessian(2, 0) = Hessian(3, 1) = -2.0;
30 }
31 else
32 {
33 Hessian(0, 3) = Hessian(1, 4) = Hessian(2, 5) = Hessian(3, 0) =
34 Hessian(4, 1) = Hessian(5, 2) = -2.0;
35 }
36}
37
38} // namespace muda::distance