# VectorNav C++ Library: vn::math::vec< 4, T > Struct Template Reference

vn::math::vec< 4, T > Struct Template Reference

Vector with 4 component specialization. More...

`#include <vector.h>`

## Public Member Functions

| vec ()
| Creates a new vector with uninitialized components.
| vec (T val)
| Creates new vector with components initialized to val. More...
| vec (T x_val, T y_val, T z_val, T w_val)
| Creates a new vector with its components inintialized to the provided values. More...
T & | operator[] (size_t index)
| Indexing into the vector's components. More...
const T & | operator[] (size_t index) const
| Indexing into the vector's components. More...
vec | operator- () const
| Negates the vector. More...
vec & | operator+= (const vec &rhs)
| Adds a vector to this vector. More...
vec & | operator-= (const vec &rhs)
| Subtracts a vector from this vector. More...
vec & | operator*= (const T &rhs)
| Multiplies the vector by a scalar. More...
vec & | operator/= (const T &rhs)
| Divides the vector by a scalar. More...
size_t | dim () const
| The vector's dimension. More...
vec | neg () const
| Negates the vector. More...
T | mag () const
| The vector's magnitude. More...
vec | add (const vec &toAdd) const
| Adds a vector to this vector. More...
vec | sub (const vec &to_sub) const
| Subtracts a vector from this vector. More...
vec | mult (const double &scalar) const
| Multiplies the vector by a scalar. More...
vec | div (const double &scalar) const
| Divides the vector by a scalar. More...
vec | norm () const
| Normalizes the vector. More...
T | dot (const vec &rhs) const
| Computes the dot product of this and the provided vector. More...

## Static Public Member Functions

static vec | zero ()
| Vector with all of its components set to 0. More...
static vec | one ()
| Vector with all of its components set to 1. More...
static vec | unitX ()
| Unit vector pointing in the X (0-component) direction. More...
static vec | unitY ()
| Unit vector pointing in the Y (1-component) direction. More...
static vec | unitZ ()
| Unit vector pointing in the Z (2-component) direction. More...
static vec | unitW ()
| Unit vector pointing in the W (3-component) direction. More...

## Public Attributes

union vn::math::vec< 4, T >:: { ... } |
T | x
| X (0-component).
T | y
| Y (1-component).
T | z
| Z (2-component).
T | w
| W (3-component).
T | r
| Red (0-component).
T | g
| Green (1-component).
T | b
| Blue (2-component).
T | a
| Alpha (3-component).
T | c [4]
| The vector's components.

## Detailed Description

### template<typename T>
struct vn::math::vec< 4, T >

Vector with 4 component specialization.

## Constructor & Destructor Documentation

template<typename T >

vn::math::vec< 4, T >::vec | ( | T | val | ) |

inlineexplicit

Creates new vector with components initialized to val.

Parameters

  [in] | val | The initialization value.

template<typename T >

vn::math::vec< 4, T >::vec | ( | T | x_val,
|  | T | y_val,
|  | T | z_val,
|  | T | w_val
| ) |  |

inline

Creates a new vector with its components inintialized to the provided values.

Parameters

  [in] | x_val | The x value.
  [in] | y_val | The y value.
  [in] | z_val | The z value.
  [in] | w_val | The w value.

## Member Function Documentation

template<typename T >

vec vn::math::vec< 4, T >::add | ( | const vec< 4, T > & | toAdd | ) | const

inline

Adds a vector to this vector.

Parameters

  [in] | toAdd | The vector to add.

Returns
  The resulting vector.

template<typename T >

size_t vn::math::vec< 4, T >::dim | ( |  | ) | const

inline

The vector's dimension.

Returns
  The vector's dimension.

template<typename T >

vec vn::math::vec< 4, T >::div | ( | const double & | scalar | ) | const

inline

Divides the vector by a scalar.

Parameters

  [in] | scalar | The scalar value.

Returns
  The divided vector.

template<typename T >

T vn::math::vec< 4, T >::dot | ( | const vec< 4, T > & | rhs | ) | const

