UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ugdk::math::Vector2D Class Reference

#include <ugdk/math/vector2D.h>

Public Member Functions

 Vector2D ()
 Initializes both fields with 0.0. More...
 
 Vector2D (double value)
 Initializes both fields with val. More...
 
 Vector2D (double _x, double _y)
 Initializes both fields with given values. More...
 
 Vector2D (const math::Integer2D &int2d)
 Copy constructor from Integer2D. More...
 
 ~Vector2D ()
 
double get_x () const
 
double get_y () const
 
void set_x (double x_)
 
void set_y (double y_)
 
double NormOne () const
 Returns the norm-1 of this vector. More...
 
double Length () const
 Returns the norm-2 of this vector. More...
 
double LengthSquared () const
 Returns the norm-2 squared. More...
 
double Angle () const
 Returns the angle (in radians) of this vector. More...
 
Vector2D Normalize () const
 Returns a new vector equal to this vector normalized. More...
 
Vector2D Rotate (double angle) const
 Returns a new vector equal to this vector rotated by "angle" (in radians) counter-clockwise. More...
 
void Mirror (const ugdk::enums::mirroraxis::MirrorAxis axis)
 Mirrors this Vector2D (in-place) by the "axis" axis. Include types.h and use "using namespace ugdk::enums". More...
 
Vector2D Mirrored (const ugdk::enums::mirroraxis::MirrorAxis axis) const
 Returns a new Vector2D, mirrored by the "axis" axis. Include types.h and use "using namespace ugdk::enums". More...
 
Vector2D Scale (const Vector2D &scale) const
 Returns a new vector which is this vector scaled coordinate by coordinate with "scale". More...
 
void Divide (const Vector2D &divider)
 In-place integer division, coordinate by coordinate. More...
 
Vector2D Divided (const Vector2D &divider) const
 Returns a new Integer2D equal to this divided coordinate by coordinate by "multiplier". More...
 
double length () const
 Deprecated. Use the upper case method. More...
 
double angle () const
 Deprecated. Use the upper case method. More...
 
bool operator== (const Vector2D &rhs)
 Compares this vector to the given vector, return True if they are equivalent. More...
 
Vector2Doperator+= (const Vector2D &other)
 
Vector2Doperator-= (const Vector2D &other)
 
Vector2Doperator*= (double other)
 
Vector2D operator+ (const Vector2D &right) const
 Method that returns a vector equal to the sum of two others. More...
 
Vector2D operator- () const
 Method that returns a vector equal to the oposite of another. More...
 
Vector2D operator- (const Vector2D &right) const
 Method that returns a vector equal to the subtraction of two others. More...
 
Vector2D operator* (double scalar) const
 Method that returns a vector equal to the a vector multiplied by a scalar. More...
 
Vector2D operator/ (double scalar) const
 Method that returns a vector equal to the a vector multiplied by the inverse of a scalar. More...
 
double operator* (const Vector2D &right) const
 Method that returns a scalar equal to the inner product of two vectors. More...
 
 operator std::array< double, 2 > () const
 
 operator std::pair< double, double > () const
 

Static Public Member Functions

static Vector2D Add (const Vector2D &a, const Vector2D &b)
 Static method that returns a vector equal to the sum of two others. More...
 
static Vector2D Subtract (const Vector2D &a, const Vector2D &b)
 Static method that returns a vector equal to the subtraction of two others. More...
 
static Vector2D Multiply (const Vector2D &a, double scalar)
 Static method that returns a vector equal to the a vector multiplied by a scalar. More...
 
static double InnerProduct (const Vector2D &a, const Vector2D &b)
 Static method that returns a scalar equal to the inner product of two vectors. More...
 
static Vector2D Normalized (Vector2D &a)
 Deprecated. Use the method function Normalize. More...
 
static Vector2D Rotate (Vector2D &a, double angle)
 Deprecated. Use the method function Rotate. More...
 

Public Attributes

union {
   struct {
      double   x
 
      double   y
 
   } 
 
   struct {
      double   val [2]
 
   } 
 
}; 
 

Constructor & Destructor Documentation

ugdk::math::Vector2D::Vector2D ( )
inline

Initializes both fields with 0.0.

Create the vector (x,y) with x = 0 and y =0

