Isis 3 Programmer Reference
Isis::LinearAlgebra Class Reference

This class holds all static methods to perform linear algebra operations on vectors and matrices. More...

#include <LinearAlgebra.h>

Collaboration diagram for Isis::LinearAlgebra:
Collaboration graph

Public Types

typedef boost::numeric::ublas::matrix< double > Matrix
 Definition for an Isis::LinearAlgebra::Matrix of doubles. More...
 
typedef boost::numeric::ublas::symmetric_matrix< double, boost::numeric::ublas::upper > SymmetricMatrix
 Definition for an Isis::LinearAlgebra::SymmetrixMatrix of doubles with an upper configuration. More...
 
typedef boost::numeric::ublas::vector< double > Vector
 Definition for an Isis::LinearAlgebra::Vector of doubles. More...
 
typedef QPair< Vector, AngleAxisAngle
 Definition for an Axis-Angle pair. More...
 
typedef QPair< Angle, int > EulerAngle
 Definition for an EulerAngle pair. More...
 

Static Public Member Functions

static bool isIdentity (const Matrix &matrix)
 Determines whether the given matrix is the identity. More...
 
static bool isOrthogonal (const Matrix &matrix)
 Determines whether the given matrix is orthogonal by verifying that the matrix and its tranpose are inverses. More...
 
static bool isRotationMatrix (const Matrix &matrix)
 Determines whether the given matrix is a rotation matrix. More...
 
static bool isZero (const Matrix &matrix)
 Determines whether the given matrix is filled with zereos. More...
 
static bool isZero (const Vector &vector)
 Determines whether the given vector is filled with zereos. More...
 
static bool isEmpty (const Vector &vector)
 Determines whether the given vector is empty (i.e. More...
 
static bool isUnit (const Vector &vector)
 Determines whether the given vector is a unit vector. More...
 
static Matrix identity (int size)
 Returns the identity matrix of size NxN. More...
 
static Matrix transpose (const Matrix &matrix)
 Returns the transpose of the given matrix. More...
 
static Matrix inverse (const Matrix &matrix)
 Returns the inverse of a 2x2 or 3x3 matrix. More...
 
static Matrix zeroMatrix (int rows, int columns)
 Returns a matrix with given dimensions that is filled with zeroes. More...
 
static Vector zeroVector (int size)
 Returns a vector of given length that is filled with zeroes. More...
 
static double determinant (const Matrix &matrix)
 Returns the determinant of the given 3x3 matrix. More...
 
static Vector normalize (const Vector &vector)
 Returns a unit vector that is codirectional with the given vector by dividing each component of the vector by the vector magnitude. More...
 
static double magnitude (const Vector &vector)
 Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm). More...
 
static double absoluteMaximum (const Vector &vector)
 Returns the maximum norm (L-infinity norm) for the given vector. More...
 
static Matrix multiply (const Matrix &matrix1, const Matrix &matrix2)
 Returns the product of two matrices. More...
 
static Vector multiply (const Matrix &matrix, const Vector &vector)
 Computes the product of the given matrix and vector. More...
 
static Vector multiply (double scalar, const Vector &vector)
 Multiplies the given scalar and vector. More...
 
static Matrix multiply (double scalar, const Matrix &matrix)
 Multiplies the given scalar and matrix. More...
 
static Vector add (const Vector &vector1, const Vector &vector2)
 Adds the two given vectors. More...
 
static Vector subtract (const Vector &vector1, const Vector &vector2)
 Subtracts the right vector from the left vector. More...
 
static Vector crossProduct (const Vector &vector1, const Vector &vector2)
 Returns the cross product of two vectors. More...
 
static Vector normalizedCrossProduct (const Vector &vector1, const Vector &vector2)
 Divides each vector by its corresponding absolute maximum, computes the cross product of the new vectors, and normalizes the resultant vector from the cross product. More...
 
static Matrix outerProduct (const Vector &vector1, const Vector &vector2)
 Computes the outer product of the given vectors. More...
 
static double dotProduct (const Vector &vector1, const Vector &vector2)
 Computes the dot product of the given vectors. More...
 
static double innerProduct (const Vector &vector1, const Vector &vector2)
 Computes the inner product of the given vectors. More...
 
static Vector project (const Vector &vector1, const Vector &vector2)
 Compute the vector projection of vector1 onto vector2. More...
 
static Vector rotate (const Vector &vector, const Vector &axis, Angle angle)
 Rotates a vector about an axis vector given a specified angle. More...
 
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, where A is the first vector (vector1) and B is the second vector (vector2) passed in by the user. More...
 
static AxisAngle toAxisAngle (const Matrix &rotationMatrix)
 Converts a rotation's representation from a matrix to a axis of rotation and its corresponding rotation angle. More...
 
static Matrix toMatrix (const AxisAngle &axisAngle)
 Converts a rotation's representation from an axis of rotation and its corresponding rotation angle to a 3x3 matrix. More...
 
static Matrix toMatrix (const Vector &axis, Angle angle)
 Converts a rotation's representation from an axis of rotation and its corresponding rotation angle to a 3x3 matrix. More...
 
static QList< EulerAngletoEulerAngles (const Matrix &rotationMatrix, const QList< int > axes)
 Converts a rotation's representation from a matrix to a set of Euler angles with corresponding axes. More...
 
