blob: 2622926c32e4382554a79f693afa8b08749c26e4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#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);
}
|