|
ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
|
A Utility 2D Vector class. More...
#include <Vec2.h>
Public Member Functions | |
| Vec2 () | |
| Construct a new Vec 2 object. | |
| double | magnitude () const |
| Gets the magnitude of the Vector. | |
| double | direction () const |
| Gets the direction of the Vector. | |
| Vec2 | normalize () const |
| Returns a unit Vector with the same direction. | |
| double | distTo (Vec2 target) const |
| Gets the distance from this vector to another. | |
| double | angleTo (Vec2 target) const |
| Gets the angle from this vector to another. | |
| Vec2 | operator+ (Vec2 const &obj) const |
| Returns the sum of 2 vectors. | |
| Vec2 | operator- (Vec2 const &obj) const |
| Returns the difference of 2 vectors. | |
| Vec2 | operator* (double const &scale) const |
| Returns a vector after scaling it. | |
| double | operator* (Vec2 const &other) const |
| Returns the Dot Product of 2 vectors. | |
| Vec2 & | operator+= (Vec2 const &obj) |
| Adds another vector to this one. | |
| Vec2 & | operator-= (Vec2 const &obj) |
| Substracts another vector from this one. | |
| Vec2 & | operator*= (double const &scale) |
| Changes the vector by a scale. | |
Static Public Member Functions | |
| static Vec2 | XandY (double x, double y) |
| Constructs a vector with the specified x and y components. | |
| static Vec2 | dirAndMag (double dir, double mag) |
| Constructs a vector with the specified direction and magnitude. | |
Public Attributes | |
| double | x |
| Stores the X component of the Vector. | |
| double | y |
| Stores the Y component of the Vector. | |
A Utility 2D Vector class.
The Vec2 class aims to provide a better way to store coordinates, travel and displacement in a 2d space. Vec2 objects store thier x and y components, but has methods to access thier direction and magnitude as well. Vectors can be added together, scaled or multiplied by each other to find the dot product.
The components' units can be whatever you want, but the direction will always be in radians, as the math works best that way. The Angle Unit Utility Class defaults to Radians as a result, but as of right now, using the Angle class is optional.
| art::Vec2::Vec2 | ( | ) |
| double art::Vec2::angleTo | ( | Vec2 | target | ) | const |
Gets the angle from this vector to another.
| target | the vector to find the angle too |
Finds the angle(in radians) of the difference of 2 vectors. In practice, this is most often used to find the angle connecting 2 points. This method simply returns the angle after finding the difference between the two vectors, so if you want both the direction and magnitude, you can simply store the difference between the vectors:
Both ending and starting are Vec2s as well.
|
static |
Constructs a vector with the specified direction and magnitude.
| dir | the direction of the vector(in radians) |
| mag | the magnitude of the vector |
One of 2 construction functions within the Vec2 class. If you want to create a new vector with a specified direction(in radians) and magnitude, you will need to call this by using the accessor operator(::) and store the returned value.
Understanding directions using radians can be somewhat strange if you're not already familiar. The Angle Unit class can help by converting degrees or revolutions to radians.
| double art::Vec2::direction | ( | ) | const |
| double art::Vec2::distTo | ( | Vec2 | target | ) | const |
Gets the distance from this vector to another.
| target | the vector to find the distance too |
Finds the magnitude of the difference of 2 vectors. In practice, this is most often used to find the distance between 2 points. This method simply returns the magnitude after finding the difference between the two vectors, so if you want both the direction and magnitude, you can simply store the difference between the vectors:
Both ending and starting are Vec2s as well.
| double art::Vec2::magnitude | ( | ) | const |
| Vec2 art::Vec2::normalize | ( | ) | const |
Returns a unit Vector with the same direction.
The process of normalization divides a vector by it's magnitude, resulting in a vector with a magnitude of 1 unit. This vector preserves the original direction, so it can be useful for other calculations or simply to change the scale of a vector.
| Vec2 art::Vec2::operator* | ( | double const & | scale | ) | const |
Returns a vector after scaling it.
| scale | the number to scale by |
Functionally, this just multiplies the components by the scale. The vector used in this operation ins't modified, so it retains its original values. The result must be stored or used immediately.
| double art::Vec2::operator* | ( | Vec2 const & | other | ) | const |
Returns the Dot Product of 2 vectors.
| other | the other vector to calculate using |
The Dot Product doesn't have that many use-cases, but it has use in some more calculations for more complex things. For example in physics, it is used to calculate work by using the vectors of the force and distance travelled.
Neither of the vectors used in this operation are modified, they retain thier original values.
| Vec2 & art::Vec2::operator*= | ( | double const & | scale | ) |
Returns the difference of 2 vectors.
| obj | the other vector to subtract |
Functionally, this just flips the second vector and takes the sum. Neither of the vectors used in this operation are modified, they retain thier original values. The result must be stored or used immediately.
|
static |
Constructs a vector with the specified x and y components.
| x | the x component of the vector |
| y | the y component of the vector |
One of 2 construction functions within the Vec2 class. If you want to create a new vector with a specified x and y, you will need to call this by using the accessor operator(::) and store the returned value.
| double art::Vec2::x |
| double art::Vec2::y |