lab_inheritance
Insidious Inheritance
 All Classes Namespaces Files Functions Variables
Vector2 Class Reference

Represents a 2 dimensional vector. More...

#include <vector2.h>

Public Member Functions

 Vector2 ()
 Constructs a new Vector2 at (0, 0) More...
 
 Vector2 (double x, double y)
 Constructs a new Vector2 at (x, y) More...
 
Vector2 operator- (const Vector2 &other) const
 Subtracts two Vector2s and returns the value. More...
 
Vector2 operator+ (const Vector2 &other) const
 Adds two Vector2s together and returns the value. More...
 
Vector2 operator* (int constant)
 Multiples the current Vector2 by a scalar and returns a new Vector2 with its value. More...
 
Vector2 operator/ (int constant)
 Divides the current Vector2 by a scalar and returns a new Vector2 with its value. More...
 
bool operator== (const Vector2 &other) const
 Checks to see if the current Vector2 equals the other Vector2. More...
 
double x () const
 Gets the x coordinate of the Vector2. More...
 
void setX (double x)
 Sets the x coordinate of the Vector2. More...
 
double y () const
 Gets the y coordinate of the Vector2. More...
 
void setY (double y)
 Sets the y coordinate of the Vector2. More...
 
double distanceTo (const Vector2 &other) const
 Computes and returns the distance from the current Vector2 to the other Vector2. More...
 
bool isNorthOf (const Vector2 &other) const
 Checks if the current Vector2 is north of the other Vector2. More...
 
bool isNorthWestOf (const Vector2 &other) const
 Checks if the current Vector2 is north west of the other Vector2. More...
 
bool isNorthEastOf (const Vector2 &other) const
 Checks if the current Vector2 is north east of the other Vector2. More...
 
bool isSouthOf (const Vector2 &other) const
 Checks if the current Vector2 is south of the other Vector2. More...
 
bool isSouthWestOf (const Vector2 &other) const
 Checks if the current Vector2 is south west of the other Vector2. More...
 
bool isSouthEastOf (const Vector2 &other) const
 Checks if the current Vector2 is south east of the other Vector2. More...
 
bool isWestOf (const Vector2 &other) const
 Checks if the current Vector2 is west of the other Vector2. More...
 
bool isEastOf (const Vector2 &other) const
 Checks if the current Vector2 is east of the other Vector2. More...
 
double dotProduct (const Vector2 &other) const
 Computes and returns the dot product of the current Vector2 and other Vector2. More...
 
double crossProduct (const Vector2 &other) const
 Computes and returns the cross product of the current Vector2 and the other Vector2. More...
 
Vector2 projectionOn (const Vector2 &b) const
 Computes and returns the projection of the current Vector2 onto b. More...
 
double length () const
 Computes and returns the length of the Vector2 from the origin. More...
 
double length2 () const
 Computes and returns the length^2 of the Vector2 from the origin. More...
 
double magnitude () const
 Computes and returns the magnitude of the Vector2. More...
 
Vector2 normalize () const
 Computes and returns the normalized form of the current Vector2. More...
 
Vector2 leftHandNormal () const
 Computes and returns the left hand normal of the current Vector2. More...
 
Vector2 rightHandNormal () const
 Computes and returns the right hand normal of the current Vector2. More...
 

Private Attributes

double x_
 The X coordinate of this vector. More...
 
double y_
 The Y coordinate of this vector. More...
 

Detailed Description

Represents a 2 dimensional vector.

Constructor & Destructor Documentation

Vector2::Vector2 ( )

Constructs a new Vector2 at (0, 0)

Vector2::Vector2 ( double  x,
double  y 
)

Constructs a new Vector2 at (x, y)

Parameters
x
y

Member Function Documentation

double Vector2::crossProduct ( const Vector2 other) const

Computes and returns the cross product of the current Vector2 and the other Vector2.

Parameters
other
Returns
the cross product of the current Vector2 and the other Vector2
double Vector2::distanceTo ( const Vector2 other) const

Computes and returns the distance from the current Vector2 to the other Vector2.

