OpenWalnut  1.3.1
WLinearAlgebraFunctions.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WLINEARALGEBRAFUNCTIONS_H
26 #define WLINEARALGEBRAFUNCTIONS_H
27 
28 
29 #include "WMatrix.h"
30 #include "linearAlgebra/WLinearAlgebra.h"
31 
32 template< typename > class WMatrix;
33 
34 /**
35  * helper routine to multiply a 3x3 matrix with a vector
36  *
37  * \param mat 3x3 matrix
38  * \param vec vector
39  */
40 WVector3d multMatrixWithVector3D( WMatrix<double> mat, WVector3d vec );
41 
42 /**
43  * Applies a coordinate transformation in homogenous coordinates to a vector.
44  * This differs from transformPosition3DWithMatrix4D in that it DOES NOT incorporate the translation
45  *
46  * \param mat 4x4 matrix
47  * \param vec vector
48  */
49 WVector3d transformVector3DWithMatrix4D( WMatrix<double> mat, WVector3d vec );
50 
51 /**
52  * Applies a coordinate transformation in homogenous coordinates to a position.
53  * This differs from transformVector3DWithMatrix4D in that it incorporates the translation.
54  *
55  * \param mat 4x4 matrix
56  * \param vec vector
57  */
58 WPosition transformPosition3DWithMatrix4D( WMatrix<double> mat, WPosition vec );
59 
60 /**
61  * helper routine to invert a 3x3 matrix
62  *
63  * \param mat 3x3 matrix
64  *
65  * \return inverted 3x3 matrix
66  */
67 WMatrix<double> invertMatrix3x3( WMatrix<double> mat );
68 
69 /**
70  * helper routine to invert a 4x4 matrix
71  *
72  * \param mat 4x4 matrix
73  *
74  * \return inverted 4x4 matrix
75  */
76 WMatrix<double> invertMatrix4x4( WMatrix<double> mat );
77 
78 /**
79  * Checks if the given two vectors are linearly independent.
80  *
81  * \param u First vector
82  * \param v Second vector
83  *
84  * \return True if they are linear independent.
85  *
86  * \note This check is performed with the cross product != (0,0,0) but in numerical stability with FLT_EPS.
87  */
88 bool linearIndependent( const WVector3d& u, const WVector3d& v );
89 
90 /**
91  * Computes the SVD for the Matrix \param A
92  *
93  * A=U*S*V^T
94  *
95  * \param A Input Matrix
96  * \param U Output Matrix
97  * \param S Output of the entries in the diagonal matrix
98  * \param V Output Matrix
99  *
100  */
101 void computeSVD( const WMatrix<double>& A, WMatrix<double>& U, WMatrix<double>& V, WValue<double>& S );
102 
103 /**
104  * Calculates for a matrix the pseudo inverse.
105  *
106  * \param input Matrix to invert
107  *
108  * \return Inverted Matrix
109  *
110  */
111 WMatrix<double> pseudoInverse( const WMatrix<double>& input );
112 
113 #endif // WLINEARALGEBRAFUNCTIONS_H