ugdk::math::Vector2D::Vector2D ( double  value)
inlineexplicit

Initializes both fields with val.

Create the vector (x,y) with x = val and y = val being val a constant

Parameters
valis a constant
ugdk::math::Vector2D::Vector2D ( double  _x,
double  _y 
)
inline

Initializes both fields with given values.

Create the vector (x,y) with x = x-value and y = y-value

Parameters
xis the x-value argument
yis the y-value argument
ugdk::math::Vector2D::Vector2D ( const math::Integer2D int2d)

Copy constructor from Integer2D.

ugdk::math::Vector2D::~Vector2D ( )
inline

Member Function Documentation

static Vector2D ugdk::math::Vector2D::Add ( const Vector2D a,
const Vector2D b 
)
inlinestatic

Static method that returns a vector equal to the sum of two others.

The sum of two vectors (x,y) (w,z) is igual to the vector (x+w, y+z)

Returns
Sum Vector
double ugdk::math::Vector2D::Angle ( ) const

Returns the angle (in radians) of this vector.

Return the angle (in radians) associated to this vector

Returns
Angle
double ugdk::math::Vector2D::angle ( ) const
inline

Deprecated. Use the upper case method.

Depprecated method that returns the angle associated to a vector (x,y). Use instead Angle()

Returns
angle
See also
Angle()
void ugdk::math::Vector2D::Divide ( const Vector2D divider)

In-place integer division, coordinate by coordinate.

See also
Divided
Scale
Vector2D ugdk::math::Vector2D::Divided ( const Vector2D divider) const

Returns a new Integer2D equal to this divided coordinate by coordinate by "multiplier".

See also
Divide
Scale
double ugdk::math::Vector2D::get_x ( ) const
inline
double ugdk::math::Vector2D::get_y ( ) const
inline
static double ugdk::math::Vector2D::InnerProduct ( const Vector2D a,
const Vector2D b 
)
inlinestatic

Static method that returns a scalar equal to the inner product of two vectors.

By definition the inner product of two vectors (x,y) (w,z) is equal to (x*w) + (y*z)

Returns
InnerProduct
double ugdk::math::Vector2D::Length ( ) const

Returns the norm-2 of this vector.

The norm-2 of a vector (x,y) is sqrt( x^2 + y^2 )

Returns
Norm-2
See also
NormOne()
LenghtSquared()
double ugdk::math::Vector2D::length ( ) const
inline

Deprecated. Use the upper case method.

Deprecated method that returns the Lenght of a vector (x,y). Use instead Lenght method

Returns
lenght
See also
Lenght()
double ugdk::math::Vector2D::LengthSquared ( ) const
inline

Returns the norm-2 squared.

The norm-2 squared of a vector (x,y) is (x^2 + y^2)

Returns
Norm-2 Squared
See also
NormOne()
Lenght()
void ugdk::math::Vector2D::Mirror ( const ugdk::enums::mirroraxis::MirrorAxis  axis)

Mirrors this Vector2D (in-place) by the "axis" axis. Include types.h and use "using namespace ugdk::enums".

Parameters
axisEither mirroraxis::HORZ, mirroraxis::VERT, mirroraxis::DIAG_UP, or mirroraxis::DIAG_DOWN.
See also
Mirrored
Vector2D ugdk::math::Vector2D::Mirrored ( const ugdk::enums::mirroraxis::MirrorAxis  axis) const

Returns a new Vector2D, mirrored by the "axis" axis. Include types.h and use "using namespace ugdk::enums".

Parameters
axisEither mirroraxis::HORZ, mirroraxis::VERT, mirroraxis::DIAG_UP, or mirroraxis::DIAG_DOWN.
See also
Mirror
static Vector2D ugdk::math::Vector2D::Multiply ( const Vector2D a,
double  scalar 
)
inlinestatic

Static method that returns a vector equal to the a vector multiplied by a scalar.

A vector (x,y) multiplied by a scalar a is equal to the vector (x * scalar, y*scalar)

Returns
Scalar Multiplied Vector
Vector2D ugdk::math::Vector2D::Normalize ( ) const

Returns a new vector equal to this vector normalized.

The normalized vector (x,y) is (x,y) / Lenght(x,y)

Returns
Normalized Vector
See also
Lenght()
static Vector2D ugdk::math::Vector2D::Normalized ( Vector2D a)
inlinestatic

