SpatiumLib
Public Member Functions | Friends | List of all members
spatium::geom2d::Vector2 Class Reference

Vector in 2D space. More...

#include <Vector2.h>

Inheritance diagram for spatium::geom2d::Vector2:
Inheritance graph
[legend]
Collaboration diagram for spatium::geom2d::Vector2:
Collaboration graph
[legend]

Public Member Functions

 Vector2 ()
 Constructor. More...
 
 Vector2 (double x, double y)
 Constructor. More...
 
 Vector2 (double xy[])
 Constructor. More...
 
 Vector2 (std::vector< double > vector)
 Constructor. More...
 
 Vector2 (const Vector2 &other)
 Copy constructor. More...
 
 Vector2 (const Matrix &other)
 Copy constructor. More...
 
Vector2operator= (Vector2 other)
 Assignment operator. More...
 
 ~Vector2 ()=default
 Desctructor. More...
 
void x (double val)
 
double x () const
 
void y (double val)
 
double y () const
 
double * array ()
 Get coordinates as array. More...
 
Vector2 operator+ (const Matrix &other) const
 Add matrix to vector. More...
 
Vector2 operator- (const Matrix &other) const
 Subtract matrix from vector. More...
 
Vector2 operator * (double scalar) const
 Multiply vector by scalar. More...
 
Vector2 operator/ (double scalar) const
 Divide by scalar. More...
 
double length () const
 Calculate length of vector (magnitude). More...
 
void normalize ()
 Normalize the vector. A normalized vector has length = 1. More...
 
Vector2 normalized () const
 Get normalized copy of vector. A normalized vector has length = 1. More...
 
double dot (const Vector2 &other) const
 Calculate dot product with vector. Dot product = 0: vectors are orthogonal (perpendicular). Dot product = |a||b| (1 if normalized): vectors are parallel. More...
 
double angle (const Vector2 &other) const
 Calculate angle with vector. More...
 
Vector2 project (const Vector2 &other) const
 Project vector onto vector. More...
 
- Public Member Functions inherited from spatium::Vector
 Vector (size_t rows)
 Constructor. More...
 
 Vector (std::initializer_list< double > array)
 Constructor. More...
 
 Vector (const std::vector< double > &vector)
 Constructor. More...
 
 Vector (const Vector &other)
 Copy constructor. More...
 
 Vector (const Matrix &other)
 Copy constructor. More...
 
Vectoroperator= (const Vector &other)=default
 Assignment operator. More...
 
 ~Vector ()=default
 Destructor. More...
 
double operator() (size_t row) const
 Access element by value. More...
 
double & operator() (size_t row)
 Access element by reference. More...
 
Vector operator+ (const Matrix &other) const
 Add matrix to vector. More...
 
Vector operator- (const Matrix &other) const
 Subtract matrix from vector. More...
 
Vector operator * (double scalar) const
 Multiply by scalar. More...
 
Vector operator/ (double scalar) const
 Divide by scalar. More...
 
void resize (size_t rows)
 Resize. More...
 
- Public Member Functions inherited from spatium::Matrix
 Matrix (size_t rows, size_t cols)
 Constructor. More...
 
 Matrix (std::initializer_list< std::initializer_list< double >> array)
 Constructor. More...
 
bool operator== (const Matrix &other) const
 Compare operator. Is equal. More...
 
bool operator!= (const Matrix &other) const
 Compare operator. Is unequal. More...
 
size_t rows () const
 Get the number of rows. More...
 
size_t cols () const
 Get the number of columns. More...
 
std::vector< double > data () const
 Get all matrix elements. More...
 
void clear ()
 Clear all matrix elements. More...
 
Matrix transposed () const
 Get transposed matrix. More...
 
double determinant () const
 Calculate determinant. More...
 
double minor (size_t row, size_t col) const
 Calulcate minor. More...
 
Matrix omit (size_t row, size_t col) const
 Omit a given row and column. More...
 
Matrix inverse () const
 Calculate inverse of matrix. More...
 
double operator() (size_t row, size_t col) const
 Access element by value. More...
 
double & operator() (size_t row, size_t col)
 Access element by reference. More...
 
Matrix operator+ (const Matrix &other) const
 Add by matrix. More...
 
Matrix operator- (const Matrix &other) const
 Subtract by matrix. More...
 
Matrix operator * (const Matrix &other) const
 Multiply by matrix. More...
 
Matrix operator * (double scalar) const
 Multiply by scalar. More...
 
Matrix operator/ (double scalar) const
 Divide by scalar. More...
 