static Matrix toMatrix (const QList< EulerAngle > &eulerAngles)
 Converts a rotation's representation from a list of Euler angles (3 angles, each with a corresponding axis) to a 3x3 matrix. More...
 
static Matrix toMatrix (const EulerAngle &angle3, const EulerAngle &angle2, const EulerAngle &angle1)
 Converts a rotation's representation from a set of Euler angles (3 angles, each with a corresponding axis) to a 3x3 matrix. More...
 
static Vector toQuaternion (const Matrix &rotationMatrix)
 Converts a rotation's representation from a matrix to a unit quaternion. More...
 
static Matrix toMatrix (const Vector &quaternion)
 Converts a rotation's representation from a quaternion to a 3x3 matrix. More...
 
static void setRow (Matrix &matrix, const Vector &vector, int rowIndex)
 Sets the row of the given matrix to the values of the given vector. More...
 
static void setColumn (Matrix &matrix, const Vector &vector, int columnIndex)
 Sets the column of the given matrix to the values of the given vector. More...
 
static Vector row (const Matrix &matrix, int rowIndex)
 Returns a vector whose components match those of the given matrix row. More...
 
static Vector column (const Matrix &matrix, int columnIndex)
 Returns a vector whose components match those of the given matrix column. More...
 
static void setVec3 (Vector *v, double v0, double v1, double v2)
 Fills the first three elements of the given vector with the given values. More...
 
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. More...
 
static Vector vector (double v0, double v1, double v2)
 Constructs a 3 dimensional vector with the given component values. More...
 
static Vector vector (double v0, double v1, double v2, double v3)
 Constructs a 4 dimensional vector with the given component values. More...
 
static Vector subVector (const Vector &v, int start, int size)
 Constructs a vector of given size using the given vector and starting index. More...
 

Protected Member Functions

 LinearAlgebra ()
 Default constructor for a LinearAlgebra object. More...
 
 ~LinearAlgebra ()
 Destructor for a LinearAlgebra object. More...
 

Detailed Description

This class holds all static methods to perform linear algebra operations on vectors and matrices.

This class has 4 representations of a 3 dimensional rotation

  • A 3 X 3 rotation matrix
  • An angle/axis pair - This pair is made up of a vector (axis) and angle of rotation about that axis.
  • A quaternion - This is saved as a 4-valued unit vector of the form q = (q0, q1, q2, q3) where for the angle/axis pair of the form (A, (ux, uy, uz)), we have q0 = cos(A/2), q1 = ux*sin(A/2), q2 = uy*sin(A/2), q3 = uz*sin(A/2).
  • A set of Euler angles - This is a set of three angles and their corresponding axis of rotation. In this case, each axis must be one of the x, y, or z axes for the coordinate system.
Author
2013-06-01 Jeannie Backer
History:

2013-06-01 Jeannie Backer - Original version.

2013-08-07 Kimberly Oyama - Updated documentation.

2016-07-25 Jeannie Backer - Updated documentation and test.

2016-08-05 Jeannie Backer - Replace std abs() function with qAbs() from QtGlobal.

2016-08-16 Jesse Mapel - Added BOOST_UBLAS_NO_STD_CERR definition to prevent Boost from outputing debug information to standard out when throwing exceptions. Fixes #2302.

2017-12-12 Jeannie Backer - Added SymmetricMatrix typedef.

Todo:

document methods (a) add naif routine names to documentation where appropriate, (b) clean up comments within methods, (3) use naif documentation where appropriate

add links to naif documentation web pages???

add proper scopes

implement norm2 (L2 norm)?

implement trace?

common validate errors - vector size match, 3x3 matrix, 3D vector

what is more expensive - unitize vector and compare to 1 or isOrthogonal?

rename local variables m2q and q2m

implement qdq2av (Quaternion and quaternion derivative to angular velocity)?

implement qxq (Quaternion times quaternion)?

implement qderiv (Quadratic derivative)?

When converting quaternion, axis-angle, Euler angle to rot matrix, should we verify that the matrix is valid (is a rotation matrix)???

isQuaternion???

should we throw error in q2m if q = 0???

q2m - why check if sharpen when q is not unit if it is required to be a unit? throw an error?

axisar - throw error if axis is origin? If we rotate about about origin, then we get a zero matrix - not a rotation... except maybe trivially... (or do we get identity??? indicating no rotation)

double check all indexing on code copied from NAIF - indices should reverse col/row order and subtract 1

Definition at line 104 of file LinearAlgebra.h.

Member Typedef Documentation

◆ AxisAngle

Definition for an Axis-Angle pair.

This is a three dimensional rotation represented as an axis of rotation and a corresponding rotation angle. AxisAngle is a typedef for a QPair of an Isis::LinearAlgebra::Vector and an Isis::Angle.

Definition at line 144 of file LinearAlgebra.h.

◆ EulerAngle

Definition for an EulerAngle pair.

This is a three dimensional rotation represented as an Euler angle and the number corresponding to its rotation axis. EulerAngle is a typedef for a QPair of an Isis::Angle and an integer (1, 2, or 3).

Definition at line 151 of file LinearAlgebra.h.

◆ Matrix

typedef boost::numeric::ublas::matrix<double> Isis::LinearAlgebra::Matrix

Definition for an Isis::LinearAlgebra::Matrix of doubles.

