1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#pragma once #include <eigen3/Eigen/Dense> template <class T, int D> using Vector = Eigen::Matrix<T, D, 1>; template <class T, int D> Vector<T, D> diff(T L, Vector<T, D> v1, Vector<T, D> v2) { Vector<T, D> v; for (unsigned i = 0; i < D; i++) { v(i) = std::abs(v1(i) - v2(i)); if (v(i) > L / 2) { v(i) = L - v(i); } } return v; }