GPR5100 - Rollback
Loading...
Searching...
No Matches
angle.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <numbers>
7#include <cmath>
8
9namespace core
10{
11
12inline constexpr static float PI = std::numbers::pi_v<float>;
13class Degree;
19class Radian
20{
21public:
22 constexpr Radian() = default;
23 constexpr Radian(float value) : value_(value){}
28 constexpr Radian(const Degree& angle);
29 [[nodiscard]] constexpr float value() const { return value_; }
30
31 constexpr Radian operator+(Radian angle) const { return { value_ + angle.value() }; }
32 constexpr Radian& operator+=(Radian angle)
33 {
34 value_ += angle.value();
35 return *this;
36 }
37 constexpr Radian operator-(Radian angle) const { return { value_ - angle.value() }; }
38 constexpr Radian& operator-=(Radian angle)
39 {
40 value_ -= angle.value();
41 return *this;
42 }
43 constexpr Radian operator*(float value) const { return { value_ * value }; }
44 constexpr Radian operator/(float value) const { return { value_ / value }; }
45 constexpr Radian operator-() const { return { -value_ }; }
46private:
47 float value_ = 0.0f;
48};
49
55class Degree
56{
57public:
58 constexpr Degree() = default;
59 constexpr Degree(float value) : value_(value){}
64 constexpr Degree(const Radian& angle) : value_(angle.value()/PI*180.0f){}
65 [[nodiscard]] constexpr float value() const { return value_; }
66 constexpr Degree operator+(Degree angle) const { return { value_ + angle.value() }; }
67 constexpr Degree& operator+=(Degree angle)
68 {
69 value_ += angle.value();
70 return *this;
71 }
72 constexpr Degree operator-(Degree angle) const { return { value_ - angle.value() }; }
73 constexpr Degree& operator-=(Degree angle)
74 {
75 value_ -= angle.value();
76 return *this;
77 }
78 constexpr Degree operator*(float value) const { return { value_ * value }; }
79 constexpr Degree operator/(float value) const { return { value_ / value }; }
80 constexpr Degree operator-() const { return { -value_ }; }
81private:
82 float value_ = 0.0f;
83};
84
85constexpr Degree operator*(float value, Degree angle) { return angle.value() * value; }
86
87
88constexpr Radian::Radian(const Degree& angle)
89{
90 value_ = angle.value() / 180.0f * PI;
91}
92
98inline float Sin(Radian angle)
99{
100 return std::sin(angle.value());
101}
102
108inline float Cos(Radian angle)
109{
110 return std::cos(angle.value());
111}
112
118inline float Tan(Radian angle)
119{
120 return std::tan(angle.value());
121}
122
128inline Radian Asin(float ratio)
129{
130 return {std::asin(ratio)};
131}
132
138inline Radian Acos(float ratio)
139{
140 return {std::acos(ratio)};
141}
142
148inline Radian Atan(float ratio)
149{
150 return {std::atan(ratio)};
151}
152
159inline Radian Atan2(float y, float x)
160{
161 return {std::atan2(y,x)};
162}
163}
Radian Acos(float ratio)
Acos is a function that calculates the angle of a given ratio.
Definition: angle.h:138
float Tan(Radian angle)
Tan is a function that calculates the tangent of a given angle.
Definition: angle.h:118
Radian Atan(float ratio)
Atan is a function that calculates the angle of a given ratio.
Definition: angle.h:148
float Sin(Radian angle)
Sin is a function that calculates the sinus of a given angle.
Definition: angle.h:98
Radian Asin(float ratio)
Asin is a function that calculates the angle of a given ratio.
Definition: angle.h:128
float Cos(Radian angle)
Cos is a function that calculates the cosinus of a given angle.
Definition: angle.h:108
Radian Atan2(float y, float x)
Atan2 is a function that calculates the angle of a given ratio between two parameters.
Definition: angle.h:159
Degree is an utility class that describes degree angles (0 to 360). It can be easily converted to Rad...
Definition: angle.h:56
constexpr Degree(const Radian &angle)
Conversion constructor that implicitly converts Radian to Degree.
Definition: angle.h:64
Radian is an utility class that describes radian angles (0 to 2PI). It can be easily converted to Deg...
Definition: angle.h:20