This is a typedef for a boost matrix.

Note: This typedef is used so that we can add functionality to an existing matrix type and/or change which third party library's matrix we are using without changing all references to this type in the ISIS API.

Definition at line 115 of file LinearAlgebra.h.

◆ SymmetricMatrix

typedef boost::numeric::ublas::symmetric_matrix<double, boost::numeric::ublas::upper> Isis::LinearAlgebra::SymmetricMatrix

Definition for an Isis::LinearAlgebra::SymmetrixMatrix of doubles with an upper configuration.

This is a typedef for a boost symmetric_matrix.

Note: This typedef is used so that we can add functionality to an existing matrix type and/or change which third party library's matrix we are using without changing all references to this type in the ISIS API.

Definition at line 125 of file LinearAlgebra.h.

◆ Vector

typedef boost::numeric::ublas::vector<double> Isis::LinearAlgebra::Vector

Definition for an Isis::LinearAlgebra::Vector of doubles.

This is a typedef for a boost vector.

Note: This typedef is used so that we can add functionality to an existing vector type and/or change which third party library's vector we are using without changing all references to this type in the ISIS API.

Definition at line 135 of file LinearAlgebra.h.

Constructor & Destructor Documentation

◆ LinearAlgebra()

Isis::LinearAlgebra::LinearAlgebra ( )
protected

Default constructor for a LinearAlgebra object.

This is protected so it can never be constructed. The static methods and typedefs in this class are meant to be used without a LinearAlgebra object.

Definition at line 52 of file LinearAlgebra.cpp.

◆ ~LinearAlgebra()

Isis::LinearAlgebra::~LinearAlgebra ( )
protected

Destructor for a LinearAlgebra object.

Definition at line 59 of file LinearAlgebra.cpp.

Member Function Documentation

◆ absoluteMaximum()

double Isis::LinearAlgebra::absoluteMaximum ( const Vector vector)
static

Returns the maximum norm (L-infinity norm) for the given vector.

The maximum norm is defined by the absolute values of the vector components:

\( \| v \|_\infty = \max_{i=1}^n \{ \mid v_i \mid \} \)

Parameters
vectorThe vector whose absolute maximum will be returned.
Returns
double The maximum of the absolute values of the vector components.

Definition at line 514 of file LinearAlgebra.cpp.

References vector().

Referenced by magnitude(), normalizedCrossProduct(), and perpendicular().

◆ add()

LinearAlgebra::Vector Isis::LinearAlgebra::add ( const Vector vector1,
const Vector vector2 
)
static

Adds the two given vectors.

Parameters
vector1The first vector.
vector2The second vector.
Returns
LinearAlgebra::Vector The sum of the vectors.
Exceptions
IException::Programmer"Unable to add vectors with mismatched sizes."

Definition at line 617 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

◆ column()

LinearAlgebra::Vector Isis::LinearAlgebra::column ( const Matrix matrix,
int  columnIndex 
)
static

Returns a vector whose components match those of the given matrix column.

Parameters
matrixThe matrix to pull values from.
columnIndexThe index of the matrix column to grab.
Returns
LinearAlgebra::Vector A vector whose values match the given column of the given matrix.
Exceptions
IException::Programmer"Unable to get the matrix column to the given vector. Column index is out of bounds."

Definition at line 1676 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by isRotationMatrix(), toEulerAngles(), and toMatrix().

◆ crossProduct()

LinearAlgebra::Vector Isis::LinearAlgebra::crossProduct ( const Vector vector1,
const Vector vector2 
)
static

Returns the cross product of two vectors.

Note: the cross-product requires the vectors to have exactly three components each.

Parameters
vector1The vector to the left of the cross product operator.
vector2The vector to the right of the cross product operator.
Returns
LinearAlgebra::Vector The cross product of the given vectors (i.e. vector1 x vector2).
Exceptions
IException::Programmer"Unable to calculate the cross product on vectors that are not size 3. "

Definition at line 671 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by normalizedCrossProduct(), and rotate().

◆ determinant()

double Isis::LinearAlgebra::determinant ( const Matrix matrix)
static

Returns the determinant of the given 3x3 matrix.

Parameters
LinearAlgebra::MatrixThe 3x3 matrix whose determinant will be calculated.
Returns
double The determinant of the given matrix.
Exceptions
IException::Programmer"Unable to calculate the determinant for the given matrix. This method only calculates the determinant for 2x2 or 3x3 matrices."

Definition at line 423 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by inverse(), and isRotationMatrix().

◆ dotProduct()

double Isis::LinearAlgebra::dotProduct ( const Vector vector1,
const Vector vector2 
)
static

Computes the dot product of the given vectors.

For Euclidean space, this is the same as the inner product, so these methods are interchangeable.

See also
innerProduct()
Parameters
vector1The first vector.
vector2The second vector.
Returns
double The dot product of the vectors.

Definition at line 764 of file LinearAlgebra.cpp.

References innerProduct().

Referenced by isUnit(), project(), Isis::RosettaOsirisCameraDistortionMap::SetFocalPlane(), and Isis::RosettaOsirisCameraDistortionMap::SetUndistortedFocalPlane().

◆ identity()

LinearAlgebra::Matrix Isis::LinearAlgebra::identity ( int  size)
static

