LinearAlgebra
Loading...
Searching...
No Matches
Angle.h
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0.If a copy of the MPL was not distributed with this
3// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
4
5#ifndef ANGLE_H
6#define ANGLE_H
7
8namespace Passer {
9namespace LinearAlgebra {
10
11static float pi = 3.1415927410125732421875F;
12
13static float Rad2Deg = 360.0f / (pi * 2);
14static float Deg2Rad = (pi * 2) / 360.0f;
15
21template <typename T> class AngleOf {
22public:
24 AngleOf<T>();
25
27 const static AngleOf<T> zero;
28 // const static AngleOf<T> deg90;
29 // const static AngleOf<T> deg180;
30
34 static AngleOf<T> Degrees(float degrees);
38 static AngleOf<T> Radians(float radians);
39
44
47 float InDegrees() const;
50 float InRadians() const;
51
54 T GetBinary() const;
57 void SetBinary(T rawValue);
58
64 bool operator==(const AngleOf<T> angle) const;
69 bool operator>(AngleOf<T> angle) const;
74 bool operator>=(AngleOf<T> angle) const;
79 bool operator<(AngleOf<T> angle) const;
84 bool operator<=(AngleOf<T> angle) const;
85
90 static signed int Sign(AngleOf<T> angle);
95 static AngleOf<T> Abs(AngleOf<T> angle);
96
99 AngleOf<T> operator-() const;
103 AngleOf<T> operator-(const AngleOf<T> &angle) const;
107 AngleOf<T> operator+(const AngleOf<T> &angle) const;
111 AngleOf<T> operator+=(const AngleOf<T> &angle);
112
117 friend AngleOf<T> operator*(const AngleOf<T> &angle, float factor) {
118 return AngleOf::Degrees((float)angle.InDegrees() * factor);
119 }
124 friend AngleOf<T> operator*(float factor, const AngleOf<T> &angle) {
125 return AngleOf::Degrees((float)factor * angle.InDegrees());
126 }
127
130 void Normalize();
134 static AngleOf<T> Normalize(AngleOf<T> angle);
143 // static AngleOf<T> Difference(AngleOf<T> a, AngleOf<T> b) {
144 // AngleOf<T> r = Normalize(b.InDegrees() - a.InDegrees());
145 // return r;
146 // };
147
154 float maxAngle);
155
159 static float Cos(AngleOf<T> angle);
163 static float Sin(AngleOf<T> angle);
167 static float Tan(AngleOf<T> angle);
168
172 static AngleOf<T> Acos(float f);
176 static AngleOf<T> Asin(float f);
180 static AngleOf<T> Atan(float f);
186 static AngleOf<T> Atan2(float y, float x);
187
193 static float CosineRuleSide(float a, float b, AngleOf<T> gamma);
199 static AngleOf<T> CosineRuleAngle(float a, float b, float c);
200
206 static AngleOf<T> SineRuleAngle(float a, AngleOf<T> beta, float c);
207
208private:
209 T value;
210
212};
213
217
218} // namespace LinearAlgebra
219} // namespace Passer
220using namespace Passer::LinearAlgebra;
221
222#endif
An angle in various representations.
Definition Angle.h:21
AngleOf< T > operator-() const
Negate the angle.
Definition Angle.cpp:69
static float Cos(AngleOf< T > angle)
Calculates the cosine of an angle.
Definition Angle.cpp:166
static const AngleOf< T > zero
An zero value angle.
Definition Angle.h:27
static AngleOf< T > SineRuleAngle(float a, AngleOf< T > beta, float c)
Computes the angle of a corner using the rule of sines.
Definition Angle.cpp:264
static float Tan(AngleOf< T > angle)
Calculates the tangent of an angle.
Definition Angle.cpp:172
bool operator<(AngleOf< T > angle) const
Tests if this angle is less than the given angle.
Definition Angle.cpp:44
static AngleOf< T > Radians(float radians)
Creates an angle in radians.
float InDegrees() const
Get the angle value in degrees.
T GetBinary() const
Get the raw value for the angle.
Definition Angle.cpp:26
static AngleOf< T > Atan(float f)
Calculates the arc tangent angle.
Definition Angle.cpp:182
static AngleOf< T > CosineRuleAngle(float a, float b, float c)
Computes the angle of a corner using the rule of cosines.
Definition Angle.cpp:239
void SetBinary(T rawValue)
Set the raw value of the angle.
Definition Angle.cpp:27
AngleOf()
Create a new angle with a zero value.
Definition Angle.cpp:14
friend AngleOf< T > operator*(float factor, const AngleOf< T > &angle)
Multiplies the angle.
Definition Angle.h:124
static AngleOf< T > MoveTowards(AngleOf< T > fromAngle, AngleOf< T > toAngle, float maxAngle)
Rotates an angle towards another angle with a max distance.
Definition Angle.cpp:154
bool operator<=(AngleOf< T > angle) const
Tests if this angle is less than or equal to the given angle.
Definition Angle.cpp:48
void Normalize()
Normalizes the angle to (-180..180] or (-PI..PI] Should not be needed but available in case it is.
Definition Angle.cpp:123
bool operator>=(AngleOf< T > angle) const
Tests if this angle is greater than or equal to the given angle.
Definition Angle.cpp:40
static AngleOf< T > Degrees(float degrees)
Creates an angle in degrees.
static AngleOf< T > Abs(AngleOf< T > angle)
Returns the magnitude of the angle.
Definition Angle.cpp:62
static AngleOf< T > Binary(T rawValue)
Creates an angle from a raw value.
Definition Angle.cpp:20
float InRadians() const
Get the angle value in radians.
static AngleOf< T > Asin(float f)
Calculates the arc sine angle.
Definition Angle.cpp:179
AngleOf< T > operator+=(const AngleOf< T > &angle)
Add another angle to this angle.
Definition Angle.cpp:106
static signed int Sign(AngleOf< T > angle)
Returns the sign of the angle.
Definition Angle.cpp:53
friend AngleOf< T > operator*(const AngleOf< T > &angle, float factor)
Mutliplies the angle.
Definition Angle.h:117
bool operator==(const AngleOf< T > angle) const
Tests whether this angle is equal to the given angle.
Definition Angle.cpp:32
static AngleOf< T > Acos(float f)
Calculates the arc cosine angle.
Definition Angle.cpp:176
bool operator>(AngleOf< T > angle) const
Tests if this angle is greater than the given angle.
Definition Angle.cpp:36
static float CosineRuleSide(float a, float b, AngleOf< T > gamma)
Computes the length of a side using the rule of cosines.
Definition Angle.cpp:209
static AngleOf< T > Atan2(float y, float x)
Calculates the tangent for the given values.
Definition Angle.cpp:187
AngleOf< T > operator+(const AngleOf< T > &angle) const
Add another angle from this angle.
Definition Angle.cpp:93
static AngleOf< T > Clamp(AngleOf< T > angle, AngleOf< T > min, AngleOf< T > max)
Clamps the angle value between the two given angles.
Definition Angle.cpp:148
static float Sin(AngleOf< T > angle)
Calculates the sine of an angle.
Definition Angle.cpp:169