diff options
author | Nao Pross <naopross@thearcway.org> | 2018-12-10 15:28:28 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-12-10 15:28:28 +0100 |
commit | b94064dec5c39f30cbf3ecad668f8e51cebcee7d (patch) | |
tree | 4c29159d92aa5f01eaa89d7693b3cf8c76d28242 /vector | |
parent | Update makefile ad update basic_vec to allow abstract algebraic structures (diff) | |
download | cplusplus-b94064dec5c39f30cbf3ecad668f8e51cebcee7d.tar.gz cplusplus-b94064dec5c39f30cbf3ecad668f8e51cebcee7d.zip |
Implement vec2<T>::polar() former vec2<T>::angle()
Diffstat (limited to 'vector')
-rw-r--r-- | vector/vector.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/vector/vector.cpp b/vector/vector.cpp index d5f0c36..8057cdd 100644 --- a/vector/vector.cpp +++ b/vector/vector.cpp @@ -1,10 +1,11 @@ #include <iostream> -#include <iterator> #include <cassert> +#include <cmath> + #include <array> -#include <initializer_list> #include <algorithm> +#include <initializer_list> template<typename T, std::size_t d> @@ -146,11 +147,16 @@ public: template<std::size_t n> vec2(const basic_vec<T, n>& other) : basic_vec<T, 2>(other) {} - T angle(); + T polar(); static vec3<T> cross(const vec2<T>& rhs, const vec2<T>& lhs); }; template<typename T> +T vec2<T>::polar() { + return std::atan2(this->at(0), this->at(1)); +} + +template<typename T> vec3<T> vec2<T>::cross(const vec2<T>& rhs, const vec2<T>& lhs) { return vec3<T>::cross(vec3<T>(rhs), vec3<T>(lhs)); } |