summaryrefslogtreecommitdiff
path: root/include/llmr/util/math.hpp
blob: 8ea4a6b7925efd3febc5d877507180274f29b280 (plain)
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
#ifndef LLMR_UTIL_MATH
#define LLMR_UTIL_MATH

#include <cmath>

#include "vec.hpp"

namespace llmr {
namespace util {

inline double angle_between(double ax, double ay, double bx, double by) {
    return atan2((ax * by - ay * bx), ax * bx + ay * by);
}

template <typename T, typename S1, typename S2>
inline vec2<T> normal(const S1& a, const S2& b) {
    T dx = b.x - a.x;
    T dy = b.y - a.y;
    T c = sqrt(dx * dx + dy * dy);
    return { dx / c, dy / c };
}

template <typename T, typename S1, typename S2>
inline T dist(const S1& a, const S2& b) {
    T dx = b.x - a.x;
    T dy = b.y - a.y;
    T c = sqrt(dx * dx + dy * dy);
    return c;
};

}
}

#endif