A Utility Unit class for Angles.
The Length class aims to provide a better way to convert and store different units for angles. This way, when a function asks for a direction to turn to, any unit can be used to specify the angle. This makes it easier to write and tune autons as well as perform calculations, as you can use whatever unit is most comfortable.
The Default/Internal unit for Angles is radians, since all the trignometric functions included in <cmath> use radians by default. This makes calculations easier and allows for the Angle class to be used to easily specify direction for the Vec2 class.
Definition at line 274 of file Units.h.
| art::Angle::Angle |
( |
double | f | ) |
|
Construct a new Angle object.
- Parameters
-
| f | - a number(or Angle) to initialize m_value to |
This constructor is used similarly to the assignment operator. It can be used to construct an Angle to copy the value of another length without needing to convert to and from a specified unit. In order words, instead of a number, another Angle can be used and/or modified by treating it as a number.
The number(f) is in radians, which is also the default output when a Angle is used as a number.
Definition at line 143 of file Units.cpp.
| void art::Angle::constrain |
( |
| ) |
|
Constrains the Angle to the -180 to 180 range.
- Todo
- add seperate constrains for 0 to 360 and -180 to 180 (this one is -180 to 180)
Wraps the Angle around until it fits within a single circle. This preserves the direction, but prevents over-representing the value. This can be used in places to optimize turns and rotations, but is mostly just utility should you want to reduce an angle while preserving the absolute direction.
Definition at line 145 of file Units.cpp.
| art::Angle::operator double |
( |
| ) |
|
Returns the Angle as a default value(Radians)
- Returns
- double - the Angle as a default value(Radians)
This operator overload allows Angle to be treated as a plain old number. It can be typecasted to a double explicitly or just used in an expression. The value returned is technically in radians, but so long as the result is stored using Angle(double f) or Angle operator=(double const &f), as oppsosed to a Unit-specifying constructing function (Inches, Tiles, Meters etc.), it shouldn't be that important.
A Utility Unit class for Angles.
Angle Degrees(double degrees)
Constructs an Angle from Degrees.
Angle Revolutions(double revolutions)
Constructs an Angle from Revolutions.
Normal C++ order of operations applies, as each Angle is simply replaced by it's underlying value.
Definition at line 164 of file Units.cpp.
| Angle art::Angle::operator= |
( |
double const & | f | ) |
|
Assign a value to the Angle object.
- Parameters
-
| f | - a number(or Angle) to initialize m_value to |
- Returns
- Angle - The new modified Angle
This overloaded assignment operator allows the result of an operation using an Angle to be stored by another Angle.
Keep in mind this works best when the value on the right side is an Angle. Modifying the Angle with operators is okay, but keep in mind how those operations distribute.
As of right now, this number(f) is in radians, which is also the default output when a Angle is used as a number.
Definition at line 157 of file Units.cpp.