Deprecated. Use the method function Normalize.

Deprecated method that returns a normalized vector of a vector (x,y). Use instead Normalize

Returns
normalized vector
See also
Normalize()
double ugdk::math::Vector2D::NormOne ( ) const

Returns the norm-1 of this vector.

The norm-1 of a vector (x,y) is |x| + |y|.

Returns
Norm-1
See also
Length()
ugdk::math::Vector2D::operator std::array< double, 2 > ( ) const
inline
ugdk::math::Vector2D::operator std::pair< double, double > ( ) const
inline
Vector2D ugdk::math::Vector2D::operator* ( double  scalar) const

Method that returns a vector equal to the a vector multiplied by a scalar.

A vector (x,y) multiplied by a scalar a is equal to the vector (x * scalar, y*scalar)

Returns
Scalar Multiplied Vector
double ugdk::math::Vector2D::operator* ( const Vector2D right) const

Method that returns a scalar equal to the inner product of two vectors.

By definition the inner product of two vectors (x,y) (w,z) is equal to (x*w) + (y*z)

Returns
InnerProduct
Vector2D& ugdk::math::Vector2D::operator*= ( double  other)
Vector2D ugdk::math::Vector2D::operator+ ( const Vector2D right) const

Method that returns a vector equal to the sum of two others.

The sum of two vectors (x,y) (w,z) is igual to the vector (x+w, y+z)

Returns
Sum Vector
Vector2D& ugdk::math::Vector2D::operator+= ( const Vector2D other)
Vector2D ugdk::math::Vector2D::operator- ( ) const

Method that returns a vector equal to the oposite of another.

The oposite of a vector (x,y) is equal to the vector (-x,-y) in this order

Returns
Oposite Vector
Vector2D ugdk::math::Vector2D::operator- ( const Vector2D right) const

Method that returns a vector equal to the subtraction of two others.

The subtraction of two vectors (x,y) (z,w) is equal to the vector (x-z,y-w) in this order

Returns
Subtract Vector
Vector2D& ugdk::math::Vector2D::operator-= ( const Vector2D other)
Vector2D ugdk::math::Vector2D::operator/ ( double  scalar) const

Method that returns a vector equal to the a vector multiplied by the inverse of a scalar.

A vector (x,y) multiplied by the inverse of a scalar is equal to the vector (x * 1/scalar, y * 1/scalar)

Returns
Inverse Scalar Multiplied Vector
bool ugdk::math::Vector2D::operator== ( const Vector2D rhs)
inline

Compares this vector to the given vector, return True if they are equivalent.

Two vectors are equivalent if the coordinates are equal.

Returns
True if vectors are equivalent.
Vector2D ugdk::math::Vector2D::Rotate ( double  angle) const

Returns a new vector equal to this vector rotated by "angle" (in radians) counter-clockwise.

The vector rotated of a vector (x,y) is (x * cos(angle) - y * sin(angle) , x * sin(angle) + y * cos(angle)); angle in radians

Returns
Rotated Vector
See also
Angle
static Vector2D ugdk::math::Vector2D::Rotate ( Vector2D a,
double  angle 
)
inlinestatic

Deprecated. Use the method function Rotate.

Deprecated method that returns a rotated vector of a vector (x,y). Use instead Rotate

Returns
rotated vector
See also
Rotate
Vector2D ugdk::math::Vector2D::Scale ( const Vector2D scale) const

Returns a new vector which is this vector scaled coordinate by coordinate with "scale".

The resulting scaled vector is (this->x * scale.x, this->y * scale.y).

Returns
scaled vector
void ugdk::math::Vector2D::set_x ( double  x_)
inline
void ugdk::math::Vector2D::set_y ( double  y_)
inline
static Vector2D ugdk::math::Vector2D::Subtract ( const Vector2D a,
const Vector2D b 
)
inlinestatic

Static method that returns a vector equal to the subtraction of two others.

The subtraction of two vectors (x,y) (z,w) is equal to the vector (x-z,y-w) in this order

Returns
Subtract Vector

Member Data Documentation

union { ... }
double ugdk::math::Vector2D::val[2]
double ugdk::math::Vector2D::x
double ugdk::math::Vector2D::y

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