RIT VEXU Core API
Loading...
Searching...
No Matches
Vector2D Class Reference

#include <vector2d.h>

Public Member Functions

 Vector2D (double dir, double mag)
 
 Vector2D (point_t p)
 
double get_dir () const
 
double get_mag () const
 
double get_x () const
 
double get_y () const
 
Vector2D normalize ()
 
point_t point ()
 
Vector2D operator* (const double &x)
 
Vector2D operator+ (const Vector2D &other)
 
Vector2D operator- (const Vector2D &other)
 

Detailed Description

Vector2D is an x,y pair Used to represent 2D locations on the field. It can also be treated as a direction and magnitude

Constructor & Destructor Documentation

◆ Vector2D() [1/2]

Vector2D::Vector2D ( double dir,
double mag )

Construct a vector object.

Parameters
dirDirection, in radians. 'foward' is 0, clockwise positive when viewed from the top.
magMagnitude.

◆ Vector2D() [2/2]

Vector2D::Vector2D ( point_t p)

Construct a vector object from a cartesian point.

Parameters
ppoint_t.x , point_t.y

Member Function Documentation

◆ get_dir()

double Vector2D::get_dir ( ) const

Get the direction of the vector, in radians. '0' is forward, clockwise positive when viewed from the top.

Use r2d() to convert.

Returns
the direction of the vetctor in radians

Get the direction of the vector, in radians. '0' is forward, clockwise positive when viewed from the top.

Use r2d() to convert.

◆ get_mag()

double Vector2D::get_mag ( ) const
Returns
the magnitude of the vector

Get the magnitude of the vector

◆ get_x()

double Vector2D::get_x ( ) const
Returns
the X component of the vector; positive to the right.

Get the X component of the vector; positive to the right.

◆ get_y()

double Vector2D::get_y ( ) const
Returns
the Y component of the vector, positive forward.

Get the Y component of the vector, positive forward.

◆ normalize()

Vector2D Vector2D::normalize ( )

Changes the magnitude of the vector to 1

Returns
the normalized vector

Changes the magnetude of the vector to 1

◆ operator*()

Vector2D Vector2D::operator* ( const double & x)

Scales a Vector2D by a scalar with the * operator

Parameters
xthe value to scale the vector by
Returns
the this Vector2D scaled by x

◆ operator+()

Vector2D Vector2D::operator+ ( const Vector2D & other)

Add the components of two vectors together Vector2D + Vector2D = (this.x + other.x, this.y + other.y)

Parameters
otherthe vector to add to this
Returns
the sum of the vectors

◆ operator-()

Vector2D Vector2D::operator- ( const Vector2D & other)

Subtract the components of two vectors together Vector2D - Vector2D = (this.x - other.x, this.y - other.y)

Parameters
otherthe vector to subtract from this
Returns
the difference of the vectors

◆ point()

point_t Vector2D::point ( )

Returns a point from the vector

Returns
the point represented by the vector

Convert a direction and magnitude representation to an x, y representation

Returns
the x, y representation of the vector

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