Parameters
other
Returns
sqrt((this->x - other.x)^2 + (this-y - other.y)^2)
double Vector2::dotProduct ( const Vector2 other) const

Computes and returns the dot product of the current Vector2 and other Vector2.

Parameters
other
Returns
the dot product of the current Vector2 and the other Vector2
bool Vector2::isEastOf ( const Vector2 other) const

Checks if the current Vector2 is east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is east of the other Vector2
bool Vector2::isNorthEastOf ( const Vector2 other) const

Checks if the current Vector2 is north east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north east of the other Vector2
bool Vector2::isNorthOf ( const Vector2 other) const

Checks if the current Vector2 is north of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north of the other Vector2
bool Vector2::isNorthWestOf ( const Vector2 other) const

Checks if the current Vector2 is north west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is north west of the other Vector2
bool Vector2::isSouthEastOf ( const Vector2 other) const

Checks if the current Vector2 is south east of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south east of the other Vector2
bool Vector2::isSouthOf ( const Vector2 other) const

Checks if the current Vector2 is south of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south of the other Vector2
bool Vector2::isSouthWestOf ( const Vector2 other) const

Checks if the current Vector2 is south west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is south west of the other Vector2
bool Vector2::isWestOf ( const Vector2 other) const

Checks if the current Vector2 is west of the other Vector2.

Parameters
other
Returns
true if the current Vector2 is west of the other Vector2
Vector2 Vector2::leftHandNormal ( ) const

Computes and returns the left hand normal of the current Vector2.

Returns
the left hand normal of the current Vector2
double Vector2::length ( ) const

Computes and returns the length of the Vector2 from the origin.

Returns
the length of the Vector2 from the origin
double Vector2::length2 ( ) const

Computes and returns the length^2 of the Vector2 from the origin.

Returns
the length^2 of the Vector2 from the origin
double Vector2::magnitude ( ) const

Computes and returns the magnitude of the Vector2.

Note this is the same as length

Returns
the magnitude of the Vector2
Vector2 Vector2::normalize ( ) const

Computes and returns the normalized form of the current Vector2.

Returns
the normalized form of the current Vector2
Vector2 Vector2::operator* ( int  constant)

Multiples the current Vector2 by a scalar and returns a new Vector2 with its value.

Parameters
constantto multiply by
Returns
a new Vector2 that equals (x * constant, y * constant)
Vector2 Vector2::operator+ ( const Vector2 other) const

Adds two Vector2s together and returns the value.

Parameters
otherVector2 to add
Returns
a new Vector2 that equals *this + other
Vector2 Vector2::operator- ( const Vector2 other) const

Subtracts two Vector2s and returns the value.

Parameters
otherVector2 to subtract by
Returns
a new Vector2 that equals *this - other
Vector2 Vector2::operator/ ( int  constant)

Divides the current Vector2 by a scalar and returns a new Vector2 with its value.

Parameters
constantto divide by
Returns
a new Vector2 that equals (x / constant, y / constant)
bool Vector2::operator== ( const Vector2 other) const

Checks to see if the current Vector2 equals the other Vector2.

Parameters
otherVector2 to check
Returns
true if the current Vector2 equals the other Vector2
Vector2 Vector2::projectionOn ( const Vector2 b) const

Computes and returns the projection of the current Vector2 onto b.

Parameters
bVector2 to project onto
Returns
the Vector2 representing the projection of the current Vector2 onto b
Vector2 Vector2::rightHandNormal ( ) const

Computes and returns the right hand normal of the current Vector2.

Returns
the right hand normal of the current Vector2
void Vector2::setX ( double  x)

Sets the x coordinate of the Vector2.

Parameters
xthe new x coordinate of the Vector2
void Vector2::setY ( double  y)

Sets the y coordinate of the Vector2.

Parameters
ythe new y coordinate of the Vector2
double Vector2::x ( ) const

Gets the x coordinate of the Vector2.

Returns
the x coordinate of the Vector2
double Vector2::y ( ) const

Gets the y coordinate of the Vector2.

Returns
the y coordinate of the Vector2

Member Data Documentation

double Vector2::x_
private

The X coordinate of this vector.

double Vector2::y_
private

The Y coordinate of this vector.


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