Imported Upstream version 2.81
[platform/upstream/libbullet.git] / src / LinearMath / btPolarDecomposition.h
1 #ifndef POLARDECOMPOSITION_H
2 #define POLARDECOMPOSITION_H
3
4 #include "btMatrix3x3.h"
5
6 /**
7  * This class is used to compute the polar decomposition of a matrix. In
8  * general, the polar decomposition factorizes a matrix, A, into two parts: a
9  * unitary matrix (U) and a positive, semi-definite Hermitian matrix (H).
10  * However, in this particular implementation the original matrix, A, is
11  * required to be a square 3x3 matrix with real elements. This means that U will
12  * be an orthogonal matrix and H with be a positive-definite, symmetric matrix.
13  */
14 class btPolarDecomposition
15 {
16   public:
17     static const btScalar DEFAULT_TOLERANCE;
18     static const unsigned int DEFAULT_MAX_ITERATIONS;
19
20     /**
21      * Creates an instance with optional parameters.
22      *
23      * @param tolerance     - the tolerance used to determine convergence of the
24      *                        algorithm
25      * @param maxIterations - the maximum number of iterations used to achieve
26      *                        convergence
27      */
28     btPolarDecomposition(btScalar tolerance = DEFAULT_TOLERANCE, 
29       unsigned int maxIterations = DEFAULT_MAX_ITERATIONS);
30
31     /**
32      * Decomposes a matrix into orthogonal and symmetric, positive-definite
33      * parts. If the number of iterations returned by this function is equal to
34      * the maximum number of iterations, the algorithm has failed to converge.
35      *
36      * @param a - the original matrix
37      * @param u - the resulting orthogonal matrix
38      * @param h - the resulting symmetric matrix
39      *
40      * @return the number of iterations performed by the algorithm.
41      */
42     unsigned int decompose(const btMatrix3x3& a, btMatrix3x3& u, btMatrix3x3& h) const; 
43
44     /**
45      * Returns the maximum number of iterations that this algorithm will perform
46      * to achieve convergence.
47      *
48      * @return maximum number of iterations
49      */
50     unsigned int maxIterations() const;
51
52   private:
53     btScalar m_tolerance;
54     unsigned int m_maxIterations;
55 };
56
57 /**
58  * This functions decomposes the matrix 'a' into two parts: an orthogonal matrix
59  * 'u' and a symmetric, positive-definite matrix 'h'. If the number of
60  * iterations returned by this function is equal to
61  * btPolarDecomposition::DEFAULT_MAX_ITERATIONS, the algorithm has failed to
62  * converge.
63  *
64  * @param a - the original matrix
65  * @param u - the resulting orthogonal matrix
66  * @param h - the resulting symmetric matrix
67  *
68  * @return the number of iterations performed by the algorithm.
69  */
70 unsigned int polarDecompose(const btMatrix3x3& a, btMatrix3x3& u, btMatrix3x3& h); 
71
72 #endif // POLARDECOMPOSITION_H
73