vector: add 2d cross product

This commit is contained in:
Danny Robson 2016-12-21 20:22:37 +11:00
parent fde9b281be
commit a7caea16e1
2 changed files with 15 additions and 0 deletions

View File

@ -41,6 +41,11 @@ namespace util {
vector<3,T>
cross (vector<3,T>, vector<3,T>);
template <typename T>
constexpr
T
cross (vector<2,T>, vector<2,T>);
// polar/cartesian conversions; assumes (mag, angle) form.
template <typename T> vector<2,T> polar_to_cartesian (vector<2,T>);
template <typename T> vector<2,T> cartesian_to_polar (vector<2,T>);

View File

@ -48,6 +48,16 @@ util::cross (util::vector<3,T> a, util::vector<3,T> b)
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr
T
util::cross (util::vector<2,T> a, util::vector<2,T> b)
{
return a[0] * b[1] - a[1] * b[0];
}
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
constexpr