Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
Vector2 Class Reference

Vectors in two dimensions. More...

#include <evector.h>

Public Member Functions

 Vector2 ()
 Empty.
 
 Vector2 (const double &)
 Create a vector with the same real coordinates. More...
 
 Vector2 (const double &, const double &)
 Create a vector with argument coordinates.
 
 Vector2 (const Vector &)
 Create a two dimension vector from another three dimension vector.
 
double & operator[] (int)
 Gets the i-th coordinate of vector.
 
constexpr double operator[] (int) const
 Returns the i-th coordinate of vector.
 
Vector2 Orthogonal () const
 Returns a direct orthogonal vector.
 
Vector2 operator+ () const
 Overloaded.
 
Vector2 operator- () const
 Overloaded.
 
Vector2operator+= (const Vector2 &)
 Destructive addition.
 
Vector2operator-= (const Vector2 &)
 Destructive subtraction.
 
Vector2operator*= (const Vector2 &)
 Destructively scale a vector by another vector.
 
Vector2operator/= (const Vector2 &)
 Destructively divide the components of a vector by another vector.
 
Vector2operator*= (double)
 Destructive scalar multiply.
 
Vector2operator/= (double)
 Destructive division by a scalar.
 
double Max () const
 Compute the maximum component of a vector. More...
 
int MaxIndex () const
 Compute the index of the maximum component of a vector. More...
 
int MinIndex () const
 Compute the index of the minimum component of a vector. More...
 
Vector ToVector (const double &=0.0) const
 Convert a Vector2 to a Vector. More...
 
Vector2 Inverse () const
 Inverse of a vector. More...
 
int Quadrant (const Vector2 &) const
 Computes quadrant index of a vector with respect to the vector object. More...
 
QString ToString (int=6) const
 Create a QString form a vector. More...
 
Vector2 Scaled (const Vector2 &) const
 Scales the vector. More...
 
void Scale (const Vector2 &)
 Scales the vector. More...
 
Vector2 Sort () const
 Sort the terms of the vector into ascending order.
 
double Angle (const Vector2 &) const
 Compute the angle between two vectors. More...
 
double Angle () const
 Compute the angle of a vector. More...
 
Vector2 Floor () const
 Compute the numerator part of the coordinates. More...
 
Vector2 Fract () const
 Compute the fractional part of the coordinates. More...
 

Static Public Member Functions

static bool Equal (const Vector2 &, const Vector2 &, const double &=0.0001)
 Test if two vectors are almost equal. More...
 
static Vector2 Min (const Vector2 &, const Vector2 &)
 Return a vector with coordinates set to the minimum coordinates of the two argument vectors.
 
static Vector2 Max (const Vector2 &, const Vector2 &)
 Return a vector with coordinates set to the maximum coordinates of the two argument vectors.
 
static void SetMinMax (const Vector2 &, Vector2 &, Vector2 &)
 Update the minimum and maximum values given a vector. More...
 
static Vector2 Modulo (const Vector2 &, const Vector2 &)
 Modulo of two vectors. More...
 
static Vector2 Lerp (const Vector2 &, const Vector2 &, const double &)
 Linear interpolation between two vectors. More...
 
static Vector2 Bilinear (const Vector2 &, const Vector2 &, const Vector2 &, const Vector2 &, const double &, const double &)
 Bi-linear interpolation between four vectors. More...
 
static Vector2 FromString (QString)
 Creates a vector from a QString. More...
 
static Vector2 Polar (const double &)
 Creates a vector given polar coordinates. More...
 
static Vector2 Solve (const Vector2 &, const Vector2 &, const double &, const double &)
 Compute the point on a segment such that the linear function satisfies f(a)=va and f(b)=vb. More...
 
static bool Clockwise (const Vector2 &, const Vector2 &, const Vector2 &)
 Returns true if the three points make a clockwise turn. More...
 

Static Public Attributes

static const Vector2 Null = Vector2(0.0, 0.0)
 Null vector.
 
static const Vector2 X = Vector2(1.0, 0.0)
 Vector2(1,0).
 
static const Vector2 Y = Vector2(0.0, 1.0)
 Vector2(0,1).
 

Protected Attributes

double c [2]
 Components.
 

Friends

bool operator> (const Vector2 &, const Vector2 &)
 Compare two vectors.
 
bool operator< (const Vector2 &, const Vector2 &)
 Compare two vectors.
 
bool operator>= (const Vector2 &, const Vector2 &)
 Overloaded.
 
bool operator<= (const Vector2 &, const Vector2 &)
 Overloaded.
 
Vector2 operator+ (const Vector2 &, const Vector2 &)
 Adds up two vectors.
 
Vector2 operator- (const Vector2 &, const Vector2 &)
 Difference between two vectors.
 
double operator* (const Vector2 &, const Vector2 &)
 Dot product between two vectors. More...
 