Returns the identity matrix of size NxN.

Parameters
intThe size of the square matrix.
Returns
LinearAlgebra::Matrix The NxN square matrix.
Exceptions
IException::Programmer"Can not create identity matrix of negative size."

Definition at line 367 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by inverse(), and toMatrix().

◆ innerProduct()

double Isis::LinearAlgebra::innerProduct ( const Vector vector1,
const Vector vector2 
)
static

Computes the inner product of the given vectors.

For Euclidean space, this is the same as the dot product, so these methods are interchangeable.

See also
dotProduct()
Parameters
vector1The first vector.
vector2The second vector.
Returns
double The inner product of the vectors.
Exceptions
IException::Programmer"Unable to compute the dot product for vectors with mismatched sizes."

Definition at line 784 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by dotProduct().

◆ inverse()

LinearAlgebra::Matrix Isis::LinearAlgebra::inverse ( const Matrix matrix)
static

Returns the inverse of a 2x2 or 3x3 matrix.

Throws an error if the given matrix is not invertible.

Parameters
matrixThe matrix to inverse.
Returns
LinearAlgebra::Matrix The inverse matrix.
Exceptions
IException::Programmer"The given matrix is not invertible. The determinant is 0.0."
IException::Programmer"Unable to invert the given matrix."

Definition at line 295 of file LinearAlgebra.cpp.

References _FILEINFO_, determinant(), identity(), isOrthogonal(), Isis::IException::Programmer, and transpose().

◆ isEmpty()

bool Isis::LinearAlgebra::isEmpty ( const Vector vector)
static

Determines whether the given vector is empty (i.e.

size 0).

Parameters
vectorThe vector to check.
Returns
bool Returns true if the size of the given vector is zero.

Definition at line 263 of file LinearAlgebra.cpp.

References vector().

◆ isIdentity()

bool Isis::LinearAlgebra::isIdentity ( const Matrix matrix)
static

Determines whether the given matrix is the identity.

Non-square matrices always return false. A qfuzzycompare is used when checking the zeroes and ones.

Parameters
matrixThe matrix to check. Automatically returns false if not square.
Returns
bool Returns true if the matrix is a square identity matrix (i.e. there are ones down the diagonal and zeroes elsewhere).

Definition at line 74 of file LinearAlgebra.cpp.

References row().

Referenced by isOrthogonal().

◆ isOrthogonal()

bool Isis::LinearAlgebra::isOrthogonal ( const Matrix matrix)
static

Determines whether the given matrix is orthogonal by verifying that the matrix and its tranpose are inverses.

Parameters
matrixThe matrix to check. Automatically returns false if not square.
Returns
bool Returns true if the matrix is orthogonal.

Definition at line 102 of file LinearAlgebra.cpp.

References isIdentity(), multiply(), and transpose().

Referenced by inverse().

◆ isRotationMatrix()

bool Isis::LinearAlgebra::isRotationMatrix ( const Matrix matrix)
static

Determines whether the given matrix is a rotation matrix.

Parameters
matrixThe matrix to check. Automatically returns false if not 2x2 or 3x3.
Returns
bool Returns true if the given matrix represents a rotation.
Exceptions
IException::Programmer"Unable to determine whether the given matrix is a rotation matrix."

Definition at line 126 of file LinearAlgebra.cpp.

References _FILEINFO_, column(), determinant(), magnitude(), Isis::IException::Programmer, and setColumn().

Referenced by toAxisAngle(), toEulerAngles(), and toQuaternion().

◆ isUnit()

bool Isis::LinearAlgebra::isUnit ( const Vector vector)
static

Determines whether the given vector is a unit vector.

Parameters
vectorThe vector to check.
Returns
bool Returns true if the vector is a unit vector.

Definition at line 275 of file LinearAlgebra.cpp.

References dotProduct(), and vector().

Referenced by toMatrix(), and toQuaternion().

◆ isZero() [1/2]

bool Isis::LinearAlgebra::isZero ( const Matrix matrix)
static

Determines whether the given matrix is filled with zereos.

Parameters
vectorThe matrix to check.
Returns
bool Returns true if the matrix is all zereos.

Definition at line 224 of file LinearAlgebra.cpp.

Referenced by magnitude(), normalize(), perpendicular(), project(), rotate(), toAxisAngle(), and toMatrix().

◆ isZero() [2/2]

bool Isis::LinearAlgebra::isZero ( const Vector vector)
static

Determines whether the given vector is filled with zereos.

Parameters
vectorThe vector to check.
Returns
bool Returns true if the vector is all zereos.

Definition at line 244 of file LinearAlgebra.cpp.

References vector().

◆ magnitude()

double Isis::LinearAlgebra::magnitude ( const Vector vector)
static

Computes the magnitude (i.e., the length) of the given vector using the Euclidean norm (L2 norm).

The maximum norm (L-infinity) is also used to stabilize the solution in order to avoid overflow. This method uses the computation

\( \| v \| = \| v \|_\infty \| \frac{v}{\| v \|_\infty} \|_2 \) where \( \| u \|_\infty = \max_{i=1}^n \{ \mid u_i \mid \} \) is the maximum norm and \( \| u \|_2 = \sqrt{\sum_{i=1}^n u_1^2} \) is the Euclidean norm.