void resize (size_t rows, size_t cols)
 Resize. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Vector2 &vector)
 Output to ostream. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from spatium::Matrix
static Matrix identity (size_t order)
 Construct identity matrix. More...
 
- Protected Member Functions inherited from spatium::Matrix
double determinant (const Matrix &matrix) const
 Calculate determinant. More...
 
- Protected Attributes inherited from spatium::Matrix
size_t m_rows
 
size_t m_cols
 
std::vector< double > m_data
 

Detailed Description

Vector in 2D space.

Column vector with 3 rows. The first two elements define the X and Y coordinates. The third element is always 0.

Constructor & Destructor Documentation

◆ Vector2() [1/6]

spatium::geom2d::Vector2::Vector2 ( )
inline

Constructor.

◆ Vector2() [2/6]

spatium::geom2d::Vector2::Vector2 ( double  x,
double  y 
)
inline

Constructor.

Parameters
[in]xX coordinate
[in]yY coordinate

◆ Vector2() [3/6]

spatium::geom2d::Vector2::Vector2 ( double  xy[])
inline

Constructor.

Parameters
[in]xyArray with X and Y coordinates

◆ Vector2() [4/6]

spatium::geom2d::Vector2::Vector2 ( std::vector< double >  vector)
inline

Constructor.

Parameters
[in]vectorSTD vector

◆ Vector2() [5/6]

spatium::geom2d::Vector2::Vector2 ( const Vector2 other)
inline

Copy constructor.

◆ Vector2() [6/6]

spatium::geom2d::Vector2::Vector2 ( const Matrix other)
inline

Copy constructor.

Parameters
[in]otherOther matrix
Exceptions
std::out_of_rangeMatrix dimensions out of range

◆ ~Vector2()

spatium::geom2d::Vector2::~Vector2 ( )
default

Desctructor.

Member Function Documentation

◆ angle()

double spatium::geom2d::Vector2::angle ( const Vector2 other) const
inline

Calculate angle with vector.

Parameters
[in]otherOther vector
Returns
Angle in radians

◆ array()

double* spatium::geom2d::Vector2::array ( )
inline

Get coordinates as array.

Returns
Coordinates

◆ dot()

double spatium::geom2d::Vector2::dot ( const Vector2 other) const
inline

Calculate dot product with vector. Dot product = 0: vectors are orthogonal (perpendicular). Dot product = |a||b| (1 if normalized): vectors are parallel.

Parameters
[in]otherOther vector
Returns
Dot product

◆ length()

double spatium::geom2d::Vector2::length ( ) const
inline

Calculate length of vector (magnitude).

Returns
Length

◆ normalize()

void spatium::geom2d::Vector2::normalize ( )
inline

Normalize the vector. A normalized vector has length = 1.

◆ normalized()

Vector2 spatium::geom2d::Vector2::normalized ( ) const
inline

Get normalized copy of vector. A normalized vector has length = 1.

Returns
Normalized vector

◆ operator *()

Vector2 spatium::geom2d::Vector2::operator * ( double  scalar) const
inline

Multiply vector by scalar.

Parameters
[in]scalar
Returns
Multiplied vector

◆ operator+()

Vector2 spatium::geom2d::Vector2::operator+ ( const Matrix other) const
inline

Add matrix to vector.

Parameters
[in]otherMatrix to add
Exceptions
std::out_of_rangeMatrix dimensions out of range
Returns
Added vector

◆ operator-()

Vector2 spatium::geom2d::Vector2::operator- ( const Matrix other) const
inline

Subtract matrix from vector.

Parameters
[in]otherMatrix to subtract
Exceptions
std::out_of_rangeMatrix dimensions out of range
Returns
Subtracted vector

◆ operator/()

Vector2 spatium::geom2d::Vector2::operator/ ( double  scalar) const
inline

Divide by scalar.

Parameters
[in]scalarScalar
Returns
Divided vector

◆ operator=()

Vector2& spatium::geom2d::Vector2::operator= ( Vector2  other)
inline

Assignment operator.

◆ project()

Vector2 spatium::geom2d::Vector2::project ( const Vector2 other) const
inline

Project vector onto vector.

Parameters
[in]otherVector to project
Returns
Projected vector

◆ x() [1/2]

void spatium::geom2d::Vector2::x ( double  val)
inline

◆ x() [2/2]

double spatium::geom2d::Vector2::x ( ) const
inline

◆ y() [1/2]

void spatium::geom2d::Vector2::y ( double  val)
inline

◆ y() [2/2]

double spatium::geom2d::Vector2::y ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Vector2 vector 
)
friend

Output to ostream.


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