Vector2 operator* (const Vector2 &, double)
 Right multiply by a scalar.
 
Vector2 operator* (double, const Vector2 &)
 Left multiply by a scalar.
 
Vector2 operator/ (const Vector2 &, double)
 Left divide by a scalar.
 
double operator/ (const Vector2 &, const Vector2 &)
 Cross productof two vectors. Note that the derminant of a 2-square matrix is the cross product of its two colum vectors.
 
bool operator== (const Vector2 &, const Vector2 &)
 Strong equality test.
 
bool operator!= (const Vector2 &, const Vector2 &)
 Strong difference test.
 
double Norm (const Vector2 &)
 Compute the Euclidean norm of a vector. This function involves a square root computation, it is often more efficient to rely on the squared norm of a vector instead. More...
 
double SquaredNorm (const Vector2 &)
 Compute the squared Euclidean norm of a vector. More...
 
double NormInfinity (const Vector2 &)
 Compute the infinity norm of a vector. More...
 
void Normalize (Vector2 &)
 Normalize a two dimensional vector. More...
 
Vector2 Normalized (const Vector2 &)
 Return a Normalized a vector, computing the inverse of its norm and scaling the components. This function does not check if the vector is null, which might result in errors.
 
double Sine (const Vector2 &, const Vector2 &)
 Returns the sine of two vectors. More...
 
double Cosine (const Vector2 &, const Vector2 &)
 Returns the positive cosine of two vectors. More...
 
Vector2 Abs (const Vector2 &)
 Computes the absolute value of a vector.
 
void Swap (Vector2 &, Vector2 &)
 Swap two vectors. More...
 
Vector2 Clamp (const Vector2 &, const Vector2 &, const Vector2 &)
 Clamp a Vector2 between two bounds. More...
 
double WhichSide (const Vector2 &, const Vector2 &, const Vector2 &)
 Compute the position of a point with respect to a line. More...
 
bool IsLeft (const Vector2 &, const Vector2 &, const Vector2 &)
 Compute the position of a point with respect to a line. More...
 
bool IsRight (const Vector2 &, const Vector2 &, const Vector2 &)
 Compute the position of a point with respect to a line. More...
 
std::ostream & operator<< (std::ostream &, const Vector2 &)
 Overloaded output-stream operator. More...
 

Detailed Description

Vectors in two dimensions.

This class implements most operators and member functions as for Vector class.

Constructor & Destructor Documentation

◆ Vector2()

Vector2::Vector2 ( const double &  a)
inlineexplicit

Create a vector with the same real coordinates.

Parameters
aReal.

Member Function Documentation

◆ Angle() [1/2]

double Vector2::Angle ( ) const

Compute the angle of a vector.

The vector need not be normalized.

◆ Angle() [2/2]

double Vector2::Angle ( const Vector2 b) const

Compute the angle between two vectors.

Note that both vectors should be unit.

See also
Vector2::Angle() const
Parameters
bArgument vector forming the angle.

◆ Bilinear()

Vector2 Vector2::Bilinear ( const Vector2 a00,
const Vector2 a10,
const Vector2 a11,
const Vector2 a01,
const double &  u,
const double &  v 
)
inlinestatic

Bi-linear interpolation between four vectors.

The vectors are given in trigonometric order.

Parameters
a00,a10,a11,a01Interpolated vectors.
u,vInterpolation coefficients.
See also
Math::Bilinear

◆ Clockwise()

bool Vector2::Clockwise ( const Vector2 a,
const Vector2 b,
const Vector2 c 
)
inlinestatic

Returns true if the three points make a clockwise turn.

Parameters
a,b,cPoints.
See also
WhichSide

◆ Equal()

bool Vector2::Equal ( const Vector2 a,
const Vector2 b,
const double &  epsilon = 0.0001 
)
static

Test if two vectors are almost equal.

See also
Vector::Equal

◆ Floor()

Vector2 Vector2::Floor ( ) const
inline

Compute the numerator part of the coordinates.

See also
Math::Floor

◆ Fract()

Vector2 Vector2::Fract ( ) const
inline

Compute the fractional part of the coordinates.

See also
Math::Fract

◆ FromString()

Vector2 Vector2::FromString ( QString  n)
static

Creates a vector from a QString.

Parameters
nString.

◆ Inverse()

Vector2 Vector2::Inverse ( ) const
inline

Inverse of a vector.

This function inverses the components of the vector.

See also
Vector::Inverse()

◆ Lerp()

Vector2 Vector2::Lerp ( const Vector2 a,
const Vector2 b,
const double &  t 
)
inlinestatic

Linear interpolation between two vectors.

Parameters
a,bInterpolated points.
tInterpolant.

◆ Max()

double Vector2::Max ( ) const
inline

Compute the maximum component of a vector.

See also
NormInfinity

◆ MaxIndex()