See also
absoluteMaximum()
Parameters
vectorThe vector whose magnitude will be computed.
Returns
double The magnitude (length) of the given vector.

Definition at line 487 of file LinearAlgebra.cpp.

References absoluteMaximum(), isZero(), and vector().

Referenced by Isis::EmbreeShapeModel::intersectSurface(), isRotationMatrix(), Isis::EmbreeShapeModel::isVisibleFrom(), Isis::EmbreeShapeModel::localRadius(), Isis::EmbreeTargetShape::maximumSceneDistance(), normalize(), Isis::RosettaOsirisCameraDistortionMap::SetUndistortedFocalPlane(), Isis::EmbreeShapeModel::sortHits(), and toAxisAngle().

◆ multiply() [1/4]

LinearAlgebra::Matrix Isis::LinearAlgebra::multiply ( const Matrix matrix1,
const Matrix matrix2 
)
static

Returns the product of two matrices.

Will throw an error if the matrices are not properly sized (the number of columns of the first matrix must match the number or rows of the second matrix).

Parameters
matrix1The left matrix.
matrix2The right matrix.
Returns
LinearAlgebra::Matrix The resultant matrix product.
Exceptions
IException::Programmer"Unable to multiply matrices with mismatched dimensions."

Definition at line 532 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by isOrthogonal(), Isis::RosettaOsirisCameraDistortionMap::SetFocalPlane(), Isis::RosettaOsirisCameraDistortionMap::SetUndistortedFocalPlane(), and toEulerAngles().

◆ multiply() [2/4]

LinearAlgebra::Vector Isis::LinearAlgebra::multiply ( const Matrix matrix,
const Vector vector 
)
static

Computes the product of the given matrix and vector.

The vector will be multiplied on the right side of the given matrix. Will throw an error if the two are not properly sized (matrix columns not equal to vector size).

Parameters
matrixThe matrix to be multiplied.
vectorThe column vector to be multiplied on the right side of the matrix.
Returns
LinearAlgebra::Vector The resultant vector.
Exceptions
IException::Programmer"Unable to multiply matrix and vector with mismatched dimensions."

Definition at line 563 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, Isis::toString(), and vector().

◆ multiply() [3/4]

LinearAlgebra::Vector Isis::LinearAlgebra::multiply ( double  scalar,
const Vector vector 
)
static

Multiplies the given scalar and vector.

Parameters
scalarThe scalar to be multiplied by each component of the vector.
vectorThe vector to be scaled.
Returns
LinearAlgebra::Vector The resultant scaled vector.

Definition at line 586 of file LinearAlgebra.cpp.

References vector().

◆ multiply() [4/4]

LinearAlgebra::Matrix Isis::LinearAlgebra::multiply ( double  scalar,
const Matrix matrix 
)
static

Multiplies the given scalar and matrix.

Parameters
scalarThe scalar to be multiplied by each element of the matrix.
matrixThe matrix to be scaled.
Returns
LinearAlgebra::Matrix The resultant scaled matrix.

Definition at line 600 of file LinearAlgebra.cpp.

◆ normalize()

LinearAlgebra::Vector Isis::LinearAlgebra::normalize ( const Vector vector)
static

Returns a unit vector that is codirectional with the given vector by dividing each component of the vector by the vector magnitude.

\( \hat{v} = \frac{v}{\| v \|} \) where \( \| u \|_ \) is the magnitude of u.

See also
magnitude()
Parameters
vectorThe vector to be normalized.
Returns
LinearAlgebra::Vector A unit vector from the given vector.
Exceptions
IException::Programmer"Unable to normalize the zero vector."

Definition at line 460 of file LinearAlgebra.cpp.

References _FILEINFO_, isZero(), magnitude(), Isis::IException::Unknown, and vector().

Referenced by Isis::EmbreeTargetShape::getHitInformation(), Isis::EmbreeShapeModel::intersectSurface(), normalizedCrossProduct(), Isis::EmbreeShapeModel::pointToRay(), rotate(), toAxisAngle(), toEulerAngles(), toMatrix(), and toQuaternion().

◆ normalizedCrossProduct()

LinearAlgebra::Vector Isis::LinearAlgebra::normalizedCrossProduct ( const Vector vector1,
const Vector vector2 
)
static

Divides each vector by its corresponding absolute maximum, computes the cross product of the new vectors, and normalizes the resultant vector from the cross product.

Note: the cross-product requires the vectors to have exactly three components each.

Parameters
vector1The vector to the left of the cross product operator.
vector2The vector to the right of the cross product operator.
Returns
LinearAlgebra::Vector The normalized cross product of the given vectors (i.e. normalize(vector1/absoluteMaximum(vector1) x vector2/absoluteMaximum(vector2))).

Definition at line 704 of file LinearAlgebra.cpp.

References absoluteMaximum(), crossProduct(), and normalize().

◆ outerProduct()

LinearAlgebra::Matrix Isis::LinearAlgebra::outerProduct ( const Vector vector1,
const Vector vector2 
)
static

Computes the outer product of the given vectors.

The outer product operation is defined as the cross product of vector1 and the conjugate transpose of vector2.

Parameters
vector1The vector to the left side of the outer product operator.
vector2The vector to the right side of the outer product operator.
Returns
LinearAlgebra::Matrix The outer product matrix of the given vectors.
Exceptions
IException::Programmer"Unable to compute the outer product for vectors with mismatched sizes."

Definition at line 740 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

◆ perpendicular()

LinearAlgebra::Vector Isis::LinearAlgebra::perpendicular ( const Vector vector1,
const Vector vector2 
)
static

Finds the unique vector P such that A = V + P, V is parallel to B and P is perpendicular to B, where A is the first vector (vector1) and B is the second vector (vector2) passed in by the user.

For all vectors A and B, there exists unique vectors V and P such that 1) A = V + P 2) V is parallel to B
3) P is perpendicular to B

Parameters
vector1The first vector, denoted A in the description.
vector2The second vector, denoted B in the description.
Returns
LinearAlgebra::Vector A vector perpendicular to vector2 and equal to vector1-parallel2 (where parallel2 is some vector that is parallel to vector2).

Definition at line 915 of file LinearAlgebra.cpp.

References absoluteMaximum(), isZero(), and project().

◆ project()

LinearAlgebra::Vector Isis::LinearAlgebra::project ( const Vector vector1,
const Vector vector2 
)
static

Compute the vector projection of vector1 onto vector2.

This is the orthogonal projection of vector1 onto a line that is parallel to vector2.

It is defined by \( proj_{v_2} v_1 = \frac{v_1 \cdot v_2}{\| v_2 \|^2}v_2 \) where \( \| u \|_ \) is the magnitude of u.

Parameters
vector1The vector to the left of the project operator.
vector2The vector to the right of the project operator.
Returns
LinearAlgebra::Vector The resultant vector that is the orthogonal projection of vector1 onto vector2.
Exceptions
IException::Programmer"Unable to project vector1 onto vector2 with mismatched sizes."

Definition at line 816 of file LinearAlgebra.cpp.

References _FILEINFO_, dotProduct(), isZero(), Isis::IException::Programmer, and Isis::toString().

Referenced by perpendicular(), and rotate().

◆ rotate()

LinearAlgebra::Vector Isis::LinearAlgebra::rotate ( const Vector vector,
const Vector axis,
Angle  angle 
)
static

Rotates a vector about an axis vector given a specified angle.

Note: this method only rotates a vector with three components since the cross product calculation requires this.

Parameters
vectorThe vector to rotate, which must have three components.
axisA vector defining the axis, which must also have three components.
angleThe angle to rotate.
Returns
LinearAlgebra::Vector The rotated vector.
Exceptions
IException::Programmer"Unable to rotate vector about the given axis and angle. Vectors must be of size 3 to perform rotation. "

Definition at line 855 of file LinearAlgebra.cpp.

References _FILEINFO_, crossProduct(), isZero(), normalize(), Isis::IException::Programmer, project(), Isis::Angle::radians(), Isis::toString(), and vector().

Referenced by toMatrix().

◆ row()

LinearAlgebra::Vector Isis::LinearAlgebra::row ( const Matrix matrix,
int  rowIndex 
)
static

Returns a vector whose components match those of the given matrix row.

Parameters
matrixThe matrix to pull values from.
rowIndexThe index of the matrix row to grab.
Returns
LinearAlgebra::Vector A vector whose values match the given row of the given matrix.
Exceptions
IException::Programmer"Unable to get the matrix row to the given vector. Row index is out of bounds."

Definition at line 1653 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

Referenced by isIdentity().

◆ setColumn()

void Isis::LinearAlgebra::setColumn ( Matrix matrix,
const Vector vector,
int  columnIndex 
)
static

Sets the column of the given matrix to the values of the given vector.

Parameters
matrixThe address of the matrix to be altered.
vectorThe vector with the new values.
columnIndexThe index of the column to be altered.
Exceptions
IException::Programmer"Unable to set the matrix column to the given vector. Column index is out of bounds."

Definition at line 1630 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, Isis::toString(), and vector().

Referenced by isRotationMatrix(), toEulerAngles(), and toMatrix().

◆ setRow()

void Isis::LinearAlgebra::setRow ( Matrix matrix,
const Vector vector,
int  rowIndex 
)
static

Sets the row of the given matrix to the values of the given vector.

Parameters
matrixThe address of the matrix to be altered.
vectorThe vector with the new values.
rowIndexThe index of the row to be altered.
Exceptions
IException::Programmer"Unable to set the matrix row to the given vector. Row index is out of bounds."

Definition at line 1609 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, Isis::toString(), and vector().

◆ setVec3()

void Isis::LinearAlgebra::setVec3 ( Vector v,
double  v0,
double  v1,
double  v2 
)
static

Fills the first three elements of the given vector with the given values.

Parameters
vA pointer to a 3-dimensional vector to be filled.
v0The first component of the vector.
v1The second component of the vector.
v2The third component of the vector.

Definition at line 1735 of file LinearAlgebra.cpp.

◆ setVec4()

void Isis::LinearAlgebra::setVec4 ( Vector v,
double  v0,
double  v1,
double  v2,
double  v3 
)
static

Fills the first four elements of the given vector with the given values.

Parameters
vA pointer to a 4-dimensional vector to be filled.
v0The first component of the vector.
v1The second component of the vector.
v2The third component of the vector.
v3The fourth component of the vector.

Definition at line 1751 of file LinearAlgebra.cpp.

◆ subtract()

LinearAlgebra::Vector Isis::LinearAlgebra::subtract ( const Vector vector1,
const Vector vector2 
)
static

Subtracts the right vector from the left vector.

Parameters
vector1The vector to the left of the subtraction operator.
vector2The vector to the right of the subtraction operator.
Returns
LinearAlgebra::Vector The difference of the vectors (i.e. vector1 - vector2).
Exceptions
IException::Programmer"Unable to subtract vectors with mismatched sizes."

Definition at line 643 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

◆ subVector()

LinearAlgebra::Vector Isis::LinearAlgebra::subVector ( const Vector v,
int  startIndex,
int  size 
)
static

Constructs a vector of given size using the given vector and starting index.

Parameters
vThe original vector to get values from.
startIndexThe index of the original vector, used to indicate the first value that will be copied to the new vector.
sizeThe number of elements from the original vector to copy to the new vector.
Returns
LinearAlgebra::Vector A sub-vector containing values from the original vector.

Definition at line 1772 of file LinearAlgebra.cpp.

◆ toAxisAngle()

LinearAlgebra::AxisAngle Isis::LinearAlgebra::toAxisAngle ( const Matrix rotationMatrix)
static

Converts a rotation's representation from a matrix to a axis of rotation and its corresponding rotation angle.

Parameters
rotationMatrixA matrix representing a rotation.
Returns
LinearAlgebra::AxisAngle The axis-angle pair representing the rotation.
Exceptions
IException::Programmer"Unable to convert the given matrix to an axis of rotation and a rotation angle. A 3x3 matrix is required." @throw IException::Programmer "Unable to convert the given matrix to an axis of rotation and a rotation angle. The given matrix is not a rotation matrix."

Definition at line 956 of file LinearAlgebra.cpp.

References _FILEINFO_, isRotationMatrix(), isZero(), magnitude(), normalize(), Isis::PI, Isis::IException::Programmer, Isis::Angle::setRadians(), toQuaternion(), and Isis::toString().

◆ toEulerAngles()

QList< LinearAlgebra::EulerAngle > Isis::LinearAlgebra::toEulerAngles ( const Matrix rotationMatrix,
const QList< int >  axes 
)
static

Converts a rotation's representation from a matrix to a set of Euler angles with corresponding axes.

Parameters
rotationMatrixA matrix representing a rotation.
axesA list containing the order of axes.
Returns
QList< LinearAlgebra::EulerAngle> The list of 3 Euler angles with their axes representing the rotation.
Exceptions
IException::Programmer"Unable to convert the given matrix to Euler angles. Exactly 3 axis codes are required."
IException::Programmer"Unable to convert the given matrix to Euler angles using the given axis codes. Axis codes must be 1, 2, or 3."
IException::Programmer"Unable to convert the given matrix to Euler angles using the given axis codes. The middle axis code must differ from its neighbors." @throw IException::Programmer "Unable to convert the given matrix to Euler angles. A 3x3 matrix is required." @throw IException::Programmer "Unable to convert the given matrix to Euler angles. The given matrix is not a rotation matrix."

Definition at line 1034 of file LinearAlgebra.cpp.

References _FILEINFO_, column(), isRotationMatrix(), multiply(), normalize(), Isis::IException::Programmer, setColumn(), Isis::Angle::setRadians(), Isis::toString(), transpose(), and zeroMatrix().

◆ toMatrix() [1/5]

LinearAlgebra::Matrix Isis::LinearAlgebra::toMatrix ( const AxisAngle axisAngle)
static

Converts a rotation's representation from an axis of rotation and its corresponding rotation angle to a 3x3 matrix.

Parameters
axisAngleThe axis-angle pair representation of a rotation
Returns
LinearAlgebra::Matrix The matrix representation of the rotation.

Definition at line 1425 of file LinearAlgebra.cpp.

Referenced by toMatrix().

◆ toMatrix() [2/5]

LinearAlgebra::Matrix Isis::LinearAlgebra::toMatrix ( const Vector axis,
Angle  angle 
)
static

Converts a rotation's representation from an axis of rotation and its corresponding rotation angle to a 3x3 matrix.

Parameters
axisThe axis of rotation for a rotation.
angleThe rotation angle.
Returns
LinearAlgebra::Matrix The matrix representing the rotation.
Exceptions
IException::Programmer"Unable to convert the given vector and angle to a rotation matrix. The given vector is not a 3D axis vector."

Definition at line 1388 of file LinearAlgebra.cpp.

References _FILEINFO_, column(), identity(), Isis::IException::Programmer, rotate(), setColumn(), and Isis::toString().

◆ toMatrix() [3/5]

LinearAlgebra::Matrix Isis::LinearAlgebra::toMatrix ( const QList< EulerAngle > &  eulerAngles)
static

Converts a rotation's representation from a list of Euler angles (3 angles, each with a corresponding axis) to a 3x3 matrix.

Parameters
eulerAnglesThe Euler angle representation of a rotation.
Returns
LinearAlgebra::Matrix The matrix representation of the rotation.
Exceptions
IException::Programmer"Unable to convert the given Euler angles to a matrix. Exactly 3 Euler angles are required."

Definition at line 1528 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, toMatrix(), and Isis::toString().

◆ toMatrix() [4/5]

LinearAlgebra::Matrix Isis::LinearAlgebra::toMatrix ( const EulerAngle angle3,
const EulerAngle angle2,
const EulerAngle angle1 
)
static

Converts a rotation's representation from a set of Euler angles (3 angles, each with a corresponding axis) to a 3x3 matrix.

Parameters
angle3The third angle and its axis.
angle2The second angle and its axis.
angle1The first angle and its axis.
Returns
LinearAlgebra::Matrix The matrix representation of the rotation.
Exceptions
IException::Programmer"Unable to convert the given Euler angles to a matrix using the given axis codes. Axis codes must be 1, 2, or 3."

Definition at line 1445 of file LinearAlgebra.cpp.

References _FILEINFO_, Isis::IException::Programmer, and Isis::toString().

◆ toMatrix() [5/5]

LinearAlgebra::Matrix Isis::LinearAlgebra::toMatrix ( const Vector quaternion)
static

Converts a rotation's representation from a quaternion to a 3x3 matrix.

Note, if the given vector is not a unit vector or the zero vector, this method will normalize it before computing the corresponding matrix.

Parameters
quaternionA unit quaternion representation of a rotation.
Returns
LinearAlgebra::Matrix The matrix representation of the rotation.
Exceptions
IException::Programmer"Unable to convert the given vector to a rotation matrix. The given vector is not a quaternion."

Definition at line 1555 of file LinearAlgebra.cpp.

References _FILEINFO_, isUnit(), isZero(), normalize(), Isis::IException::Programmer, and Isis::toString().

◆ toQuaternion()

LinearAlgebra::Vector Isis::LinearAlgebra::toQuaternion ( const Matrix rotationMatrix)
static

Converts a rotation's representation from a matrix to a unit quaternion.

Parameters
rotationMatrixA matrix representing a rotation.
Returns
LinearAlgebra::Vector A unit quaternion representing the rotation.
Exceptions
IException::Programmer"Unable to convert the given matrix to a quaternion. A 3x3 matrix is required.
IException::Programmer"Unable to convert the given matrix to an axis of rotation and a rotation angle. The given matrix is not a rotation matrix."

Definition at line 1194 of file LinearAlgebra.cpp.

References _FILEINFO_, isRotationMatrix(), isUnit(), normalize(), Isis::IException::Programmer, and Isis::toString().

Referenced by toAxisAngle().

◆ transpose()

LinearAlgebra::Matrix Isis::LinearAlgebra::transpose ( const Matrix matrix)
static

Returns the transpose of the given matrix.

Parameters
matrixThe matrix to transpose.
Returns
LinearAlgebra::Matrix The transposed matrix.

Definition at line 352 of file LinearAlgebra.cpp.

Referenced by inverse(), isOrthogonal(), and toEulerAngles().

◆ vector() [1/2]

LinearAlgebra::Vector Isis::LinearAlgebra::vector ( double  v0,
double  v1,
double  v2 
)
static

Constructs a 3 dimensional vector with the given component values.

Parameters
v0The first component of the vector.
v1The second component of the vector.
v2The third component of the vector.
Returns
LinearAlgebra::Vector A vector containing the given values.

Definition at line 1697 of file LinearAlgebra.cpp.

Referenced by absoluteMaximum(), Isis::EmbreeShapeModel::intersectSurface(), isEmpty(), isUnit(), Isis::EmbreeShapeModel::isVisibleFrom(), isZero(), magnitude(), multiply(), normalize(), Isis::EmbreeShapeModel::pointToRay(), Isis::RayHitInformation::RayHitInformation(), rotate(), setColumn(), and setRow().

◆ vector() [2/2]

LinearAlgebra::Vector Isis::LinearAlgebra::vector ( double  v0,
double  v1,
double  v2,
double  v3 
)
static

Constructs a 4 dimensional vector with the given component values.

Parameters
v0The first component of the vector.
v1The second component of the vector.
v2The third component of the vector.
v3The fourth component of the vector.
Returns
LinearAlgebra::Vector A vector containing the given values.

Definition at line 1717 of file LinearAlgebra.cpp.

◆ zeroMatrix()

LinearAlgebra::Matrix Isis::LinearAlgebra::zeroMatrix ( int  rows,
int  columns 
)
static

Returns a matrix with given dimensions that is filled with zeroes.

Parameters
rowsThe number of rows in the returned matrix.
columnsThe number of colums in the returned matrix.
Returns
LinearAlgebra::Matrix A zero-filled matrix.

Definition at line 391 of file LinearAlgebra.cpp.

Referenced by Isis::RosettaOsirisCamera::initDistortion(), Isis::RosettaOsirisCameraDistortionMap::RosettaOsirisCameraDistortionMap(), Isis::RosettaOsirisCameraDistortionMap::SetUndistortedFocalPlane(), and toEulerAngles().

◆ zeroVector()

LinearAlgebra::Vector Isis::LinearAlgebra::zeroVector ( int  size)
static

Returns a vector of given length that is filled with zeroes.

Parameters
sizeSize of the vector.
Returns
LinearAlgebra::Vector A zero-filled vector.

Definition at line 404 of file LinearAlgebra.cpp.

Referenced by Isis::RosettaOsirisCameraDistortionMap::SetFocalPlane(), and Isis::RosettaOsirisCameraDistortionMap::SetUndistortedFocalPlane().


The documentation for this class was generated from the following files: