# VectorNav C++ Library: include/vn/vector.h Source File

vector.h
Go to the documentation of this file.
#ifndef _VN_MATH_VECTOR_H_
#define _VN_MATH_VECTOR_H_
#include <cassert>
#include <sstream>
#include <ostream>
#include <cmath>
#include "exceptions.h"
#include "int.h"
namespace vn {
namespace math {
template <size_t tdim, typename T = float>
struct vec
{
// Public Members /////////////////////////////////////////////////////////
public:
T c[tdim];
// Constructors ///////////////////////////////////////////////////////////
public:
vec() { }
explicit vec(T val)
{
std::fill_n(c, tdim, val);
}
// Helper Methods /////////////////////////////////////////////////////////
public:
static vec zero()
{
return vec<tdim, T>(0);
}
static vec one()
{
return vec<tdim, T>(1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator[](size_t index)
{
return const_cast<T&>(static_cast<const vec&>(*this)[index]);
}
const T& operator[](size_t index) const
{
assert(index < tdim);
return c[index];
}
vec operator-() const
{
return neg();
}
vec& operator+=(const vec& rhs)
{
for (size_t i = 0; i < tdim; i++)
c[i] += rhs.c[i];
return *this;
}
vec& operator-=(const vec& rhs)
{
for (size_t i = 0; i < tdim; i++)
c[i] -= rhs.c[i];
return *this;
}
vec& operator*=(const T& rhs)
{
for (size_t i = 0; i < tdim; i++)
c[i] *= rhs;
return *this;
}
vec& operator/=(const T & rhs)
{
for (size_t i = 0; i < tdim; i++)
c[i] /= rhs;
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dim() const { return tdim; }
vec neg() const
{
vec v;
for (size_t i = 0; i < tdim; i++)
v.c[i] = -c[i];
return v;
}
T mag() const
{
T sumOfSquares = 0;
for (size_t i = 0; i < tdim; i++)
sumOfSquares += c[i] * c[i];
return sqrt(sumOfSquares);
}
vec add(const vec& toAdd) const
{
vec v;
for (size_t i = 0; i < tdim; i++)
v.c[i] = c[i] + toAdd.c[i];
return v;
}
vec sub(const vec& to_sub) const
{
vec v;
for (size_t i = 0; i < tdim; i++)
v.c[i] = c[i] - to_sub.c[i];
return v;
}
vec mult(const double& scalar) const
{
vec v;
for (size_t i = 0; i < tdim; i++)
v.c[i] = c[i] * scalar;
return v;
}
vec div(const double& scalar) const
{
vec v;
for (size_t i = 0; i < tdim; i++)
v.c[i] = c[i] / scalar;
return v;
}
vec norm() const
{
vec v;
T m = mag();
for (size_t i = 0; i < tdim; i++)
v.c[i] = c[i] / m;
return v;
}
T dot(const vec& rhs) const
{
T runningSum = 0;
for (size_t i = 0; i < tdim; i++)
runningSum += c[i] * rhs.c[i];
return runningSum;
}
};
// Specializations ////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
#pragma warning(push)
// Disable warning about 'nonstandard extension used : nameless struct/union'.
#pragma warning(disable:4201)
#endif
template <typename T>
struct vec<2, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T x;
T y;
};
T c[2];
};
// Constructors ///////////////////////////////////////////////////////////
public:
vec() { }
explicit vec(T val) : x(val), y(val) { }
vec(T x_val, T y_val) : x(x_val), y(y_val) { }
// Helper Methods /////////////////////////////////////////////////////////
public:
static vec zero()
{
return vec<2, T>(0);
}
static vec one()
{
return vec<2, T>(1);
}
static vec unitX()
{
return vec<2, T>(1, 0);
}
static vec unitY()
{
return vec<2, T>(0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator[](size_t index)
{
return const_cast<T&>(static_cast<const vec&>(*this)[index]);
}
const T& operator[](size_t index) const
{
assert(index < 2);
return c[index];
}
vec operator-() const
{
return neg();
}
vec& operator+=(const vec& rhs)
{
x += rhs.x;
y += rhs.y;
return *this;
}
vec& operator-=(const vec& rhs)
{
x -= rhs.x;
y -= rhs.y;
return *this;
}
vec& operator*=(const T& rhs)
{
x *= rhs;
y *= rhs;
return *this;
}
vec& operator/=(const T & rhs)
{
x /= rhs;
y /= rhs;
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dim() const { return 2; }
vec neg() const
{
// TODO: Issue when the underlying type is an unsigned integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4146)
#endif
return vec(-x, -y);
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
T mag() const
{
// TODO: Might want this method to return a float even if the underlying
// data type is integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4244)
#endif
#if (defined(_MSC_VER) && _MSC_VER <= 1600)
// HACK: Visual Studio 2010 has trouble determining the correct 'sqrt'
// function for the template int32_t.
return sqrt(static_cast<float>(x*x + y*y));
#else
// HACK:
return sqrt(static_cast<float>(x*x + y*y));
//return sqrt(x*x + y*y);
#endif
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
vec add(const vec& toAdd) const
{
return vec(x + toAdd.x, y + toAdd.y);
}
vec sub(const vec& to_sub) const
{
return vec(x - to_sub.x, y - to_sub.y);
}
vec mult(const double& scalar) const
{
return vec(x * scalar, y * scalar);
}
vec div(const double& scalar) const
{
return vec(x / scalar, y / scalar);
}
vec norm() const
{
T m = mag();
return vec(x / m, y / m);
}
T dot(const vec& rhs) const
{
return x*rhs.x + y*rhs.y;
}
};
template <typename T>
struct vec<3, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T x;
T y;
T z;
};
struct
{
T r;
T g;
T b;
};
// Union of template class with constructor not allowed until C++11.
#if __cplusplus >= 201103L
vec<2, T> xy;
#endif
T c[3];
};
// Constructors ///////////////////////////////////////////////////////////
public:
vec() { }
explicit vec(T val) : x(val), y(val), z(val) { }
vec(const T& x_val, const T& y_val, const T& z_val) : x(x_val), y(y_val), z(z_val) { }
// Helper Methods /////////////////////////////////////////////////////////
public:
static vec zero()
{
return vec<3, T>(0);
}
static vec one()
{
return vec<3, T>(1);
}
static vec unitX()
{
return vec<3, T>(1, 0, 0);
}
static vec unitY()
{
return vec<3, T>(0, 1, 0);
}
static vec unitZ()
{
return vec<3, T>(0, 0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator[](size_t index)
{
return const_cast<T&>(static_cast<const vec&>(*this)[index]);
}
const T& operator[](size_t index) const
{
assert(index < 3);
return c[index];
}
vec operator-() const
{
return neg();
}
vec& operator+=(const vec& rhs)
{
for (size_t i = 0; i < 3; i++)
c[i] += rhs.c[i];
return *this;
}
vec& operator-=(const vec& rhs)
{
for (size_t i = 0; i < 3; i++)
c[i] -= rhs.c[i];
return *this;
}
vec& operator*=(const T& rhs)
{
for (size_t i = 0; i < 3; i++)
c[i] *= rhs;
return *this;
}
vec& operator/=(const T & rhs)
{
for (size_t i = 0; i < 3; i++)
c[i] /= rhs;
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dim() const { return 3; }
vec neg() const
{
// TODO: Issue when the underlying type is an unsigned integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4146)
#endif
return vec(-x, -y, -z);
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
T mag() const
{
// TODO: Might want this method to return a float even if the underlying
// data type is integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4244)
#endif
#if (defined(_MSC_VER) && _MSC_VER <= 1600)
// HACK: Visual Studio 2010 has trouble determining the correct 'sqrt'
// function for the template int32_t.
return sqrt(static_cast<float>(x*x + y*y + z*z));
#else
// HACK:
return sqrt(static_cast<float>(x*x + y*y + z*z));
//return sqrt(x*x + y*y + z*z);
#endif
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
vec add(const vec& toAdd) const
{
return vec(x + toAdd.x, y + toAdd.y, z + toAdd.z);
}
vec sub(const vec& to_sub) const
{
return vec(x - to_sub.x, y - to_sub.y, z - to_sub.z);
}
vec mult(const double& scalar) const
{
return vec(x * scalar, y * scalar, z * scalar);
}
vec div(const double& scalar) const
{
return vec(x / scalar, y / scalar, z / scalar);
}
vec norm() const
{
T m = mag();
return vec(x / m, y / m, z / m);
}
T dot(const vec& rhs) const
{
return x*rhs.x + y*rhs.y + z*rhs.z;
}
vec<3, T> cross(const vec<3, T>& rhs) const
{
vec<3, T> v;
v.c[0] = c[1] * rhs.c[2] - c[2] * rhs.c[1];
v.c[1] = c[2] * rhs.c[0] - c[0] * rhs.c[2];
v.c[2] = c[0] * rhs.c[1] - c[1] * rhs.c[0];
return v;
}
};
template <typename T>
struct vec<4, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T x;
T y;
T z;
T w;
};
struct
{
T r;
T g;
T b;
T a;
};
// Union of template class with constructor not allowed until C++11.
#if __cplusplus >= 201103L
vec<2, T> xy;
vec<3, T> xyz;
vec<3, T> rgb;
#endif
T c[4];
};
// Constructors ///////////////////////////////////////////////////////////
public:
vec() { }
explicit vec(T val) : x(val), y(val), z(val), w(val) { }
vec(T x_val, T y_val, T z_val, T w_val) : x(x_val), y(y_val), z(z_val), w(w_val) { }
// Helper Methods /////////////////////////////////////////////////////////
public:
static vec zero()
{
return vec<4, T>(0);
}
static vec one()
{
return vec<4, T>(1);
}
static vec unitX()
{
return vec<4, T>(1, 0, 0, 0);
}
static vec unitY()
{
return vec<4, T>(0, 1, 0, 0);
}
static vec unitZ()
{
return vec<4, T>(0, 0, 1, 0);
}
static vec unitW()
{
return vec<4, T>(0, 0, 0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator[](size_t index)
{
return const_cast<T&>(static_cast<const vec&>(*this)[index]);
}
const T& operator[](size_t index) const
{
assert(index < 4);
return c[index];
}
vec operator-() const
{
return neg();
}
vec& operator+=(const vec& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
w += rhs.w;
return *this;
}
vec& operator-=(const vec& rhs)
{
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
w -= rhs.w;
return *this;
}
vec& operator*=(const T& rhs)
{
x *= rhs;
y *= rhs;
z *= rhs;
w *= rhs;
return *this;
}
vec& operator/=(const T & rhs)
{
x /= rhs;
y /= rhs;
z /= rhs;
w /= rhs;
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dim() const { return 4; }
vec neg() const
{
// TODO: Issue when the underlying type is an unsigned integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4146)
#endif
return vec(-x, -y, -z, -w);
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
T mag() const
{
// TODO: Might want this method to return a float even if the underlying
// data type is integer.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4244)
#endif
#if (defined(_MSC_VER) && _MSC_VER <= 1600)
// HACK: Visual Studio 2010 has trouble determining the correct 'sqrt'
// function for the template int32_t.
return sqrt(static_cast<float>(x*x + y*y + z*z + w*w));
#else
// HACK:
return sqrt(static_cast<float>(x*x + y*y + z*z + w*w));
//return sqrt(x*x + y*y + z*z + w*w);
#endif
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
}
vec add(const vec& toAdd) const
{
return vec(x + toAdd.x, y + toAdd.y, z + toAdd.z, w + toAdd.w);
}
vec sub(const vec& to_sub) const
{
return vec(x - to_sub.x, y - to_sub.y, z - to_sub.z, w - to_sub.w);
}
vec mult(const double& scalar) const
{
return vec(x * scalar, y * scalar, z * scalar, w * scalar);
}
vec div(const double& scalar) const
{
return vec(x / scalar, y / scalar, z / scalar, w / scalar);
}
vec norm() const
{
T m = mag();
return vec(x / m, y / m, z / m, w / m);
}
T dot(const vec& rhs) const
{
return x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w;
}
};
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
// Operator Overloads /////////////////////////////////////////////////////////
template <size_t tdim, typename T>
vec<tdim, T> operator+(vec<tdim, T> lhs, const vec<tdim, T>& rhs)
{
lhs += rhs;
return lhs;
}
template <size_t tdim, typename T>
vec<tdim, T> operator-(vec<tdim, T> lhs, const vec<tdim, T>& rhs)
{
lhs -= rhs;
return lhs;
}
#if defined(_MSC_VER)
#pragma warning(push)
// The operator* and operator/ throw a warning when a vec*f is multiplied by a double.
#pragma warning(disable:4244)
#endif
template <size_t tdim, typename T, typename S>
vec<tdim, T> operator*(vec<tdim, T> lhs, const S& rhs)
{
lhs *= rhs;
return lhs;
}
template <size_t tdim, typename T, typename S>
vec<tdim, T> operator*(const S& rhs, vec<tdim, T> lhs)
{
lhs *= rhs;
return lhs;
}
template <size_t tdim, typename T, typename S>
vec<tdim, T> operator/(vec<tdim, T> lhs, const S& rhs)
{
lhs /= rhs;
return lhs;
}
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
// Specific Typedefs //////////////////////////////////////////////////////////
typedef vec<2> vec2;
typedef vec<3> vec3;
typedef vec<4> vec4;
typedef vec<2, float> vec2f;
typedef vec<3, float> vec3f;
typedef vec<4, float> vec4f;
typedef vec<2, double> vec2d;
typedef vec<3, double> vec3d;
typedef vec<4, double> vec4d;
typedef vec<2, long double> vec2ld;
typedef vec<3, long double> vec3ld;
typedef vec<4, long double> vec4ld;
typedef vec<2, int32_t> vec2i32;
typedef vec2i32 ivec2;
typedef vec<3, int32_t> vec3i32;
typedef vec<4, int32_t> vec4i32;
typedef vec<2, uint32_t> vec2u32;
typedef vec<3, uint32_t> vec3u32;
typedef vec<4, uint32_t> vec4u32;
// Common functions for working with vectors.
template <size_t tdim, typename T> std::string str(vec<tdim, T> v)
{
std::stringstream ss;
ss << "(";
for (size_t i = 0; i < v.dim(); i++)
{
ss << v[i];
if (i + 1 < v.dim())
ss << "; ";
}
ss << ")";
return ss.str();
}
template <size_t tdim, typename T> std::ostream& operator<<(std::ostream& out, vec<tdim, T> v)
{
out << str(v);
return out;
}
}
}
#endif
vn::math::vec< 3, T >::z
T z
Z (2-component).
Definition: vector.h:569
vn::math::vec< 3, T >::operator*=
vec & operator*=(const T &rhs)
Multiplies the vector by a scalar.
Definition: vector.h:720
vn::math::vec
Template for a Euclidean vector.
Definition: vector.h:22
vn::math::vec::operator[]
T & operator[](size_t index)
Indexing into the vector's components.
Definition: vector.h:74
vn::math::vec< 3, T >::dot
T dot(const vec &rhs) const
Computes the dot product of this and the provided vector.
Definition: vector.h:844
vn::math::vec::dot
T dot(const vec &rhs) const
Computes the dot product of this and the provided vector.
Definition: vector.h:256
vn::math::vec< 3, T >::operator+=
vec & operator+=(const vec &rhs)
Adds a vector to this vector.
Definition: vector.h:696
vn::math::vec< 4, T >::w
T w
W (3-component).
Definition: vector.h:890
vn::math::vec< 2, T >::operator[]
const T & operator[](size_t index) const
Indexing into the vector's components.
Definition: vector.h:374
vn::math::vec< 4, T >
Vector with 4 component specialization.
Definition: vector.h:869
vn::math::vec< 4, T >::z
T z
Z (2-component).
Definition: vector.h:887
vn::math::vec::vec
vec(T val)
Creates new vector with components initialized to val.
Definition: vector.h:41
vn::math::vec< 3, T >::operator[]
const T & operator[](size_t index) const
Indexing into the vector's components.
Definition: vector.h:677
int.h
vn::math::vec< 3, T >::operator/=
vec & operator/=(const T &rhs)
Divides the vector by a scalar.
Definition: vector.h:732
vn::math::vec< 3, T >::operator[]
T & operator[](size_t index)
Indexing into the vector's components.
Definition: vector.h:668
vn::math::vec< 4, T >::mult
vec mult(const double &scalar) const
Multiplies the vector by a scalar.
Definition: vector.h:1162
vn::math::vec::sub
vec sub(const vec &to_sub) const
Subtracts a vector from this vector.
Definition: vector.h:199
vn::math::vec::dim
size_t dim() const
The vector's dimension.
Definition: vector.h:153
vn::math::vec< 4, T >::vec
vec(T val)
Creates new vector with components initialized to val.
Definition: vector.h:936
vn::math::vec< 4, T >::unitX
static vec unitX()
Unit vector pointing in the X (0-component) direction.
Definition: vector.h:970
vn::math::vec< 4, T >::dot
T dot(const vec &rhs) const
Computes the dot product of this and the provided vector.
Definition: vector.h:1190
vn::math::vec::div
vec div(const double &scalar) const
Divides the vector by a scalar.
Definition: vector.h:227
vn::math::vec< 3, T >::vec
vec(const T &x_val, const T &y_val, const T &z_val)
Creates a new vector with its components initialized to the provided values.
Definition: vector.h:614
vn::math::vec< 2, T >::sub
vec sub(const vec &to_sub) const
Subtracts a vector from this vector.
Definition: vector.h:504
vn::math::vec< 4, T >::dim
size_t dim() const
The vector's dimension.
Definition: vector.h:1093
vn::math::vec< 3, T >::vec
vec(T val)
Creates new vector with components initialized to val.
Definition: vector.h:606
vn::math::vec< 3, T >::y
T y
Y (1-component).
Definition: vector.h:566
vn::math::vec< 2, T >::one
static vec one()
Vector with all of its components set to 1.
Definition: vector.h:335
vn::math::vec< 4, T >::operator+=
vec & operator+=(const vec &rhs)
Adds a vector to this vector.
Definition: vector.h:1034
vn::math::vec::operator/=
vec & operator/=(const T &rhs)
Divides the vector by a scalar.
Definition: vector.h:138
vn::math::vec< 2, T >::vec
vec(T x_val, T y_val)
Creates a new vector with its components inintialized to the provided values.
Definition: vector.h:318
vn::math::vec< 4, T >::mag
T mag() const
The vector's magnitude.
Definition: vector.h:1116
vn::math::vec< 4, T >::r
T r
Red (0-component).
Definition: vector.h:896
vn::math::vec::neg
vec neg() const
Negates the vector.
Definition: vector.h:158
vn::math::vec< 4, T >::norm
vec norm() const
Normalizes the vector.
Definition: vector.h:1179
vn::math::vec< 3, T >::unitZ
static vec unitZ()
Unit vector pointing in the Z (2-component) direction.
Definition: vector.h:655
vn::math::vec< 4, T >::operator[]
const T & operator[](size_t index) const
Indexing into the vector's components.
Definition: vector.h:1015
vn::math::vec< 4, T >::unitY
static vec unitY()
Unit vector pointing in the Y (1-component) direction.
Definition: vector.h:978
vn::math::vec< 2, T >::add
vec add(const vec &toAdd) const
Adds a vector to this vector.
Definition: vector.h:495
vn::math::vec< 3, T >::sub
vec sub(const vec &to_sub) const
Subtracts a vector from this vector.
Definition: vector.h:807
vn::math::vec< 4, T >::y
T y
Y (1-component).
Definition: vector.h:884
vn::math::vec< 3, T >::unitY
static vec unitY()
Unit vector pointing in the Y (1-component) direction.
Definition: vector.h:647
vn::math::vec< 2, T >::operator-
vec operator-() const
Negates the vector.
Definition: vector.h:384
vn::math::vec< 2, T >::div
vec div(const double &scalar) const
Divides the vector by a scalar.
Definition: vector.h:522
vn::math::vec< 3, T >::mag
T mag() const
The vector's magnitude.
Definition: vector.h:770
vn::math::vec< 4, T >::div
vec div(const double &scalar) const
Divides the vector by a scalar.
Definition: vector.h:1171
vn::math::vec< 4, T >::operator*=
vec & operator*=(const T &rhs)
Multiplies the vector by a scalar.
Definition: vector.h:1062
vn::math::vec< 2, T >::vec
vec()
Creates a new vector with uninitialized components.
Definition: vector.h:306
vn::math::vec< 2, T >::dot
T dot(const vec &rhs) const
Computes the dot product of this and the provided vector.
Definition: vector.h:541
vn::math::vec< 3, T >
Vector with 3 component specialization.
Definition: vector.h:551
vn::math::vec< 2, T >::dim
size_t dim() const
The vector's dimension.
Definition: vector.h:444
vn::math::vec< 3, T >::mult
vec mult(const double &scalar) const
Multiplies the vector by a scalar.
Definition: vector.h:816
vn::math::vec< 3, T >::dim
size_t dim() const
The vector's dimension.
Definition: vector.h:747
vn::math::vec< 4, T >::g
T g
Green (1-component).
Definition: vector.h:899
vn::math::vec< 4, T >::neg
vec neg() const
Negates the vector.
Definition: vector.h:1098
vn::math::vec< 2, T >::vec
vec(T val)
Creates new vector with components initialized to val.
Definition: vector.h:311
vn::math::vec< 2, T >::mult
vec mult(const double &scalar) const
Multiplies the vector by a scalar.
Definition: vector.h:513
vn::math::vec< 3, T >::x
T x
X (0-component).
Definition: vector.h:563
exceptions.h
vn::math::vec::c
T c[tdim]
The vector's components.
Definition: vector.h:29
vn::math::vec< 4, T >::b
T b
Blue (2-component).
Definition: vector.h:902
vn::math::vec::one
static vec one()
Vector with all of its components set to 1.
Definition: vector.h:61
vn::math::vec< 2, T >::operator+=
vec & operator+=(const vec &rhs)
Adds a vector to this vector.
Definition: vector.h:393
vn::math::vec< 3, T >::div
vec div(const double &scalar) const
Divides the vector by a scalar.
Definition: vector.h:825
vn::math::vec< 4, T >::vec
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.
Definition: vector.h:945
vn::math::vec::mag
T mag() const
The vector's magnitude.
Definition: vector.h:171
vn::math::vec< 4, T >::operator/=
vec & operator/=(const T &rhs)
Divides the vector by a scalar.
Definition: vector.h:1076
vn::math::vec< 3, T >::g
T g
Green (1-component).
Definition: vector.h:578
vn::math::vec< 4, T >::zero
static vec zero()
Vector with all of its components set to 0.
Definition: vector.h:954
vn::math::vec< 4, T >::operator[]
T & operator[](size_t index)
Indexing into the vector's components.
Definition: vector.h:1006
vn::math::vec::norm
vec norm() const
Normalizes the vector.
Definition: vector.h:240
vn::math::vec< 3, T >::zero
static vec zero()
Vector with all of its components set to 0.
Definition: vector.h:623
vn::math::vec< 4, T >::unitZ
static vec unitZ()
Unit vector pointing in the Z (2-component) direction.
Definition: vector.h:986
vn::math::vec::vec
vec()
Creates a new vector with uninitialized components.
Definition: vector.h:36
vn::math::vec< 3, T >::b
T b
Blue (2-component).
Definition: vector.h:581
vn::math::vec< 3, T >::operator-=
vec & operator-=(const vec &rhs)
Subtracts a vector from this vector.
Definition: vector.h:708
vn::math::vec< 2, T >::operator*=
vec & operator*=(const T &rhs)
Multiplies the vector by a scalar.
Definition: vector.h:417
vn::math::vec::operator+=
vec & operator+=(const vec &rhs)
Adds a vector to this vector.
Definition: vector.h:102
vn::math::vec< 2, T >::zero
static vec zero()
Vector with all of its components set to 0.
Definition: vector.h:327
vn::math::vec< 4, T >::x
T x
X (0-component).
Definition: vector.h:881
vn::math::vec::operator-
vec operator-() const
Negates the vector.
Definition: vector.h:93
vn::math::vec< 2, T >::unitX
static vec unitX()
Unit vector pointing in the X (0-component) direction.
Definition: vector.h:343
vn::math::vec< 2, T >::operator-=
vec & operator-=(const vec &rhs)
Subtracts a vector from this vector.
Definition: vector.h:405
vn::math::vec< 2, T >::unitY
static vec unitY()
Unit vector pointing in the Y (1-component) direction.
Definition: vector.h:351
vn::math::vec::mult
vec mult(const double &scalar) const
Multiplies the vector by a scalar.
Definition: vector.h:213
vn::math::vec< 2, T >::y
T y
Y (1-component).
Definition: vector.h:294
vn::math::vec< 2, T >::operator[]
T & operator[](size_t index)
Indexing into the vector's components.
Definition: vector.h:365
vn::math::vec< 3, T >::cross
vec< 3, T > cross(const vec< 3, T > &rhs) const
Computes the cross product of this and the provided vector.
Definition: vector.h:854
vn::math::vec< 4, T >::vec
vec()
Creates a new vector with uninitialized components.
Definition: vector.h:931
vn::math::vec< 3, T >::norm
vec norm() const
Normalizes the vector.
Definition: vector.h:833
vn::math::vec< 3, T >::c
T c[3]
The vector's components.
Definition: vector.h:593
vn::math::vec::zero
static vec zero()
Vector with all of its components set to 0.
Definition: vector.h:53
vn::math::vec< 2, T >::neg
vec neg() const
Negates the vector.
Definition: vector.h:449
vn
Definition: attitude.h:8
vn::math::vec< 2, T >
Vector with 2 component specialization.
Definition: vector.h:279
vn::math::vec::operator[]
const T & operator[](size_t index) const
Indexing into the vector's components.
Definition: vector.h:83
vn::math::vec< 4, T >::add
vec add(const vec &toAdd) const
Adds a vector to this vector.
Definition: vector.h:1144
vn::math::vec< 4, T >::unitW
static vec unitW()
Unit vector pointing in the W (3-component) direction.
Definition: vector.h:994
vn::math::vec< 3, T >::unitX
static vec unitX()
Unit vector pointing in the X (0-component) direction.
Definition: vector.h:639
vn::math::vec< 3, T >::vec
vec()
Creates a new vector with uninitialized components.
Definition: vector.h:601
vn::math::vec< 2, T >::x
T x
X (0-component).
Definition: vector.h:291
vn::math::vec< 3, T >::operator-
vec operator-() const
Negates the vector.
Definition: vector.h:687
vn::math::vec< 3, T >::neg
vec neg() const
Negates the vector.
Definition: vector.h:752
vn::math::vec< 4, T >::a
T a
Alpha (3-component).
Definition: vector.h:905
vn::math::vec< 4, T >::sub
vec sub(const vec &to_sub) const
Subtracts a vector from this vector.
Definition: vector.h:1153
vn::math::vec< 2, T >::operator/=
vec & operator/=(const T &rhs)
Divides the vector by a scalar.
Definition: vector.h:429
vn::math::vec< 2, T >::mag
T mag() const
The vector's magnitude.
Definition: vector.h:467
vn::math::vec::operator*=
vec & operator*=(const T &rhs)
Multiplies the vector by a scalar.
Definition: vector.h:126
vn::math::vec< 4, T >::one
static vec one()
Vector with all of its components set to 1.
Definition: vector.h:962
vn::math::vec< 2, T >::norm
vec norm() const
Normalizes the vector.
Definition: vector.h:530
vn::math::vec< 3, T >::one
static vec one()
Vector with all of its components set to 1.
Definition: vector.h:631
vn::math::vec< 4, T >::operator-=
vec & operator-=(const vec &rhs)
Subtracts a vector from this vector.
Definition: vector.h:1048
vn::math::vec::add
vec add(const vec &toAdd) const
Adds a vector to this vector.
Definition: vector.h:185
vn::math::vec< 3, T >::add
vec add(const vec &toAdd) const
Adds a vector to this vector.
Definition: vector.h:798
vn::math::vec::operator-=
vec & operator-=(const vec &rhs)
Subtracts a vector from this vector.
Definition: vector.h:114
vn::math::vec< 3, T >::r
T r
Red (0-component).
Definition: vector.h:575
vn::math::vec< 4, T >::operator-
vec operator-() const
Negates the vector.
Definition: vector.h:1025