#include <vector.h>
Public Types | |
typedef T | ScalType |
Public Member Functions | |
T * | array () |
const T * | array () const |
void | cross (const Vector< T, Size > &other, Vector< T, Size > *res) const |
Vector< T, Size > | cross (const Vector< T, Size > &other) const |
T | dot (const Vector< T, Size > &other) const |
bool | hasDynamicSize () const |
bool | isApprox (const Vector< T, Size > &other, const T &precision=Util::epsilon< T >()) const |
bool | isNegligible (const Vector< T, Size > &other, const T &precision=Util::epsilon< T >()) const |
bool | isNegligible (const T &other, const T &precision=Util::epsilon< T >()) const |
bool | isZero (const T &precision=Util::epsilon< T >()) const |
Vector< T, Size > & | loadOrtho (const Vector< T, Size > &other) |
Vector< T, Size > & | loadRandom () |
Vector< T, Size > & | loadRandomUnit () |
Vector< T, Size > & | loadZero () |
Vector< T, Size > & | makeOrthoVector (Vector< T, Size > *res) const |
T | norm () const |
T | norm2 () const |
Vector< T, Size > & | normalize () |
Vector< T, Size > | normalized () |
bool | operator!= (const Vector< T, Size > &other) const |
T & | operator() (int i) |
const T & | operator() (int i) const |
Vector< T, Size > | operator* (const T &factor) const |
Vector & | operator*= (const T &factor) |
Vector< T, Size > | operator+ (const Vector< T, Size > &other) const |
Vector< T, Size > & | operator+= (const Vector< T, Size > &other) |
Vector & | operator+= (const Vector &other) |
Vector< T, Size > | operator- () const |
Vector< T, Size > | operator- (const Vector< T, Size > &other) const |
Vector< T, Size > & | operator-= (const Vector< T, Size > &other) |
Vector & | operator-= (const Vector &other) |
Vector< T, Size > | operator/ (const T &factor) const |
Vector & | operator/= (const T &factor) |
Vector & | operator= (const Vector &other) |
bool | operator== (const Vector< T, Size > &other) const |
T & | operator[] (int i) |
const T & | operator[] (int i) const |
Vector< T, Size > | ortho () const |
void | readArray (const T *src) |
void | replaceWithOpposite () |
void | resize (int newsize) |
int | size () const |
Vector (T x, T y, T z, T w) | |
Vector (T x, T y, T z) | |
Vector (T x, T y) | |
Vector (int unused_size, const T *array) | |
Vector (const T *array) | |
Vector (const Vector &v) | |
Vector (int unused_size) | |
Vector () | |
const T & | w () const |
T & | w () |
const T & | x () const |
T & | x () |
const T & | y () const |
T & | y () |
const T & | z () const |
T & | z () |
Protected Attributes | |
T | m_array [Size] |
A class for fixed-size vectors (for linear algebra). Thus, a Vector<T,Size> is the same as a T[Size] array, except that it has convenient operators and methods for basic vector math.
The template parameter T is the type of the coords of the vector. It can be any type representing either real or complex numbers. The template parameter Size is the size of the vector (number of coords). The following typedefs are provided to cover the usual cases:
typedef Vector<double, 2> Vector2d; typedef Vector<double, 3> Vector3d; typedef Vector<double, 4> Vector4d; typedef Vector<float, 2> Vector2f; typedef Vector<float, 3> Vector3f; typedef Vector<float, 4> Vector4f; typedef Vector<std::complex<double>, 2> Vector2cd; typedef Vector<std::complex<double>, 3> Vector3cd; typedef Vector<std::complex<double>, 4> Vector4cd; typedef Vector<std::complex<float>, 2> Vector2cf; typedef Vector<std::complex<float>, 3> Vector3cf; typedef Vector<std::complex<float>, 4> Vector4cf;
If you prefer dynamic-size vectors (they are slower), see the VectorX class template, which provides exactly the same functionality and API in dynamic-size version.
The Vector class template provides all the usual operators and methods to manipulate vectors.
Here are some examples of usage of Vector:
using namespace Eigen; using namespace std; // we'll use cout for outputting vectors Vector3d vec1( -1.1, 2.9, 4.3 ); // construct vector vec1 with given coords double array[3] = { 2.4, 3.1, -0.7 }; Vector3d vec2( array ); // reads the coords of vec2 from array2 vec1 += vec2; // computes the coord-wise sum vec1 + vec2, stores it in vec1 vec1 = vec1 - vec2; // there are also non-assignment operators vec1 = 0.9 * vec1 + vec2 / 2.6; // you can also multiply/divide by numbers vec1.x() = vec2.y() // read-write access to the x,y,z,w coords vec1(2) = -1.4; // Stores the value -1.4 in coord 2 of vec1. vec1.z() = -1.4; // equivalent to the previous line cout << vec1 << endl; // outputs vec1 cout << "norm of vec1: " << vec1.norm() << endl; cout << cross( vec1, vec2 ) << endl; // cross-product
typedef T ScalType [inherited] |
Vector | ( | ) | [inline] |
Default constructor. Constructs a vector with uninitialized coords.
Vector | ( | int | unused_size | ) | [inline, explicit] |
Convenience constructor provided for API homogeneity with VectorX. The unused_size argument is not used.
Vector | ( | const T * | array | ) | [inline] |
Constructor reading the coords from an array.
Vector | ( | int | unused_size, | |
const T * | array | |||
) | [inline] |
Convenience constructor provided for API homogeneity with VectorX. Constructor reading the coords from an array. The unused_size argument is not used.
Vector | ( | T | x, | |
T | y | |||
) | [inline] |
Convenience constructor for vectors of size 2.
Vector | ( | T | x, | |
T | y, | |||
T | z | |||
) | [inline] |
Convenience constructor for vectors of size 3.
Vector | ( | T | x, | |
T | y, | |||
T | z, | |||
T | w | |||
) | [inline] |
Convenience constructor for vectors of size 4.
T * array | ( | ) | [inline, inherited] |
const T * array | ( | ) | const [inline, inherited] |
Returns the array of the vector, as constant.
Sets *res to be the cross product of *this by other. *this and other must have size exactly 3.
In fixed-size, *res must also have size 3. In dynamic-size, *res gets resized to size 3 if necessary.
Returns the cross product of *this by other. *this and other must have size exactly 3.
This method returns an object by value, which is inefficient. For better performance, use cross(const Derived &, Derived *) const
T dot | ( | const Vector< T, Size > & | other | ) | const [inherited] |
Returns the dot product of *this by other.
*this and other must have the same size (the compiler will check that for fixed-size vectors, but not for dynamic-size vectors).
If T is std::complex, the dot product is hermitian, i.e. the coords of *this get complex-conjugated in the formula.
bool hasDynamicSize | ( | ) | const [inline, inherited] |
bool isApprox | ( | const Vector< T, Size > & | other, | |
const T & | precision = Util::epsilon<T>() | |||
) | const [inline, inherited] |
Returns true if *this and other are approximately equal.
The optional parameter precision allows to control the number of significant digits of precision. For instance, setting precision to 1e-5 results in a precision of 5 decimal digits.
This test is for nonzero vectors. If either of the two vectors being compared is zero, then it returns true if, and only if the other one is also zero -- which is not what one typically wants.
To compare a vector with the zero vector, i.e. to check whether a vector is approximately zero, use isZero() instead.
bool isNegligible | ( | const Vector< T, Size > & | other, | |
const T & | precision = Util::epsilon<T>() | |||
) | const [inline, inherited] |
Checks whether the vector *this is much smaller than other.
Equivalent to isNegligible( other.norm(), precision ).
bool isNegligible | ( | const T & | other, | |
const T & | precision = Util::epsilon<T>() | |||
) | const [inline, inherited] |
Returns true if all coeffs of *this are smaller (in absolute value) than other*precision. In other words, returns true if all coeffs are much smaller than other. For the meaning of precision, see isApprox().
bool isZero | ( | const T & | precision = Util::epsilon<T>() |
) | const [inline, inherited] |
Tests whether *this is approximately equal to the zero matrix.
Equivalent to isNegligible(1). In other words, returns true if all entries of *this are approximately zero, in the sense that they have absolute value smaller than epsilon.
Loads into *this a unit vector that is orthogonal to other.
The size of other must be at least 2. *this gets resized to have the same size, if it has dynamic size.
If the size is exactly 2, then other points toward the left, other.x() = -y() and other.y() = x(). For dimensions at least 3, it is of course impossible to speak of "pointing toward the left".
Vector< T, Size > & loadRandom | ( | ) | [inherited] |
Sets all coords to random values between -1.0 and 1.0. For complex numbers, both the real and imaginary parts can range from -1.0 to 1.0. The resulting vector can be zero (though that's not going to happen often!)
Vector< T, Size > & loadRandomUnit | ( | ) | [inline, inherited] |
Loads into *this a random unit vector.
Vector< T, Size > & loadZero | ( | ) | [inherited] |
Sets all coords of *this to zero.
Constructs a unit vector that is orthogonal to *this, and stores it into *res.
*res and *this must have the same size, and that size must be at least 2.
T norm | ( | ) | const [inline, inherited] |
Returns the norm of *this, obtained as the square root of norm2().
T norm2 | ( | ) | const [inline, inherited] |
Returns the squared norm of *this, that is, the dot product of *this with itself.
Vector< T, Size > & normalize | ( | ) | [inline, inherited] |
Normalizes *this, that is, divides *this by norm().
Vector< T, Size > normalized | ( | ) | [inline, inherited] |
Returns a normalized copy of *this. In other words, returns (*this) / norm().
This method returns an object by value, which is inefficient.
bool operator!= | ( | const Vector< T, Size > & | other | ) | const [inline, inherited] |
Equivalent to !isApprox() with the default precision.
T & operator() | ( | int | i | ) | [inline, inherited] |
const T & operator() | ( | int | i | ) | const [inline, inherited] |
Vector< T, Size > operator* | ( | const T & | factor | ) | const [inline, inherited] |
Returns *this * factor (multiplication of each coord).
This method returns an object by value, which is inefficient.
Vector& operator*= | ( | const T & | factor | ) | [inline] |
Stores *this * factor into *this (multiplication of each coord).
Reimplemented from VectorBase< T, Vector< T, Size > >.
Returns *this + other (coordinate-wise addition). The vectors *this and other must have the same size.
This method returns an object by value, which is inefficient.
Stores *this + other into *this (coordinate-wise addition).
*this and other must have the same size.
Vector< T, Size > operator- | ( | void | ) | const [inline, inherited] |
Returns (-(*this)).
This method returns an object by value, which is inefficient.
Returns *this - other (coordinate-wise substraction). The vectors *this and other must have the same size.
This method returns an object by value, which is inefficient.
Stores *this - other into *this (coordinate-wise substraction).
*this and other must have the same size.
Vector< T, Size > operator/ | ( | const T & | factor | ) | const [inline, inherited] |
Returns *this / factor (division of each coord).
This method returns an object by value, which is inefficient.
Vector& operator/= | ( | const T & | factor | ) | [inline] |
Stores *this / factor into *this (division of each coord).
Reimplemented from VectorBase< T, Vector< T, Size > >.
bool operator== | ( | const Vector< T, Size > & | other | ) | const [inline, inherited] |
Equivalent to isApprox() with the default precision.
T & operator[] | ( | int | i | ) | [inline, inherited] |
const T & operator[] | ( | int | i | ) | const [inline, inherited] |
Vector< T, Size > ortho | ( | ) | const [inline, inherited] |
Returns a unit vector that is orthogonal to *this.
This method returns an object by value, which is inefficient. For better performance, use loadOrtho() instead.
void readArray | ( | const T * | src | ) | [inherited] |
Reads the coords of *this from an array. The number of entries read from the array is equal to size().
void replaceWithOpposite | ( | ) | [inline, inherited] |
Replaces *this with (-(*this)).
void resize | ( | int | newsize | ) | [inline, inherited] |
Tries to resize the vector. That is only possible if the vector has dynamic size, i.e. is an object of class VectorX. Otherwise, nothing is done.
The vector coords are not kept, they are left with undefined values after resizing.
int size | ( | ) | const [inline, inherited] |
Returns the size (dimension) of the vector.
const T & w | ( | ) | const [inline, inherited] |
Returns a constant reference to the fourth coord of *this.
The size of *this must be at least 4.
T & w | ( | ) | [inline, inherited] |
Returns a reference to the fourth coord of *this.
The size of *this must be at least 4.
const T & x | ( | ) | const [inline, inherited] |
Returns a constant reference to the first coord of *this.
T & x | ( | ) | [inline, inherited] |
Returns a reference to the first coord of *this.
const T & y | ( | ) | const [inline, inherited] |
Returns a constant reference to the second coord of *this.
The size of *this must be at least 2.
T & y | ( | ) | [inline, inherited] |
Returns a reference to the second coord of *this.
The size of *this must be at least 2.
const T & z | ( | ) | const [inline, inherited] |
Returns a constant reference to the third coord of *this.
The size of *this must be at least 3.
T & z | ( | ) | [inline, inherited] |
Returns a reference to the third coord of *this.
The size of *this must be at least 3.
T m_array[Size] [protected] |
The vector's array of coordinates.