Classes | |
class | TMatrix |
class | TVector |
Functions | |
double | round (double n) |
template<class T > | |
void | VectorPrint (std::ostream &o, T *v, uint32_t n, bool col) |
Functions for vectors. | |
template<class T > | |
T * | VectorAllocateMemory (uint32_t n) |
template<class T > | |
void | VectorFreeMemory (T *v) |
template<class T > | |
void | VectorAssignMemory (T *v, T *v_o, uint32_t n) |
template<class T > | |
T * | VectorCopyMemory (T *v, uint32_t n) |
template<class T > | |
void | VectorAssignScalar (T *v, T s, uint32_t n) |
template<class T > | |
void | VectorMatrixCast (T **ma, T *v, uint32_t n, uint32_t m, bool col) |
template<class T > | |
void | VectorAdd (T *v, T *v_l, T *v_r, uint32_t n) |
template<class T > | |
void | VectorSubtract (T *v, T *v_l, T *v_r, uint32_t n) |
template<class T > | |
void | VectorCrossProduct (T *v, T *v_l, T *v_r) |
template<class T > | |
T | VectorDotProduct (T *v_l, T *v_r, uint32_t n) |
template<class T > | |
void | VectorScalarProduct (T *v, T *v_l, T s, uint32_t n) |
template<class T > | |
T | VectorNorm (T *v, uint32_t n) |
template<class T > | |
void | VectorNormalize (T *v, T *v_o, uint32_t n) |
template<class T > | |
void | MatrixPrint (std::ostream &o, T **ma, uint32_t n, uint32_t m) |
Functions for matrices. | |
template<class T > | |
T ** | MatrixAllocateMemory (uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixAssignMemory (T **ma, T **ma_o, uint32_t n, uint32_t m) |
template<class T > | |
T ** | MatrixCopyMemory (T **ma, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixAssignScalar (T **ma, T s, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixVectorCast (T *v, T **ma, uint32_t n, uint32_t m, bool col) |
template<class T > | |
void | MatrixFreeMemory (T **ma, uint32_t n) |
template<class T > | |
void | MatrixAdd (T **ma, T **ma_l, T **ma_r, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixSubtract (T **ma, T **ma_l, T **ma_r, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixProduct (T **ma, T **ma_l, T **ma_r, uint32_t n, uint32_t m, uint32_t nr) |
template<class T > | |
void | MatrixScalarProduct (T **ma, T **ma_l, T s, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixCofactor (T **ma, T **ma_o, uint32_t i, uint32_t j, uint32_t n, uint32_t m) |
template<class T > | |
T | MatrixDeterminant (T **ma, uint32_t n) |
template<class T > | |
void | MatrixInverseAdjoint (T **ma, T **ma_o, uint32_t n) |
template<class T > | |
void | MatrixInverseGauss (T **ma, T **ma_o, uint32_t n) |
template<class T > | |
void | MatrixTranspose (T **ma, T **ma_o, uint32_t n, uint32_t m) |
template<class T > | |
void | MatrixLoadIdentity (T **ma, uint32_t n) |
void gtm::MatrixAdd | ( | T ** | ma, | |
T ** | ma_l, | |||
T ** | ma_r, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
Performs a matricial addition.
ma | Result. | |
ma_l | Left operand. | |
ma_r | Right operand. | |
n | Columns. | |
m | Rows. |
T** gtm::MatrixAllocateMemory | ( | uint32_t | n, | |
uint32_t | m | |||
) | [inline] |
Allocates memory for a matrix.
n | Columns. | |
m | Rows. |
void gtm::MatrixAssignMemory | ( | T ** | ma, | |
T ** | ma_o, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
void gtm::MatrixAssignScalar | ( | T ** | ma, | |
T | s, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
void gtm::MatrixCofactor | ( | T ** | ma, | |
T ** | ma_o, | |||
uint32_t | i, | |||
uint32_t | j, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
Gets the matrix cofactor.
ma | Result. | |
ma_o | Matrix. | |
i | Column index. | |
j | Row index. | |
n | Columns. | |
m | Rows. |
Definition at line 538 of file vmfuncs.h.
00539 { 00540 uint32_t k, l; 00541 00542 for( k = 0; k < i; k++ ) { 00543 00544 for( l = 0; l < j; l++ ) ma[ k ][ l ] = ma_o[ k ][ l ]; 00545 for( l = j + 1; l < m; l++ ) ma[ k ][ l - 1 ] = ma_o[ k ][ l ]; 00546 00547 } // rof 00548 00549 for( k = i + 1; k < n; k++ ) { 00550 00551 for( l = 0; l < j; l++ ) ma[ k - 1 ][ l ] = ma_o[ k ][ l ]; 00552 for( l = j + 1; l < m; l++ ) ma[ k - 1 ][ l - 1 ] = ma_o[ k ][ l ]; 00553 00554 } // rof 00555 00556 }
T** gtm::MatrixCopyMemory | ( | T ** | ma, | |
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
T gtm::MatrixDeterminant | ( | T ** | ma, | |
uint32_t | n | |||
) | [inline] |
Gets the matrix determinant (square matrices only).
ma | Matrix. | |
n | Dimension. |
Definition at line 566 of file vmfuncs.h.
00567 { 00568 uint32_t k; 00569 T** tmp = NULL; 00570 T ret = ( T )0, c; 00571 00572 // All these cases are for speed-up calculations. 00573 if( n == 1 ) { 00574 00575 ret = ma[ 0 ][ 0 ]; 00576 00577 } else if( n == 2 ) { 00578 00579 ret = 00580 ( ma[ 0 ][ 0 ] * ma[ 1 ][ 1 ] ) - 00581 ( ma[ 1 ][ 0 ] * ma[ 0 ][ 1 ] ); 00582 00583 } else if( n == 3 ) { 00584 00585 ret = 00586 ( ma[ 0 ][ 0 ] * ma[ 1 ][ 1 ] * ma[ 2 ][ 2 ] ) - 00587 ( ma[ 0 ][ 0 ] * ma[ 2 ][ 1 ] * ma[ 1 ][ 2 ] ) - 00588 ( ma[ 1 ][ 0 ] * ma[ 0 ][ 1 ] * ma[ 2 ][ 2 ] ) + 00589 ( ma[ 1 ][ 0 ] * ma[ 2 ][ 1 ] * ma[ 0 ][ 2 ] ) + 00590 ( ma[ 2 ][ 0 ] * ma[ 0 ][ 1 ] * ma[ 1 ][ 2 ] ) - 00591 ( ma[ 2 ][ 0 ] * ma[ 1 ][ 1 ] * ma[ 0 ][ 2 ] ); 00592 00593 } else { 00594 00595 tmp = MatrixAllocateMemory< T >( n - 1, n - 1 ); 00596 for( k = 0, c = ( T )1, ret = ( T )0; k < n; k++ ) { 00597 00598 MatrixCofactor< T >( tmp, ma, k, 0, n, n ); 00599 ret = ret + ( c * ( ma[ k ][ 0 ] * MatrixDeterminant< T >( tmp, n - 1 ) ) ); 00600 c = c * ( T )( 0 - 1 ); 00601 00602 } // rof 00603 MatrixFreeMemory< T >( tmp, n - 1 ); 00604 00605 } // fi 00606 return( ret ); 00607 00608 }
void gtm::MatrixFreeMemory | ( | T ** | ma, | |
uint32_t | n | |||
) | [inline] |
void gtm::MatrixInverseAdjoint | ( | T ** | ma, | |
T ** | ma_o, | |||
uint32_t | n | |||
) | [inline] |
Calculates the inverse using the adjoint method (only square matrices).
ma | Result. | |
ma_o | Matrix. | |
n | Dimension. |
Definition at line 619 of file vmfuncs.h.
00620 { 00621 uint32_t i, j; 00622 T** tmp; 00623 T c; 00624 00625 tmp = MatrixAllocateMemory< T >( n - 1, n - 1 ); 00626 for( i = 0; i < n; i++ ) { 00627 00628 for( j = 0; j < n; j++ ) { 00629 00630 c = ( ( i + j ) % 2 == 0 )? ( T )1: ( T )( 0 - 1 ); 00631 MatrixCofactor< T >( tmp, ma_o, i, j, n, n ); 00632 ma[ j ][ i ] = c * MatrixDeterminant< T >( tmp, n - 1 ); 00633 00634 } // rof 00635 00636 } // rof 00637 MatrixFreeMemory< T >( tmp, n - 1 ); 00638 00639 c = ( T )1 / MatrixDeterminant< T >( ma_o, n ); 00640 MatrixScalarProduct< T >( ma, ma, c, n, n ); 00641 00642 }
void gtm::MatrixInverseGauss | ( | T ** | ma, | |
T ** | ma_o, | |||
uint32_t | n | |||
) | [inline] |
Calculates the inverse using the gauss method (only square matrices).
ma | Result. | |
ma_o | Matrix. | |
n | Dimension. |
Definition at line 654 of file vmfuncs.h.
00655 { 00656 uint32_t i, j, k, n2 = 2 * n; 00657 T** ma_a = MatrixAllocateMemory< T >( n2, n ); 00658 T a, b; 00659 00660 // Augmented matrix initialization 00661 for( i = 0; i < n; i++ ) 00662 for( j = 0; j < n; ma_a[ i ][ j ] = ma_o[ i ][ j ], j++ ); 00663 for( i = n; i < n2; i++ ) 00664 for( j = 0; j < n; ma_a[ i ][ j ] = ( i - n == j )? ( T )1: ( T )0, j++ ); 00665 00666 // Reduction 00667 for( j = 0; j < n; j++ ) { 00668 00669 a = ma_a[ j ][ j ]; 00670 if( a != 0 ) for( i = 0; i < n2; ma_a[ i ][ j ] = ma_a[ i ][ j ] / a, i++ ); 00671 for( k = 0; k < n; k++ ) { 00672 00673 if( ( k - j ) != 0 ) { 00674 00675 b = ma_a[ j ][ k ]; 00676 for( 00677 i = 0; 00678 i < n2; 00679 ma_a[ i ][ k ] = ma_a[ i ][ k ] - ( b * ma_a[ i ][ j ] ), i++ 00680 ); 00681 00682 } // fi 00683 00684 } // rof 00685 00686 } // rof 00687 00688 // Result assignation 00689 MatrixAssignMemory< T >( ma, ma_a, n, n ); 00690 MatrixFreeMemory< T >( ma_a, n2 ); 00691 00692 }
void gtm::MatrixLoadIdentity | ( | T ** | ma, | |
uint32_t | n | |||
) | [inline] |
void gtm::MatrixPrint | ( | std::ostream & | o, | |
T ** | ma, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
Functions for matrices.
Stream out function for matrices.
o | Output stream. | |
ma | Matrix. | |
n | Columns. | |
m | Rows. |
void gtm::MatrixProduct | ( | T ** | ma, | |
T ** | ma_l, | |||
T ** | ma_r, | |||
uint32_t | n, | |||
uint32_t | m, | |||
uint32_t | nr | |||
) | [inline] |
Performs a matricial product.
ma | Result. | |
ma_l | Left operand. | |
ma_r | Right operand. | |
n | Left columns. | |
m | Left rows/right columns. | |
nr | Right columns. |
void gtm::MatrixScalarProduct | ( | T ** | ma, | |
T ** | ma_l, | |||
T | s, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
void gtm::MatrixSubtract | ( | T ** | ma, | |
T ** | ma_l, | |||
T ** | ma_r, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
Performs a matricial substraction.
ma | Result. | |
ma_l | Left operand. | |
ma_r | Right operand. | |
n | Columns. | |
m | Rows. |
void gtm::MatrixTranspose | ( | T ** | ma, | |
T ** | ma_o, | |||
uint32_t | n, | |||
uint32_t | m | |||
) | [inline] |
void gtm::MatrixVectorCast | ( | T * | v, | |
T ** | ma, | |||
uint32_t | n, | |||
uint32_t | m, | |||
bool | col | |||
) | [inline] |
Converts a matrix in a vector.
v | Vector. | |
ma | Matrix. | |
n | Columns. | |
m | Rows. | |
col | Convert to a column vector? |
double gtm::round | ( | double | n | ) | [inline] |
void gtm::VectorAdd | ( | T * | v, | |
T * | v_l, | |||
T * | v_r, | |||
uint32_t | n | |||
) | [inline] |
T* gtm::VectorAllocateMemory | ( | uint32_t | n | ) | [inline] |
void gtm::VectorAssignMemory | ( | T * | v, | |
T * | v_o, | |||
uint32_t | n | |||
) | [inline] |
void gtm::VectorAssignScalar | ( | T * | v, | |
T | s, | |||
uint32_t | n | |||
) | [inline] |
T* gtm::VectorCopyMemory | ( | T * | v, | |
uint32_t | n | |||
) | [inline] |
void gtm::VectorCrossProduct | ( | T * | v, | |
T * | v_l, | |||
T * | v_r | |||
) | [inline] |
Performs a vectorial cross product.
v | Result. | |
v_l | Left operand. | |
v_r | Right operand. |
T gtm::VectorDotProduct | ( | T * | v_l, | |
T * | v_r, | |||
uint32_t | n | |||
) | [inline] |
Performs a vectorial dot product.
v_l | Left operand. | |
v_r | Right operand. | |
n | Cardinality. |
void gtm::VectorFreeMemory | ( | T * | v | ) | [inline] |
void gtm::VectorMatrixCast | ( | T ** | ma, | |
T * | v, | |||
uint32_t | n, | |||
uint32_t | m, | |||
bool | col | |||
) | [inline] |
T gtm::VectorNorm | ( | T * | v, | |
uint32_t | n | |||
) | [inline] |
void gtm::VectorNormalize | ( | T * | v, | |
T * | v_o, | |||
uint32_t | n | |||
) | [inline] |
Calculates a normal vector, usign the L2 norm.
v | Result. | |
v_o | Original vector. | |
n | Cardinality. |
void gtm::VectorPrint | ( | std::ostream & | o, | |
T * | v, | |||
uint32_t | n, | |||
bool | col | |||
) | [inline] |
Functions for vectors.
Stream out function for vectors.
o | Output stream. | |
v | ANSI array. | |
n | Cardinality. | |
col | Should I print it in column format? |
void gtm::VectorScalarProduct | ( | T * | v, | |
T * | v_l, | |||
T | s, | |||
uint32_t | n | |||
) | [inline] |
void gtm::VectorSubtract | ( | T * | v, | |
T * | v_l, | |||
T * | v_r, | |||
uint32_t | n | |||
) | [inline] |