int Vector2::MaxIndex ( ) const
inline

Compute the index of the maximum component of a vector.

Vector2 a(-1.0,-3.0);
int i=MaxIndex(Abs(a)); // Should be 1
Vectors in two dimensions.
Definition: evector.h:617
int MaxIndex() const
Compute the index of the maximum component of a vector.
Definition: evector.h:1001
friend Vector2 Abs(const Vector2 &)
Computes the absolute value of a vector.
Definition: evector.h:975
See also
Vector::MaxIndex

◆ MinIndex()

int Vector2::MinIndex ( ) const
inline

Compute the index of the minimum component of a vector.

See also
Vector::MinIndex

◆ Modulo()

Vector2 Vector2::Modulo ( const Vector2 a,
const Vector2 b 
)
inlinestatic

Modulo of two vectors.

Parameters
a,bTwo vectors.

◆ Polar()

Vector2 Vector2::Polar ( const double &  t)
inlinestatic

Creates a vector given polar coordinates.

Parameters
tTheta.

◆ Quadrant()

int Vector2::Quadrant ( const Vector2 p) const

Computes quadrant index of a vector with respect to the vector object.

See also
Box2::Quadrant(const Vector&)
Parameters
pVector.

◆ Scale()

void Vector2::Scale ( const Vector2 a)
inline

Scales the vector.

Parameters
aScaling vector.

◆ Scaled()

Vector2 Vector2::Scaled ( const Vector2 a) const
inline

Scales the vector.

Parameters
aScaling vector.

◆ SetMinMax()

void Vector2::SetMinMax ( const Vector2 x,
Vector2 a,
Vector2 b 
)
static

Update the minimum and maximum values given a vector.

Parameters
xInput vector.
a,bLower and upper vectors that will be updated.

◆ Solve()

Vector2 Vector2::Solve ( const Vector2 a,
const Vector2 b,
const double &  va,
const double &  vb 
)
inlinestatic

Compute the point on a segment such that the linear function satisfies f(a)=va and f(b)=vb.

See also
Vector::Solve(const double& a, const double& b, const Vector&, const Vector&);

◆ ToString()

QString Vector2::ToString ( int  n = 6) const

Create a QString form a vector.

Parameters
nNumber of digits.

◆ ToVector()

Vector Vector2::ToVector ( const double &  z = 0.0) const
inline

Convert a Vector2 to a Vector.

Parameters
zExtra coordinate.

Friends And Related Function Documentation

◆ Clamp

Vector2 Clamp ( const Vector2 x,
const Vector2 a,
const Vector2 b 
)
friend

Clamp a Vector2 between two bounds.

Parameters
xInput vector
a,bVector bounds.

◆ Cosine

double Cosine ( const Vector2 u,
const Vector2 v 
)
friend

Returns the positive cosine of two vectors.

Computes the dot product of the normalized vectors.

Parameters
u,vVectors.

◆ IsLeft

bool IsLeft ( const Vector2 p,
const Vector2 a,
const Vector2 b 
)
friend

Compute the position of a point with respect to a line.

Parameters
pPoint
a,bVertices of the line.

◆ IsRight

bool IsRight ( const Vector2 p,
const Vector2 a,
const Vector2 b 
)
friend

Compute the position of a point with respect to a line.

Parameters
pPoint
a,bVertices of the line.

◆ Norm

double Norm ( const Vector2 u)
friend

Compute the Euclidean norm of a vector. This function involves a square root computation, it is often more efficient to rely on the squared norm of a vector instead.

See also
SquaredNorm

◆ Normalize

void Normalize ( Vector2 u)
friend

Normalize a two dimensional vector.

It computes the inverse of its norm and scaling the components. This function does not check if the vector is null, which might yield errors.

Parameters
uVector.

◆ NormInfinity

double NormInfinity ( const Vector2 u)
friend

Compute the infinity norm of a vector.

See also
Norm, SquaredNorm

◆ operator*

double operator* ( const Vector2 u,
const Vector2 v 
)
friend

Dot product between two vectors.

Parameters
u,vArgument vectors.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Vector2 u 
)
friend

Overloaded output-stream operator.

Parameters
uVector.
sStream.

◆ Sine

double Sine ( const Vector2 u,
const Vector2 v 
)
friend

Returns the sine of two vectors.

Computes the cross product of the vectors and normalizes the result.

Parameters
u,vVectors.

◆ SquaredNorm

double SquaredNorm ( const Vector2 u)
friend

Compute the squared Euclidean norm of a vector.

See also
Norm

◆ Swap

void Swap ( Vector2 a,
Vector2 b 
)
friend

Swap two vectors.

Parameters
a,bVectors.

◆ WhichSide

double WhichSide ( const Vector2 p,
const Vector2 a,
const Vector2 b 
)
friend

Compute the position of a point with respect to a line.

Parameters
pPoint
a,bVertices of the line.