vector: add spherical canonicalisation function

This commit is contained in:
Danny Robson 2018-01-17 17:44:59 +11:00
parent a8b6184e65
commit 51ffcbb07e

View File

@ -20,6 +20,7 @@
#include "./coord/fwd.hpp"
#include "./coord.hpp"
#include "maths.hpp"
#include "json/fwd.hpp"
#include <cstddef>
@ -84,6 +85,26 @@ namespace util {
};
}
template <typename T>
constexpr vector<3,T>
canonical_spherical (vector<3,T> s)
{
if (s.x < 0) {
s.x = -s.x;
s.y += util::PI<T>;
}
if (s.y < 0) {
s.y = -s.y;
s.z += util::PI<T>;
}
s.y = std::fmod (s.y, util::PI<T>);
s.z = std::fmod (s.z, util::PI<T>);
return s;
}
template <typename T> vector<2,T> to_euler (vector<3,T>);
template <typename T> vector<3,T> from_euler (vector<2,T>);