15 #ifndef CORE_UTIL_MATH_H_
16 #define CORE_UTIL_MATH_H_
43 dist_array[0] = pos2[0] - pos1[0];
44 dist_array[1] = pos2[1] - pos1[1];
45 dist_array[2] = pos2[2] - pos1[2];
46 return dist_array.
Norm();
53 template <std::
size_t N>
57 result[0] = a[1] * b[2] - a[2] * b[1];
58 result[1] = a[2] * b[0] - a[0] * b[2];
59 result[2] = a[0] * b[1] - a[1] * b[0];
97 auto temp_1 = naxis * (vector * naxis);
98 auto temp_2 = (vector - temp_1) * std::cos(-theta);
99 auto temp_3 =
CrossProduct(vector, naxis) * std::sin(-theta);
101 return temp_1 + temp_2 + temp_3;
109 return std::acos(a * b / (a.
Norm() * b.
Norm()));
117 real_t k = (a * b) / (b * b);
123 const std::vector<real_t>& v2) {
124 if (v1.size() != v2.size()) {
125 Log::Fatal(
"Math::MSE",
"vectors must have same length");
128 for (
size_t i = 0; i < v1.size(); ++i) {
129 auto diff = v2[i] - v1[i];
130 error += diff * diff;
132 return error / v1.size();
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
void Normalize()
Normalize the array in-place.
static Real3 Perp3(const Real3 &a, real_t random)
static Real3 RotAroundAxis(const Real3 &vector, real_t theta, const Real3 &axis)
static real_t MSE(const std::vector< real_t > &v1, const std::vector< real_t > &v2)
Returns the mean squared error between two vectors.
static real_t GetL2Distance(const Real3 &pos1, const Real3 &pos2)
static MathArray< real_t, N > CrossProduct(const MathArray< real_t, N > &a, const MathArray< real_t, N > &b)
static real_t ToRadian(real_t deg)
static real_t ToDegree(real_t rad)
static real_t AngleRadian(const Real3 &a, const Real3 &b)
static constexpr real_t kInfinity
Helpful constant to identify 'infinity'.
static constexpr real_t kPi
value of pi
static Real3 ProjectionOnto(const Real3 &a, const Real3 &b)