Isis 3 Programmer Reference
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;
105  public:
115  typedef boost::numeric::ublas::matrix<double> Matrix;
125  typedef boost::numeric::ublas::symmetric_matrix<double, boost::numeric::ublas::upper> SymmetricMatrix;
135  typedef boost::numeric::ublas::vector<double> Vector;
136 
137  // define AxisAngle and EulerAngle
152 
153  // check type of matrix/vector
154  static bool isIdentity(const Matrix &matrix);
155  static bool isOrthogonal(const Matrix &matrix);
156  static bool isRotationMatrix(const Matrix &matrix);
157  static bool isZero(const Matrix &matrix);
158  static bool isZero(const Vector &vector);
159  static bool isEmpty(const Vector &vector);
160  static bool isUnit(const Vector &vector);
161 
162  // create special matrices
163  static Matrix identity(int size);
164  static Matrix transpose(const Matrix &matrix);
165  static Matrix inverse(const Matrix &matrix);
166  static Matrix zeroMatrix(int rows, int columns);
167  static Vector zeroVector(int size);
168 
169  //
170  static double determinant(const Matrix &matrix);
171 
172  // magnitude/norm based calculations
173  static Vector normalize(const Vector &vector);
174  static double magnitude(const Vector &vector);
175  static double absoluteMaximum(const Vector &vector);
176 
177  // arithmetic operations
178  static Matrix multiply(const Matrix &matrix1, const Matrix &matrix2);
179  static Vector multiply(const Matrix &matrix, const Vector &vector);
180  static Vector multiply(double scalar, const Vector &vector);
181  static Matrix multiply(double scalar, const Matrix &matrix);
182  static Vector add(const Vector &vector1, const Vector &vector2);
183  static Vector subtract(const Vector &vector1, const Vector &vector2);
184 
185  // vector products
186  static Vector crossProduct(const Vector &vector1, const Vector &vector2);
187  static Vector normalizedCrossProduct(const Vector &vector1, const Vector &vector2);
188  static Matrix outerProduct(const Vector &vector1, const Vector &vector2);
189  static double dotProduct(const Vector &vector1, const Vector &vector2);
190  static double innerProduct(const Vector &vector1, const Vector &vector2);
191 
192  // vector movements (projections, rotations)
193  static Vector project(const Vector &vector1, const Vector &vector2);
194  static Vector rotate(const Vector &vector, const Vector &axis, Angle angle);
195 
196  //
197  static Vector perpendicular(const Vector &vector1, const Vector &vector2);
198 
199  // converters
200  static AxisAngle toAxisAngle(const Matrix &rotationMatrix);//raxisa
201  static Matrix toMatrix(const AxisAngle &axisAngle); // axisar
202  static Matrix toMatrix(const Vector &axis, Angle angle); // axisar
203 
204  static QList<EulerAngle> toEulerAngles(const Matrix &rotationMatrix, const QList<int> axes);// m2eul
205  static Matrix toMatrix(const QList<EulerAngle> &eulerAngles); // eul2m
206  static Matrix toMatrix(const EulerAngle &angle3, const EulerAngle &angle2, const EulerAngle &angle1); // eul2m
207 
208  static Vector toQuaternion(const Matrix &rotationMatrix);// m2q
209  static Matrix toMatrix(const Vector &quaternion);// q2m
210 
211  //Matrix row/col to vector and vector to row/columns
212  static void setRow(Matrix &matrix, const Vector &vector, int rowIndex);
213  static void setColumn(Matrix &matrix, const Vector &vector, int columnIndex);
214  static Vector row(const Matrix &matrix, int rowIndex);
215  static Vector column(const Matrix &matrix, int columnIndex);
216 
217  static void setVec3(Vector *v, double v0, double v1, double v2);
218  static void setVec4(Vector *v, double v0, double v1, double v2, double v3);
219  static Vector vector(double v0, double v1, double v2);
220  static Vector vector(double v0, double v1, double v2, double v3);
221 
222  static Vector subVector(const Vector &v, int start, int size);
223 
224  // No need to implement the std::cout operator<< since this is already
225  // done in boost/numeric/ublas/io.hpp, which is included above
226  // The print format for a size 3 vector is
227  // [3] (1, 2, 3)
228  //
229  // friend ostream &operator<<(ostream &os, LinearAlgebra::Vector &vector);
230 
231  protected:
232  LinearAlgebra();
233  ~LinearAlgebra();
234 
235  private:
236  };
237 
238  // these must be declared outside of the class (at the end since they must be
239  // declared after the typedefs)
240  QDebug operator<<(QDebug dbg, const LinearAlgebra::Vector &vector);
241  QDebug operator<<(QDebug dbg, const LinearAlgebra::Matrix &matrix);
242  QString toString(const LinearAlgebra::Vector &vector, int precision=15);
243 };
244 
245 #endif
static Vector project(const Vector &vector1, const Vector &vector2)
Compute the vector projection of vector1 onto vector2.
static Vector vector(double v0, double v1, double v2)
Constructs a 3 dimensional vector with the given component values.
static double innerProduct(const Vector &vector1, const Vector &vector2)
Computes the inner product of the given vectors.
static Matrix transpose(const Matrix &matrix)
Returns the transpose of the given matrix.
static Vector subtract(const Vector &vector1, const Vector &vector2)
Subtracts the right vector from the left vector.
static bool isRotationMatrix(const Matrix &matrix)
Determines whether the given matrix is a rotation matrix.
static bool isIdentity(const Matrix &matrix)
Determines whether the given matrix is the identity.
static Vector column(const Matrix &matrix, int columnIndex)
Returns a vector whose components match those of the given matrix column.
static Matrix multiply(const Matrix &matrix1, const Matrix &matrix2)
Returns the product of two matrices.
static double magnitude(const Vector &vector)
Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm)...
static Vector toQuaternion(const Matrix &rotationMatrix)
Converts a rotation&#39;s representation from a matrix to a unit quaternion.
static Vector rotate(const Vector &vector, const Vector &axis, Angle angle)
Rotates a vector about an axis vector given a specified angle.
static Vector subVector(const Vector &v, int start, int size)
Constructs a vector of given size using the given vector and starting index.
LinearAlgebra()
Default constructor for a LinearAlgebra object.
static void setColumn(Matrix &matrix, const Vector &vector, int columnIndex)
Sets the column of the given matrix to the values of the given vector.
boost::numeric::ublas::matrix< double > Matrix
Definition for an Isis::LinearAlgebra::Matrix of doubles.
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...
static Matrix zeroMatrix(int rows, int columns)
Returns a matrix with given dimensions that is filled with zeroes.
static double dotProduct(const Vector &vector1, const Vector &vector2)
Computes the dot product of the given vectors.
static Matrix outerProduct(const Vector &vector1, const Vector &vector2)
Computes the outer product of the given vectors.
static Matrix toMatrix(const AxisAngle &axisAngle)
Converts a rotation&#39;s representation from an axis of rotation and its corresponding rotation angle to...
static Vector add(const Vector &vector1, const Vector &vector2)
Adds the two given vectors.
boost::numeric::ublas::vector< double > Vector
Definition for an Isis::LinearAlgebra::Vector of doubles.
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...
static bool isEmpty(const Vector &vector)
Determines whether the given vector is empty (i.e.
static Vector row(const Matrix &matrix, int rowIndex)
Returns a vector whose components match those of the given matrix row.
QPair< Vector, Angle > AxisAngle
Definition for an Axis-Angle pair.
static Matrix inverse(const Matrix &matrix)
Returns the inverse of a 2x2 or 3x3 matrix.
static AxisAngle toAxisAngle(const Matrix &rotationMatrix)
Converts a rotation&#39;s representation from a matrix to a axis of rotation and its corresponding rotati...
static bool isZero(const Matrix &matrix)
Determines whether the given matrix is filled with zereos.
static double determinant(const Matrix &matrix)
Returns the determinant of the given 3x3 matrix.
static Matrix identity(int size)
Returns the identity matrix of size NxN.
static Vector zeroVector(int size)
Returns a vector of given length that is filled with zeroes.
static void setRow(Matrix &matrix, const Vector &vector, int rowIndex)
Sets the row of the given matrix to the values of the given vector.
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.
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...
static bool isUnit(const Vector &vector)
Determines whether the given vector is a unit vector.
Defines an angle and provides unit conversions.
Definition: Angle.h:62
This class holds all static methods to perform linear algebra operations on vectors and matrices...
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QPair< Angle, int > EulerAngle
Definition for an EulerAngle pair.
static bool isOrthogonal(const Matrix &matrix)
Determines whether the given matrix is orthogonal by verifying that the matrix and its tranpose are i...
static Vector crossProduct(const Vector &vector1, const Vector &vector2)
Returns the cross product of two vectors.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.
Definition: Hillshade.cpp:308
~LinearAlgebra()
Destructor for a LinearAlgebra object.
static void setVec3(Vector *v, double v0, double v1, double v2)
Fills the first three elements of the given vector with the given values.
boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > SymmetricMatrix
Definition for an Isis::LinearAlgebra::SymmetrixMatrix of doubles with an upper configuration.
static double absoluteMaximum(const Vector &vector)
Returns the maximum norm (L-infinity norm) for the given vector.
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...