Thunderbots Project
Loading...
Searching...
No Matches
Vector Class Referencefinal

#include <vector.h>

Public Member Functions

 Vector ()
 
 Vector (double x, double y)
 
 Vector (const Vector &v)
 
double x () const
 
double y () const
 
void set (double x, double y)
 
void setX (double x)
 
void setY (double y)
 
double lengthSquared () const
 
double length () const
 
Vector normalize () const
 
Vector normalize (double length) const
 
Vector perpendicular () const
 
Vector rotate (const Angle &rot) const
 
Vector project (const Vector &other) const
 
double dot (const Vector &other) const
 
double cross (const Vector &other) const
 
double determinant (const Vector &other) const
 
Angle orientation () const
 
Vectoroperator= (const Vector &other)
 
bool isClockwiseOf (const Vector &other) const
 
bool isCounterClockwiseOf (const Vector &other) const
 

Static Public Member Functions

static Vector createFromAngle (const Angle &angle)
 

Detailed Description

A vector in 2D space.

Constructor & Destructor Documentation

◆ Vector() [1/3]

Vector ( )
explicit

Creates a zero-vector.

◆ Vector() [2/3]

Vector ( double  x,
double  y 
)

Creates a Vector with arbitrary x and y values.

Parameters
xthe x value of the Vector
ythe y value of the Vector

◆ Vector() [3/3]

Vector ( const Vector v)

Creates a new Vector that is a copy of the given Vector

Parameters
theVector to duplicate

Member Function Documentation

◆ createFromAngle()

Vector createFromAngle ( const Angle angle)
static

Creates a unit-magnitude Vector from an angle.

Parameters
anglethe angle
Returns
Vector the Vector

◆ cross()

double cross ( const Vector other) const

Takes the cross product of two vectors

Parameters
otherthe Vector to cross with
Returns
the z component of the 3-dimensional cross product between this Vector and the other Vector

◆ determinant()

double determinant ( const Vector other) const

Calculates the determinant of a 2x2 matrix

Parameters
otherVector forming the bottom row of the matrix
Returns
the determinant with rows from the specified vectors

◆ dot()

double dot ( const Vector other) const

Takes the dot product of two vectors

Parameters
otherthe Vector to dot against
Returns
the dot product of the vectors

◆ isClockwiseOf()

bool isClockwiseOf ( const Vector other) const

Returns true if this vector is to the right of the given vector. Geometrically, in the acute angle given by two vectors, it returns true if this vector is clockwise of the other vector.

Parameters
otherthe Vector to compare this Vector to

◆ isCounterClockwiseOf()

bool isCounterClockwiseOf ( const Vector other) const

In the acute angle given by the two vectors, this function returns true if this vector is counterclockwise of the other vector.

Parameters
otherthe Vector to compare this Vector to

◆ length()

double length ( ) const

Returns the length of the Vector

Returns
the length of the Vector

◆ lengthSquared()

double lengthSquared ( ) const

Returns the square of the length of the Vector

Returns
the square of the length of the Vector

◆ normalize() [1/2]

Vector normalize ( ) const

Returns this Vector as a unit vector in the same direction

Returns
Vector a unit vector in the same direction as this Vector, or a zero-vector if this Vector is a zero-vector

◆ normalize() [2/2]

Vector normalize ( double  length) const

Returns a scaled normalized vector in the same direction as this Vector

Parameters
lengththe desired length of the resultant vector
Returns
a vector in the same direction as this Vector and with the given length, or a zero-vector if this Vector is a zero-vector

◆ operator=()

Vector & operator= ( const Vector other)

Assigns one Vector to another

Parameters
otherthe Vector whose x and y magnitudes should be copied into this Vector
Returns
this Vector

◆ orientation()

Angle orientation ( ) const

Returns the direction of this Vector

Returns
the direction of this Vector, in the range [-π, π], with 0 being the positive x direction, π/2 being up (positive y), etc. like on a standard x-y plane
         +
         | Y
         |
         |
 +---------------+
  -X     |      X
         |
         | -Y
         +

◆ perpendicular()

Vector perpendicular ( ) const

Returns the vector perpendicular to this Vector (rotated +90 degrees from the original vector)

Returns
a vector perpendicular to this Vector

◆ project()

Vector project ( const Vector other) const

Projects this vector onto the line formed by another vector

Parameters
thevector to project onto
Returns
the projection of this vector onto the line formed by the given Vector

◆ rotate()

Vector rotate ( const Angle rot) const

Rotates this Vector counterclockwise by an angle

Parameters
rotthe angle to rotate the vector
Returns
the Vector rotated by rot

◆ set()

void set ( double  x,
double  y 
)

Sets the magnitudes of this vector to the new magnitudes

Parameters
xthe new magnitude in the x-coordinate
ythe new magnitude in the y-coordinate

◆ setX()

void setX ( double  x)

Sets the magnitude in the x-coordinate of this vector

Parameters
xthe new x-coordinate magnitude

◆ setY()

void setY ( double  y)

Sets the magnitude in the y-coordinate of this vector

Parameters
ythe new y-coordinate magnitude

◆ x()

double x ( ) const

Returns the magnitude in the x-coordinate of this Vector

Returns
the magnitude in the x-coordinate of this Vector

◆ y()

double y ( ) const

Returns the magnitude in the y-coordinate of this Vector

Returns
the magnitude in the y-coordinate of this Vector

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