inline

Computes the dot product of this and the provided vector.

Parameters

  [in] | rhs | The right-side vector.

Returns
  The computed dot product.

template<typename T >

T vn::math::vec< 4, T >::mag | ( |  | ) | const

inline

The vector's magnitude.

Returns
  The magnitude.

template<typename T >

vec vn::math::vec< 4, T >::mult | ( | const double & | scalar | ) | const

inline

Multiplies the vector by a scalar.

Parameters

  [in] | scalar | The scalar value.

Returns
  The multiplied vector.

template<typename T >

vec vn::math::vec< 4, T >::neg | ( |  | ) | const

inline

Negates the vector.

Returns
  The negated vector.

template<typename T >

vec vn::math::vec< 4, T >::norm | ( |  | ) | const

inline

Normalizes the vector.

Returns
  The normalized vector.

template<typename T >

static vec vn::math::vec< 4, T >::one | ( |  | ) |

inlinestatic

Vector with all of its components set to 1.

Returns
  The 1 vector.

template<typename T >

vec& vn::math::vec< 4, T >::operator*= | ( | const T & | rhs | ) |

inline

Multiplies the vector by a scalar.

Parameters

  [in] | rhs | The scalar.

Returns
  The multiplied vector.

template<typename T >

vec& vn::math::vec< 4, T >::operator+= | ( | const vec< 4, T > & | rhs | ) |

inline

Adds a vector to this vector.

Parameters

  [in] | rhs | The right-side vector.

Returns
  The resulting vector.

template<typename T >

vec vn::math::vec< 4, T >::operator- | ( |  | ) | const

inline

Negates the vector.

Returns
  The negated vector.

template<typename T >

vec& vn::math::vec< 4, T >::operator-= | ( | const vec< 4, T > & | rhs | ) |

inline

Subtracts a vector from this vector.

Parameters

  [in] | rhs | The right-side vector.

Returns
  The resulting vector.

template<typename T >

vec& vn::math::vec< 4, T >::operator/= | ( | const T & | rhs | ) |

inline

Divides the vector by a scalar.

Parameters

  [in] | rhs | The scalar.

Returns
  The divided vector.

template<typename T >

T& vn::math::vec< 4, T >::operator[] | ( | size_t | index | ) |

inline

Indexing into the vector's components.

Parameters

  [in] | index | 0-based component index.

Exceptions

  dimension_error | The index exceeded the dimension of the vector.

template<typename T >

const T& vn::math::vec< 4, T >::operator[] | ( | size_t | index | ) | const

inline

Indexing into the vector's components.

Parameters

  [in] | index | 0-based component index.

Exceptions

  dimension_error | The index exceeded the dimension of the vector.

template<typename T >

vec vn::math::vec< 4, T >::sub | ( | const vec< 4, T > & | to_sub | ) | const

inline

Subtracts a vector from this vector.

Parameters

  [in] | to_sub | The vector to subtract from this.

Returns
  The resulting vector.

template<typename T >

static vec vn::math::vec< 4, T >::unitW | ( |  | ) |

inlinestatic

Unit vector pointing in the W (3-component) direction.

Returns
  The unit vector.

template<typename T >

static vec vn::math::vec< 4, T >::unitX | ( |  | ) |

inlinestatic

Unit vector pointing in the X (0-component) direction.

Returns
  The unit vector.

template<typename T >

static vec vn::math::vec< 4, T >::unitY | ( |  | ) |

inlinestatic

Unit vector pointing in the Y (1-component) direction.

Returns
  The unit vector.

template<typename T >

static vec vn::math::vec< 4, T >::unitZ | ( |  | ) |

inlinestatic

Unit vector pointing in the Z (2-component) direction.

Returns
  The unit vector.

template<typename T >

static vec vn::math::vec< 4, T >::zero | ( |  | ) |

inlinestatic

Vector with all of its components set to 0.

Returns
  The 0 vector.

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

- include/vn/vector.h