Isis 3.0
Home
LinearAlgebra.h
Go to the documentation of this file.
1 #ifndef LinearAlgebra_h
2 #define LinearAlgebra_h
3 
25 // std library
26 #include <iostream>
27 
28 // boost library
29 #include <boost/numeric/ublas/matrix.hpp>
30 #include <boost/numeric/ublas/io.hpp>
31 
32 // Qt Library
33 #include <QDebug>
34 #include <QPair>
35 
36 // Prevent Boost from outputing debug information to
37 // standard error when throwing exceptions.
38 #define BOOST_UBLAS_NO_STD_CERR
39 
40 namespace Isis {
41  class Angle;
42  class Distance;
43  class Latitude;
44  class Longitude;
104  public:
114  typedef boost::numeric::ublas::matrix<double> Matrix;
124  typedef boost::numeric::ublas::vector<double> Vector;
125 
126  // define AxisAngle and EulerAngle
141 
142  // check type of matrix/vector
143  static bool isIdentity(const Matrix &matrix);
144  static bool isOrthogonal(const Matrix &matrix);
145  static bool isRotationMatrix(const Matrix &matrix);
146  static bool isZero(const Matrix &matrix);
147  static bool isZero(const Vector &vector);
148  static bool isEmpty(const Vector &vector);
149  static bool isUnit(const Vector &vector);
150 
151  // create special matrices
152  static Matrix identity(int size);
153  static Matrix transpose(const Matrix &matrix);
154  static Matrix inverse(const Matrix &matrix);
155  static Matrix zeroMatrix(int rows, int columns);
156  static Vector zeroVector(int size);
157 
158  //
159  static double determinant(const Matrix &matrix);
160 
161  // magnitude/norm based calculations
162  static Vector normalize(const Vector &vector);
163  static double magnitude(const Vector &vector);
164  static double absoluteMaximum(const Vector &vector);
165 
166  // arithmetic operations
167  static Matrix multiply(const Matrix &matrix1, const Matrix &matrix2);
168  static Vector multiply(const Matrix &matrix, const Vector &vector);
169  static Vector multiply(double scalar, const Vector &vector);
170  static Matrix multiply(double scalar, const Matrix &matrix);
171  static Vector add(const Vector &vector1, const Vector &vector2);
172  static Vector subtract(const Vector &vector1, const Vector &vector2);
173 
174  // vector products
175  static Vector crossProduct(const Vector &vector1, const Vector &vector2);
176  static Vector normalizedCrossProduct(const Vector &vector1, const Vector &vector2);
177  static Matrix outerProduct(const Vector &vector1, const Vector &vector2);
178  static double dotProduct(const Vector &vector1, const Vector &vector2);
179  static double innerProduct(const Vector &vector1, const Vector &vector2);
180 
181  // vector movements (projections, rotations)
182  static Vector project(const Vector &vector1, const Vector &vector2);
183  static Vector rotate(const Vector &vector, const Vector &axis, Angle angle);
184 
185  //
186  static Vector perpendicular(const Vector &vector1, const Vector &vector2);
187 
188  // converters
189  static AxisAngle toAxisAngle(const Matrix &rotationMatrix);//raxisa
190  static Matrix toMatrix(const AxisAngle &axisAngle); // axisar
191  static Matrix toMatrix(const Vector &axis, Angle angle); // axisar
192 
193  static QList<EulerAngle> toEulerAngles(const Matrix &rotationMatrix, const QList<int> axes);// m2eul
194  static Matrix toMatrix(const QList<EulerAngle> &eulerAngles); // eul2m
195  static Matrix toMatrix(const EulerAngle &angle3, const EulerAngle &angle2, const EulerAngle &angle1); // eul2m
196 
197  static Vector toQuaternion(const Matrix &rotationMatrix);// m2q
198  static Matrix toMatrix(const Vector &quaternion);// q2m
199 
200  //Matrix row/col to vector and vector to row/columns
201  static void setRow(Matrix &matrix, const Vector &vector, int rowIndex);
202  static void setColumn(Matrix &matrix, const Vector &vector, int columnIndex);
203  static Vector row(const Matrix &matrix, int rowIndex);
204  static Vector column(const Matrix &matrix, int columnIndex);
205 
206  static void setVec3(Vector *v, double v0, double v1, double v2);
207  static void setVec4(Vector *v, double v0, double v1, double v2, double v3);
208  static Vector vector(double v0, double v1, double v2);
209  static Vector vector(double v0, double v1, double v2, double v3);
210 
211  static Vector subVector(const Vector &v, int start, int size);
212 
213  // No need to implement the std::cout operator<< since this is already
214  // done in boost/numeric/ublas/io.hpp, which is included above
215  // The print format for a size 3 vector is
216  // [3] (1, 2, 3)
217  //
218  // friend ostream &operator<<(ostream &os, LinearAlgebra::Vector &vector);
219 
220  protected:
221  LinearAlgebra();
222  ~LinearAlgebra();
223 
224  private:
225  };
226 
227  // these must be declared outside of the class (at the end since they must be
228  // declared after the typedefs)
229  QDebug operator<<(QDebug dbg, const LinearAlgebra::Vector &vector);
230  QDebug operator<<(QDebug dbg, const LinearAlgebra::Matrix &matrix);
231  QString toString(const LinearAlgebra::Vector &vector, int precision=15);
232 };
233 
234 #endif
235 
static Vector project(const Vector &vector1, const Vector &vector2)
Compute the vector projection of vector1 onto vector2.
Definition: LinearAlgebra.cpp:815
static Vector vector(double v0, double v1, double v2)
Constructs a 3 dimensional vector with the given component values.
Definition: LinearAlgebra.cpp:1696
static double innerProduct(const Vector &vector1, const Vector &vector2)
Computes the inner product of the given vectors.
Definition: LinearAlgebra.cpp:783
static Matrix transpose(const Matrix &matrix)
Returns the transpose of the given matrix.
Definition: LinearAlgebra.cpp:351
static Vector subtract(const Vector &vector1, const Vector &vector2)
Subtracts the right vector from the left vector.
Definition: LinearAlgebra.cpp:642
static bool isRotationMatrix(const Matrix &matrix)
Determines whether the given matrix is a rotation matrix.
Definition: LinearAlgebra.cpp:125
static bool isIdentity(const Matrix &matrix)
Determines whether the given matrix is the identity.
Definition: LinearAlgebra.cpp:73
static Vector column(const Matrix &matrix, int columnIndex)
Returns a vector whose components match those of the given matrix column.
Definition: LinearAlgebra.cpp:1675
static Matrix multiply(const Matrix &matrix1, const Matrix &matrix2)
Returns the product of two matrices.
Definition: LinearAlgebra.cpp:531
static double magnitude(const Vector &vector)
Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm)...
Definition: LinearAlgebra.cpp:486
static Vector toQuaternion(const Matrix &rotationMatrix)
Converts a rotation&#39;s representation from a matrix to a unit quaternion.
Definition: LinearAlgebra.cpp:1193
static Vector rotate(const Vector &vector, const Vector &axis, Angle angle)
Rotates a vector about an axis vector given a specified angle.
Definition: LinearAlgebra.cpp:854
static Vector subVector(const Vector &v, int start, int size)
Constructs a vector of given size using the given vector and starting index.
Definition: LinearAlgebra.cpp:1771
LinearAlgebra()
Default constructor for a LinearAlgebra object.
Definition: LinearAlgebra.cpp:52
static void setColumn(Matrix &matrix, const Vector &vector, int columnIndex)
Sets the column of the given matrix to the values of the given vector.
Definition: LinearAlgebra.cpp:1629
boost::numeric::ublas::matrix< double > Matrix
Definition for an Isis::LinearAlgebra::Matrix of doubles.
Definition: LinearAlgebra.h:114
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:226
static Vector normalize(const Vector &vector)
Returns a unit vector that is codirectional with the given vector by dividing each component of the v...
Definition: LinearAlgebra.cpp:459
static Matrix zeroMatrix(int rows, int columns)
Returns a matrix with given dimensions that is filled with zeroes.
Definition: LinearAlgebra.cpp:390
static double dotProduct(const Vector &vector1, const Vector &vector2)
Computes the dot product of the given vectors.
Definition: LinearAlgebra.cpp:763
static Matrix outerProduct(const Vector &vector1, const Vector &vector2)
Computes the outer product of the given vectors.
Definition: LinearAlgebra.cpp:739
static Matrix toMatrix(const AxisAngle &axisAngle)
Converts a rotation&#39;s representation from an axis of rotation and its corresponding rotation angle to...
Definition: LinearAlgebra.cpp:1424
static Vector add(const Vector &vector1, const Vector &vector2)
Adds the two given vectors.
Definition: LinearAlgebra.cpp:616
boost::numeric::ublas::vector< double > Vector
Definition for an Isis::LinearAlgebra::Vector of doubles.
Definition: LinearAlgebra.h:124
static QList< EulerAngle > toEulerAngles(const Matrix &rotationMatrix, const QList< int > axes)
Converts a rotation&#39;s representation from a matrix to a set of Euler angles with corresponding axes...
Definition: LinearAlgebra.cpp:1033
static bool isEmpty(const Vector &vector)
Determines whether the given vector is empty (i.e.
Definition: LinearAlgebra.cpp:262
static Vector row(const Matrix &matrix, int rowIndex)
Returns a vector whose components match those of the given matrix row.
Definition: LinearAlgebra.cpp:1652
QPair< Vector, Angle > AxisAngle
Definition for an Axis-Angle pair.
Definition: LinearAlgebra.h:133
static Matrix inverse(const Matrix &matrix)
Returns the inverse of a 2x2 or 3x3 matrix.
Definition: LinearAlgebra.cpp:294
static AxisAngle toAxisAngle(const Matrix &rotationMatrix)
Converts a rotation&#39;s representation from a matrix to a axis of rotation and its corresponding rotati...
Definition: LinearAlgebra.cpp:955
static bool isZero(const Matrix &matrix)
Determines whether the given matrix is filled with zereos.
Definition: LinearAlgebra.cpp:223
static double determinant(const Matrix &matrix)
Returns the determinant of the given 3x3 matrix.
Definition: LinearAlgebra.cpp:422
static Matrix identity(int size)
Returns the identity matrix of size NxN.
Definition: LinearAlgebra.cpp:366
static Vector zeroVector(int size)
Returns a vector of given length that is filled with zeroes.
Definition: LinearAlgebra.cpp:403
static void setRow(Matrix &matrix, const Vector &vector, int rowIndex)
Sets the row of the given matrix to the values of the given vector.
Definition: LinearAlgebra.cpp:1608
static void setVec4(Vector *v, double v0, double v1, double v2, double v3)
Fills the first four elements of the given vector with the given values.
Definition: LinearAlgebra.cpp:1750
static Vector normalizedCrossProduct(const Vector &vector1, const Vector &vector2)
Divides each vector by its corresponding absolute maximum, computes the cross product of the new vect...
Definition: LinearAlgebra.cpp:703
static bool isUnit(const Vector &vector)
Determines whether the given vector is a unit vector.
Definition: LinearAlgebra.cpp:274
Defines an angle and provides unit conversions.
Definition: Angle.h:58
This class holds all static methods to perform linear algebra operations on vectors and matrices...
Definition: LinearAlgebra.h:103
Definition: BoxcarCachingAlgorithm.h:29
QPair< Angle, int > EulerAngle
Definition for an EulerAngle pair.
Definition: LinearAlgebra.h:140
static bool isOrthogonal(const Matrix &matrix)
Determines whether the given matrix is orthogonal by verifying that the matrix and its tranpose are i...
Definition: LinearAlgebra.cpp:101
static Vector crossProduct(const Vector &vector1, const Vector &vector2)
Returns the cross product of two vectors.
Definition: LinearAlgebra.cpp:670
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Definition: Hillshade.cpp:308
Definition: CubeIoHandler.h:39
~LinearAlgebra()
Destructor for a LinearAlgebra object.
Definition: LinearAlgebra.cpp:59
static void setVec3(Vector *v, double v0, double v1, double v2)
Fills the first three elements of the given vector with the given values.
Definition: LinearAlgebra.cpp:1734
static double absoluteMaximum(const Vector &vector)
Returns the maximum norm (L-infinity norm) for the given vector.
Definition: LinearAlgebra.cpp:513
static Vector perpendicular(const Vector &vector1, const Vector &vector2)
Finds the unique vector P such that A = V + P, V is parallel to B and P is perpendicular to B...
Definition: LinearAlgebra.cpp:914