This class provides with operations for Matrix Objects + some changes
MatrixMath.h@7:1c6ba87fa6a3, 2020-10-01 (annotated)
- Committer:
- saloutos
- Date:
- Thu Oct 01 04:08:00 2020 +0000
- Revision:
- 7:1c6ba87fa6a3
- Parent:
- 6:aa5e94cddb3f
Same changes as for Matrix library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yo_Robot | 3:48754fe86e08 | 1 | /** |
Yo_Robot | 5:93948a9bbde2 | 2 | * @brief Version 0.9 |
Yo_Robot | 3:48754fe86e08 | 3 | * @file MatrixMath.h |
Yo_Robot | 3:48754fe86e08 | 4 | * @author Ernesto Palacios |
Yo_Robot | 3:48754fe86e08 | 5 | * |
Yo_Robot | 3:48754fe86e08 | 6 | * Created on 15 de septiembre de 2011, 09:44 AM. |
Yo_Robot | 3:48754fe86e08 | 7 | * |
Yo_Robot | 5:93948a9bbde2 | 8 | * Develop Under GPL v3.0 License |
Yo_Robot | 5:93948a9bbde2 | 9 | * http://www.gnu.org/licenses/gpl-3.0.html |
Yo_Robot | 3:48754fe86e08 | 10 | * |
Yo_Robot | 3:48754fe86e08 | 11 | */ |
Yo_Robot | 3:48754fe86e08 | 12 | |
Yo_Robot | 5:93948a9bbde2 | 13 | #ifndef MATRIXMATH_H |
Yo_Robot | 5:93948a9bbde2 | 14 | #define MATRIXMATH_H |
Yo_Robot | 3:48754fe86e08 | 15 | |
Yo_Robot | 3:48754fe86e08 | 16 | #include "mbed.h" |
Yo_Robot | 3:48754fe86e08 | 17 | #include "Matrix.h" |
Yo_Robot | 3:48754fe86e08 | 18 | |
Yo_Robot | 3:48754fe86e08 | 19 | |
Yo_Robot | 3:48754fe86e08 | 20 | /** |
Yo_Robot | 5:93948a9bbde2 | 21 | * @brief This class provides STATIC methods to perform operations |
Yo_Robot | 5:93948a9bbde2 | 22 | * over Matrix Objects, version 0.9. |
Yo_Robot | 3:48754fe86e08 | 23 | */ |
Yo_Robot | 3:48754fe86e08 | 24 | class MatrixMath{ |
Yo_Robot | 3:48754fe86e08 | 25 | public: |
Yo_Robot | 3:48754fe86e08 | 26 | |
Yo_Robot | 3:48754fe86e08 | 27 | |
Yo_Robot | 3:48754fe86e08 | 28 | /**@brief |
Yo_Robot | 3:48754fe86e08 | 29 | * Transposes Matrix, return new Object. |
Yo_Robot | 3:48754fe86e08 | 30 | * @param Mat matrix to calculate |
Yo_Robot | 5:93948a9bbde2 | 31 | * @return Transposed Matrix |
Yo_Robot | 3:48754fe86e08 | 32 | */ |
Yo_Robot | 3:48754fe86e08 | 33 | static Matrix Transpose( const Matrix& Mat ); |
Yo_Robot | 3:48754fe86e08 | 34 | |
Yo_Robot | 3:48754fe86e08 | 35 | |
Yo_Robot | 3:48754fe86e08 | 36 | /**@brief |
Yo_Robot | 5:93948a9bbde2 | 37 | * Calculate the inverse of a [n,n] Matrix BUT you check first if |
Yo_Robot | 5:93948a9bbde2 | 38 | * the determinant is != 0, Same matrix will be return if Det( Mat ) == 0. |
Yo_Robot | 3:48754fe86e08 | 39 | * @param Mat matrix to calcute inverse. |
Yo_Robot | 3:48754fe86e08 | 40 | * @return Matrix Inverse |
Yo_Robot | 3:48754fe86e08 | 41 | */ |
Yo_Robot | 3:48754fe86e08 | 42 | static Matrix Inv( const Matrix& Mat ); |
Yo_Robot | 3:48754fe86e08 | 43 | |
Yo_Robot | 3:48754fe86e08 | 44 | |
Yo_Robot | 3:48754fe86e08 | 45 | /**@brief |
Yo_Robot | 5:93948a9bbde2 | 46 | * Creates an identity [n,n] Matrix |
Yo_Robot | 3:48754fe86e08 | 47 | * @param Rows Number of Rowns and Columns |
Yo_Robot | 5:93948a9bbde2 | 48 | * @return Identity Matrix of dimensions [Rows,Rows] |
Yo_Robot | 3:48754fe86e08 | 49 | */ |
Yo_Robot | 3:48754fe86e08 | 50 | static Matrix Eye( int Rows ); |
Yo_Robot | 5:93948a9bbde2 | 51 | |
Yo_Robot | 3:48754fe86e08 | 52 | |
Yo_Robot | 3:48754fe86e08 | 53 | /**@brief |
Yo_Robot | 3:48754fe86e08 | 54 | * Returns the dot Product of any two same leght vectors. |
Yo_Robot | 5:93948a9bbde2 | 55 | * In this case a vector is defined as a [1,n] or [n,1] Matrix. |
Yo_Robot | 5:93948a9bbde2 | 56 | * Very Flexible Function. |
Yo_Robot | 3:48754fe86e08 | 57 | * @param leftM First Vector |
Yo_Robot | 3:48754fe86e08 | 58 | * @param rightM Second Vector |
Yo_Robot | 3:48754fe86e08 | 59 | * @return Dot Product or Scalar Product. |
Yo_Robot | 3:48754fe86e08 | 60 | */ |
Yo_Robot | 3:48754fe86e08 | 61 | static float dot( const Matrix& leftM, const Matrix& rightM ); |
Yo_Robot | 5:93948a9bbde2 | 62 | |
Yo_Robot | 3:48754fe86e08 | 63 | |
Yo_Robot | 3:48754fe86e08 | 64 | /**@brief Calculates the determinant of a Matrix. |
Yo_Robot | 3:48754fe86e08 | 65 | * @param Mat matrix to calculate. |
Yo_Robot | 3:48754fe86e08 | 66 | * @return the determinant. |
Yo_Robot | 3:48754fe86e08 | 67 | */ |
Yo_Robot | 3:48754fe86e08 | 68 | static float det( const Matrix& Mat ); |
Yo_Robot | 3:48754fe86e08 | 69 | |
mori3rti | 6:aa5e94cddb3f | 70 | /**@brief Calculates Kronecker product of two Matrix. |
mori3rti | 6:aa5e94cddb3f | 71 | * Kronecker product is an operation on two matrices of arbitrary |
mori3rti | 6:aa5e94cddb3f | 72 | * size resulting in a block matrix. If A is an m × n matrix |
mori3rti | 6:aa5e94cddb3f | 73 | * and B is a p × q matrix, then the Kronecker product A ⊗ B is |
mori3rti | 6:aa5e94cddb3f | 74 | * the pm × qn block matrix: |
mori3rti | 6:aa5e94cddb3f | 75 | * - - |
mori3rti | 6:aa5e94cddb3f | 76 | * | a_11 B ... a_1n B | |
mori3rti | 6:aa5e94cddb3f | 77 | * A ⊗ B = | ... ... ... | |
mori3rti | 6:aa5e94cddb3f | 78 | * | a_m1 B ... a_mn B | |
mori3rti | 6:aa5e94cddb3f | 79 | * - - |
mori3rti | 6:aa5e94cddb3f | 80 | * @param Mat_A Matrix m × n |
mori3rti | 6:aa5e94cddb3f | 81 | * @param Mat_B Matrix p × q |
mori3rti | 6:aa5e94cddb3f | 82 | * @return Kron Matrix pm × qn. |
mori3rti | 6:aa5e94cddb3f | 83 | */ |
mori3rti | 6:aa5e94cddb3f | 84 | static Matrix kron(const Matrix& Mat_A, const Matrix& Mat_B); |
mori3rti | 6:aa5e94cddb3f | 85 | |
Yo_Robot | 3:48754fe86e08 | 86 | |
Yo_Robot | 3:48754fe86e08 | 87 | //==== For Kinematics ====// |
Yo_Robot | 3:48754fe86e08 | 88 | |
Yo_Robot | 3:48754fe86e08 | 89 | /**@brief |
Yo_Robot | 3:48754fe86e08 | 90 | * Calculates the Rotation Matrix Transform along 'x' axis in radians. |
Yo_Robot | 3:48754fe86e08 | 91 | * @param radians rotation angle. |
Yo_Robot | 3:48754fe86e08 | 92 | * @return Rotation Matrix[4,4] along 'x' axis. |
Yo_Robot | 3:48754fe86e08 | 93 | */ |
Yo_Robot | 3:48754fe86e08 | 94 | static Matrix RotX( float radians ); |
Yo_Robot | 3:48754fe86e08 | 95 | |
Yo_Robot | 3:48754fe86e08 | 96 | |
Yo_Robot | 3:48754fe86e08 | 97 | /**@brief |
Yo_Robot | 3:48754fe86e08 | 98 | * Calculates the Rotation Matrix Transform along 'y' axis in radians. |
Yo_Robot | 3:48754fe86e08 | 99 | * @param radians rotation angle. |
Yo_Robot | 3:48754fe86e08 | 100 | * @return Rotation Matrix[4,4] along 'y' axis. |
Yo_Robot | 3:48754fe86e08 | 101 | */ |
Yo_Robot | 3:48754fe86e08 | 102 | static Matrix RotY( float radians ); |
Yo_Robot | 3:48754fe86e08 | 103 | |
Yo_Robot | 3:48754fe86e08 | 104 | |
Yo_Robot | 3:48754fe86e08 | 105 | /**@brief |
Yo_Robot | 5:93948a9bbde2 | 106 | * Calculates the Rotation Matrix Transform along 'z' axis in radians. |
Yo_Robot | 3:48754fe86e08 | 107 | * @param radians rotation angle. |
Yo_Robot | 5:93948a9bbde2 | 108 | * @return Rotation Matrix[4,4] along 'z' axis. |
Yo_Robot | 3:48754fe86e08 | 109 | */ |
Yo_Robot | 3:48754fe86e08 | 110 | static Matrix RotZ( float radians ); |
Yo_Robot | 3:48754fe86e08 | 111 | |
Yo_Robot | 3:48754fe86e08 | 112 | /**@brief |
Yo_Robot | 5:93948a9bbde2 | 113 | * Calculates the Translation Matrix to coordenates (x' y' z'). |
Yo_Robot | 3:48754fe86e08 | 114 | * @param x axis translation |
Yo_Robot | 3:48754fe86e08 | 115 | * @param y axis translation |
Yo_Robot | 3:48754fe86e08 | 116 | * @param z axis translation |
Yo_Robot | 3:48754fe86e08 | 117 | * @return Translation Matrix[4,4] x'y'z'. |
Yo_Robot | 3:48754fe86e08 | 118 | */ |
Yo_Robot | 3:48754fe86e08 | 119 | static Matrix Transl( float x, float y, float z ); |
Yo_Robot | 3:48754fe86e08 | 120 | |
Yo_Robot | 3:48754fe86e08 | 121 | private: |
Yo_Robot | 3:48754fe86e08 | 122 | |
Yo_Robot | 3:48754fe86e08 | 123 | /**@brief |
Yo_Robot | 3:48754fe86e08 | 124 | * Calculates the Determinant of a 3x3 Matrix |
Yo_Robot | 3:48754fe86e08 | 125 | * @param Mat Already made sure is a 3 by 3 |
Yo_Robot | 3:48754fe86e08 | 126 | * @return Float, determinant. |
Yo_Robot | 3:48754fe86e08 | 127 | */ |
Yo_Robot | 3:48754fe86e08 | 128 | float Det3x3( const Matrix& Mat ); |
Yo_Robot | 3:48754fe86e08 | 129 | |
Yo_Robot | 3:48754fe86e08 | 130 | }; |
Yo_Robot | 3:48754fe86e08 | 131 | |
Yo_Robot | 3:48754fe86e08 | 132 | #endif /* MATRIXMATH_H */ |