summaryrefslogtreecommitdiff
path: root/common/math-vec2.hpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-24 02:04:43 -0400
committerGitHub <[email protected]>2021-09-24 02:04:43 -0400
commit2896b8a09ce42e965705c58593b8738adc454f7f (patch)
tree71e4d0cff60b5a1ad11427d78e1f8c7b775e5690 /common/math-vec2.hpp
parentMerge pull request #107 from a1xd/1.5.0-fix (diff)
parentmake note clearer (diff)
downloadrawaccel-1.6.0.tar.xz
rawaccel-1.6.0.zip
Merge pull request #108 from a1xd/1.6r2HEADv1.6.0masterdark-mode
v1.6
Diffstat (limited to 'common/math-vec2.hpp')
-rw-r--r--common/math-vec2.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/math-vec2.hpp b/common/math-vec2.hpp
new file mode 100644
index 0000000..f84c4c0
--- /dev/null
+++ b/common/math-vec2.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+template <typename T>
+struct vec2 {
+ T x;
+ T y;
+};
+
+using vec2d = vec2<double>;
+
+inline vec2d direction(double degrees)
+{
+ double radians = degrees * M_PI / 180;
+ return { cos(radians), sin(radians) };
+}
+
+constexpr vec2d rotate(const vec2d& v, const vec2d& direction)
+{
+ return {
+ v.x * direction.x - v.y * direction.y,
+ v.x * direction.y + v.y * direction.x
+ };
+}
+
+inline double magnitude(const vec2d& v)
+{
+ return sqrt(v.x * v.x + v.y * v.y);
+}
+
+
+inline double lp_distance(const vec2d& v, double p)
+{
+ return pow(pow(v.x, p) + pow(v.y, p), 1 / p);
+}