ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
Loading...
Searching...
No Matches
art::Angle Class Reference

A Utility Unit class for Angles. More...

#include <Units.h>

Public Member Functions

double degrees ()
 Returns the Angle in degrees.
 
double radians ()
 Returns the Angle in radians.
 
double revolutions ()
 Returns the Angle in revolutions.
 
 Angle ()
 Construct a new Angle object.
 
 Angle (double f)
 Construct a new Angle object.
 
void constrain ()
 Constrains the Angle to the -180 to 180 range.
 
Angle operator= (double const &f)
 Assign a value to the Angle object.
 
 operator double ()
 Returns the Angle as a default value(Radians)
 

Private Attributes

double m_value {0.0}
 The underlying value of the Angle.
 

Friends

Angle Degrees (double degrees)
 Constructs an Angle from Degrees.
 
Angle Radians (double radians)
 Constructs an Angle from Radians.
 
Angle Revolutions (double revolutions)
 Constructs an Angle from Revolutions.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Angle() [1/2]

art::Angle::Angle ( )

Construct a new Angle object.

Initializes the value to 0.

Definition at line 141 of file Units.cpp.

◆ Angle() [2/2]

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.

Member Function Documentation

◆ constrain()

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.

◆ degrees()

double art::Angle::degrees ( )

Returns the Angle in degrees.

Returns
double - the Angle in degrees

Definition at line 170 of file Units.cpp.

◆ operator double()

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.

art::Angle angle = art::Degrees(5) * 5 + art::Revolutions(1); //stores an Angle of 385 (25+360) degrees
A Utility Unit class for Angles.
Definition Units.h:275
Angle Degrees(double degrees)
Constructs an Angle from Degrees.
Definition Units.cpp:120
Angle Revolutions(double revolutions)
Constructs an Angle from Revolutions.
Definition Units.cpp:134

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.

◆ operator=()

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.

art::Angle angle1 = art::Degrees(5) + 5; //stores an angle of ~ 291 inches(don't do this)
art::Angle angle2 = art::Degrees(5) + art::Degrees(5); //stores an angle of 10 degrees(do this instead)
art::Angle angle3 = art::Degrees(5 + 5); //stores an angle of 10 degrees(this is best)
art::Angle angle4 = art::Degrees(5) * 5; //stores an angle of 25 degrees

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.

◆ radians()

double art::Angle::radians ( )

Returns the Angle in radians.

Returns
double - the Angle in radians

Definition at line 176 of file Units.cpp.

◆ revolutions()

double art::Angle::revolutions ( )

Returns the Angle in revolutions.

Returns
double - the Angle in revolutions

Definition at line 182 of file Units.cpp.

Friends And Related Symbol Documentation

◆ Degrees

Angle Degrees ( double degrees)
friend

Constructs an Angle from Degrees.

Parameters
degreesthe angle in Degrees
Returns
Angle - the constructed Angle

Definition at line 120 of file Units.cpp.

◆ Radians

Angle Radians ( double radians)
friend

Constructs an Angle from Radians.

Parameters
radiansthe angle in Radians
Returns
Angle - the constructed Angle

Definition at line 127 of file Units.cpp.

◆ Revolutions

Angle Revolutions ( double revolutions)
friend

Constructs an Angle from Revolutions.

Parameters
revolutionsthe angle in Revolutions
Returns
Angle - the constructed Angle

Definition at line 134 of file Units.cpp.

Member Data Documentation

◆ m_value

double art::Angle::m_value {0.0}
private

The underlying value of the Angle.

Stores the Angle in Radians. This is what is returned and modified by some methods, but this is also converted to and from other units using the corresponding constructing function or get method.

Definition at line 405 of file Units.h.


The documentation for this class was generated from the following files: