17#ifndef __albaMatrix3x3_h
18#define __albaMatrix3x3_h
36 virtual void Print (std::ostream& os,
const int indent=0)
const;
58 static void Multiply(
const double A[3][3],
const double B[3][3],
63 {Multiply(A.GetElements(),B.GetElements(),C.GetElements());C.Modified();}
70 void SetElement(
int i,
int j,
double value) {GetElements()[i][j]=value;}
73 double GetElement(
int i,
int j)
const {
return GetElements()[i][j];}
83 static void Zero(
double elements[9]);
90 static void Transpose(
const double A[3][3],
double AT[3][3]);
94 static void Invert(
const double A[3][3],
double AI[3][3]);
114 static void Diagonalize(
const double A[3][3],
double w[3],
double V[3][3]);
117 static double Determinant(
double A[3][3]);
122 static inline double Determinant(
const double c1[3],
126 static inline double Determinant(
double a1,
double a2,
double a3,
127 double b1,
double b2,
double b3,
128 double c1,
double c2,
double c3);
161 double U[3][3],
double w[3],
166 {SingularValueDecomposition(GetElements(),U,w,VT);}
173 static int Jacobi(
const double A[3][3],
double w[3],
double v[3][3]);
188 static int JacobiN(
double **a,
int n,
double *w,
double **v);
193 static void LUFactor(
double A[3][3],
int index[3]);
199 static void LUSolve(
const double A[3][3],
const int index[3],
double x[3]);
200 void LUSolve(
const int index[3],
double x[3]) \
201 { LUSolve(GetElements(),index,x);}
206 static double Pi() {
return 3.1415926535897932384626;};
210 double *
operator[](
const unsigned int i) {
return &(GetElements()[i][0]);}
213 const double *
operator[](
unsigned int i)
const {
return &(GetElements()[i][0]); }
217 return (a * d - b * c);};
220 return (c1[0]*c2[1] - c2[0]*c1[1]);};
223 static double Norm(
const double x[3]) {
224 return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);};
226 static inline void Cross(
const double x[3],
const double y[3],
double z[3]);
227 static inline double Normalize(
double x[3]);
231 double m_Elements[3][3];
238 return A[0][0]*A[1][1]*A[2][2] + A[1][0]*A[2][1]*A[0][2] +
239 A[2][0]*A[0][1]*A[1][2] - A[0][0]*A[2][1]*A[1][2] -
240 A[1][0]*A[0][1]*A[2][2] - A[2][0]*A[1][1]*A[0][2];
248 return c1[0]*c2[1]*c3[2] + c2[0]*c3[1]*c1[2] + c3[0]*c1[1]*c2[2] -
249 c1[0]*c3[1]*c2[2] - c2[0]*c1[1]*c3[2] - c3[0]*c2[1]*c1[2];
253 double b1,
double b2,
double b3,
254 double c1,
double c2,
double c3)
266 double Zx = x[1]*y[2] - x[2]*y[1];
267 double Zy = x[2]*y[0] - x[0]*y[2];
268 double Zz = x[0]*y[1] - x[1]*y[0];
269 z[0] = Zx; z[1] = Zy; z[2] = Zz;
278 for (
int i=0; i < 3; i++)
double(* albaMatrix3x3Elements)[3]
albaMatrix3x3 - Simple 3x3 Matrix.
double GetElement(int i, int j) const
Returns the element i,j from the matrix.
void DeepCopy(albaMatrix3x3 *mat)
copy the given matrix content
static double Determinant2x2(double a, double b, double c, double d)
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
static double Normalize(double x[3])
albaTypeMacro(albaMatrix3x3, albaObject)
static void LUSolve(const double A[3][3], const int index[3], double x[3])
LU back substitution for a 3x3 matrix.
static void Transpose(const double A[3][3], double AT[3][3])
Transpose the 3x3 matrix.
static void Multiply(const albaMatrix3x3 &A, albaMatrix3x3 &B, albaMatrix3x3 &C)
Multiply this matrix by another according to C = AB.
static void LUFactor(double A[3][3], int index[3])
LU Factorization of a 3x3 matrix.
void SetElement(int i, int j, double value)
Sets the element i,j in the matrix.
static double Determinant2x2(const double c1[2], const double c2[2])
Calculate the determinant of a 2x2 matrix with columns c1 and c2.
static void QuaternionToMatrix(const double quat[4], double A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
static void MultiplyVector(const float A[3][3], const float in[3], float out[3])
Multiply a vector by a 3x3 matrix.
void MultiplyVector(const double in[3], double out[3])
Multiply a vector by this matrix.
void Zero()
Set all of the elements to zero.
static void Identity(double A[3][3])
static void MultiplyVector(const double A[3][3], const double in[3], double out[3])
Multiply a vector by a 3x3 matrix.
albaMatrix3x3Elements GetElements() const
static void Diagonalize(const double A[3][3], double w[3], double V[3][3])
Diagonalize a symmetric 3x3 matrix and return the eigenvalues in w and the eigenvectors in the column...
double Determinant()
Compute the determinant of the matrix and return it.
static int JacobiN(double **a, int n, double *w, double **v)
Jacobi iteration for the solution of eigenvectors/eigenvalues of this 3x3 real symmetric matrix.
const double * operator[](unsigned int i) const
bracket operator to access single elements
void MatrixToQuaternion(double quat[4])
Convert a 3x3 matrix into a quaternion.
albaMatrix3x3(albaMatrix3x3 &mat)
static double RadiansToDegrees()
void QuaternionToMatrix(const double quat[4])
Convert a quaternion to a 3x3 rotation matrix.
static double Norm(const double x[3])
Compute the norm of 3-vector (double-precision version).
static void GetVersor(int axis, const albaMatrix3x3 &matrix, double versor[3])
Get the given matrix versor.
void GetVersor(int axis, double versor[3])
Get the given matrix versor.
double * operator[](const unsigned int i)
bracket operator to access & write single elements
static void Multiply(const double A[3][3], const double B[3][3], double C[3][3])
Multiply one 3x3 matrix by another according to C = AB.
void LUSolve(const int index[3], double x[3])
static void Cross(const double x[3], const double y[3], double z[3])
static void Orthogonalize(const double A[3][3], double B[3][3])
Orthogonalize a 3x3 matrix and put the result in B.
albaMatrix3x3 & operator=(const albaMatrix3x3 &mat)
virtual void Print(std::ostream &os, const int indent=0) const
print debug information for this object
void Orthogonalize()
Orthogonalize this matrix in place.
void Identity()
Set equal to Identity matrix.
static void Invert(const double A[3][3], double AI[3][3])
Invert the 3x3 matrix.
static int Jacobi(const double A[3][3], double w[3], double v[3][3])
static void MatrixToQuaternion(const double A[3][3], double quat[4])
Convert a 3x3 matrix into a quaternion.
static void SingularValueDecomposition(const double A[3][3], double U[3][3], double w[3], double VT[3][3])
Perform singular value decomposition on a 3x3 matrix.
void SingularValueDecomposition(double U[3][3], double w[3], double VT[3][3])
Perform singular value decomposition on a 3x3 matrix.
static void Zero(double elements[9])
Set all of the elements to zero.
void LUFactor(int index[3])
static double DegreesToRadians()
Useful constants.
Abstract superclass for all ALBA classes implementing RTTI APIs.
class acting as an interface for timestamped objects This object simply defines few methods for manag...
virtual void Modified()
Update this objects modification time.