Classes | |
class | TMatrix |
class | TVector |
Functions | |
double | round (double n) |
template<class T > | |
void | VectorPrint (std::ostream &o, T *v, uint n, bool col) |
Functions for vectors. | |
template<class T > | |
T * | VectorAllocateMemory (uint n) |
template<class T > | |
void | VectorFreeMemory (T *v) |
template<class T > | |
void | VectorAssignMemory (T *v, T *v_o, uint n) |
template<class T > | |
T * | VectorCopyMemory (T *v, uint n) |
template<class T > | |
void | VectorAssignScalar (T *v, T s, uint n) |
template<class T > | |
void | VectorMatrixCast (T **ma, T *v, uint n, uint m, bool col) |
template<class T > | |
void | VectorAdd (T *v, T *v_l, T *v_r, uint n) |
template<class T > | |
void | VectorSubtract (T *v, T *v_l, T *v_r, uint 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, uint n) |
template<class T > | |
void | VectorScalarProduct (T *v, T *v_l, T s, uint n) |
template<class T > | |
T | VectorNorm (T *v, uint n) |
template<class T > | |
void | VectorNormalize (T *v, T *v_o, uint n) |
template<class T > | |
void | MatrixPrint (std::ostream &o, T **ma, uint n, uint m) |
Functions for matrices. | |
template<class T > | |
T ** | MatrixAllocateMemory (uint n, uint m) |
template<class T > | |
void | MatrixAssignMemory (T **ma, T **ma_o, uint n, uint m) |
template<class T > | |
T ** | MatrixCopyMemory (T **ma, uint n, uint m) |
template<class T > | |
void | MatrixAssignScalar (T **ma, T s, uint n, uint m) |
template<class T > | |
void | MatrixVectorCast (T *v, T **ma, uint n, uint m, bool col) |
template<class T > | |
void | MatrixFreeMemory (T **ma, uint n) |
template<class T > | |
void | MatrixAdd (T **ma, T **ma_l, T **ma_r, uint n, uint m) |
template<class T > | |
void | MatrixSubtract (T **ma, T **ma_l, T **ma_r, uint n, uint m) |
template<class T > | |
void | MatrixProduct (T **ma, T **ma_l, T **ma_r, uint n, uint m, uint nr) |
template<class T > | |
void | MatrixScalarProduct (T **ma, T **ma_l, T s, uint n, uint m) |
template<class T > | |
void | MatrixCofactor (T **ma, T **ma_o, uint i, uint j, uint n, uint m) |
template<class T > | |
T | MatrixDeterminant (T **ma, uint n) |
template<class T > | |
void | MatrixInverseAdjoint (T **ma, T **ma_o, uint n) |
template<class T > | |
void | MatrixInverseGauss (T **ma, T **ma_o, uint n) |
template<class T > | |
void | MatrixTranspose (T **ma, T **ma_o, uint n, uint m) |
template<class T > | |
void | MatrixLoadIdentity (T **ma, uint n) |
Performs a matricial addition.
ma | Result. | |
ma_l | Left operand. | |
ma_r | Right operand. | |
n | Columns. | |
m | Rows. |
Definition at line 449 of file vmfuncs.h.
00450 { 00451 uint i, j; 00452 00453 for( i = 0; i < n; i++ ) 00454 for( j = 0; j < m; ma[ i ][ j ] = ma_l[ i ][ j ] + ma_r[ i ][ j ], j++ ); 00455 00456 }
Allocates memory for a matrix.
n | Columns. | |
m | Rows. |
Definition at line 325 of file vmfuncs.h.
00326 { 00327 uint i; 00328 T** ma = new T*[ n ]; 00329 00330 for( i = 0; i < n; i++ ) { 00331 00332 ma[ i ] = new T[ m ]; 00333 memset( ma[ i ], 0, sizeof( T ) * m ); 00334 00335 } // rof 00336 return( ma ); 00337 00338 }
void gtm::MatrixCofactor | ( | T ** | ma, | |
T ** | ma_o, | |||
uint | i, | |||
uint | j, | |||
uint | n, | |||
uint | m | |||
) | [inline] |
Gets the matrix cofactor.
ma | Result. | |
ma_o | Matrix. | |
i | Column index. | |
j | Row index. | |
n | Columns. | |
m | Rows. |
Definition at line 536 of file vmfuncs.h.
00537 { 00538 uint k, l; 00539 00540 for( k = 0; k < i; k++ ) { 00541 00542 for( l = 0; l < j; l++ ) ma[ k ][ l ] = ma_o[ k ][ l ]; 00543 for( l = j + 1; l < m; l++ ) ma[ k ][ l - 1 ] = ma_o[ k ][ l ]; 00544 00545 } // rof 00546 00547 for( k = i + 1; k < n; k++ ) { 00548 00549 for( l = 0; l < j; l++ ) ma[ k - 1 ][ l ] = ma_o[ k ][ l ]; 00550 for( l = j + 1; l < m; l++ ) ma[ k - 1 ][ l - 1 ] = ma_o[ k ][ l ]; 00551 00552 } // rof 00553 00554 }
T gtm::MatrixDeterminant | ( | T ** | ma, | |
uint | n | |||
) | [inline] |
Gets the matrix determinant (square matrices only).
ma | Matrix. | |
n | Dimension. |
Definition at line 564 of file vmfuncs.h.
00565 { 00566 uint k; 00567 T** tmp = NULL; 00568 T ret = ( T )0, c; 00569 00570 // All these cases are for speed-up calculations. 00571 if( n == 1 ) { 00572 00573 ret = ma[ 0 ][ 0 ]; 00574 00575 } else if( n == 2 ) { 00576 00577 ret = 00578 ( ma[ 0 ][ 0 ] * ma[ 1 ][ 1 ] ) - 00579 ( ma[ 1 ][ 0 ] * ma[ 0 ][ 1 ] ); 00580 00581 } else if( n == 3 ) { 00582 00583 ret = 00584 ( ma[ 0 ][ 0 ] * ma[ 1 ][ 1 ] * ma[ 2 ][ 2 ] ) - 00585 ( ma[ 0 ][ 0 ] * ma[ 2 ][ 1 ] * ma[ 1 ][ 2 ] ) - 00586 ( ma[ 1 ][ 0 ] * ma[ 0 ][ 1 ] * ma[ 2 ][ 2 ] ) + 00587 ( ma[ 1 ][ 0 ] * ma[ 2 ][ 1 ] * ma[ 0 ][ 2 ] ) + 00588 ( ma[ 2 ][ 0 ] * ma[ 0 ][ 1 ] * ma[ 1 ][ 2 ] ) - 00589 ( ma[ 2 ][ 0 ] * ma[ 1 ][ 1 ] * ma[ 0 ][ 2 ] ); 00590 00591 } else { 00592 00593 tmp = MatrixAllocateMemory< T >( n - 1, n - 1 ); 00594 for( k = 0, c = ( T )1, ret = ( T )0; k < n; k++ ) { 00595 00596 MatrixCofactor< T >( tmp, ma, k, 0, n, n ); 00597 ret = ret + ( c * ( ma[ k ][ 0 ] * MatrixDeterminant< T >( tmp, n - 1 ) ) ); 00598 c = c * ( T )( 0 - 1 ); 00599 00600 } // rof 00601 MatrixFreeMemory< T >( tmp, n - 1 ); 00602 00603 } // fi 00604 return( ret ); 00605 00606 }
void gtm::MatrixFreeMemory | ( | T ** | ma, | |
uint | n | |||
) | [inline] |
void gtm::MatrixInverseAdjoint | ( | T ** | ma, | |
T ** | ma_o, | |||
uint | n | |||
) | [inline] |
Calculates the inverse using the adjoint method (only square matrices).
ma | Result. | |
ma_o | Matrix. | |
n | Dimension. |
Definition at line 617 of file vmfuncs.h.
00618 { 00619 uint i, j; 00620 T** tmp; 00621 T c; 00622 00623 tmp = MatrixAllocateMemory< T >( n - 1, n - 1 ); 00624 for( i = 0; i < n; i++ ) { 00625 00626 for( j = 0; j < n; j++ ) { 00627 00628 c = ( ( i + j ) % 2 == 0 )? ( T )1: ( T )( 0 - 1 ); 00629 MatrixCofactor< T >( tmp, ma_o, i, j, n, n ); 00630 ma[ j ][ i ] = c * MatrixDeterminant< T >( tmp, n - 1 ); 00631 00632 } // rof 00633 00634 } // rof 00635 MatrixFreeMemory< T >( tmp, n - 1 ); 00636 00637 c = ( T )1 / MatrixDeterminant< T >( ma_o, n ); 00638 MatrixScalarProduct< T >( ma, ma, c, n, n ); 00639 00640 }
void gtm::MatrixInverseGauss | ( | T ** | ma, | |
T ** | ma_o, | |||
uint | n | |||
) | [inline] |
Calculates the inverse using the gauss method (only square matrices).
ma | Result. | |
ma_o | Matrix. | |
n | Dimension. |
Definition at line 652 of file vmfuncs.h.
00653 { 00654 uint i, j, k, n2 = 2 * n; 00655 T** ma_a = MatrixAllocateMemory< T >( n2, n ); 00656 T a, b; 00657 00658 // Augmented matrix initialization 00659 for( i = 0; i < n; i++ ) 00660 for( j = 0; j < n; ma_a[ i ][ j ] = ma_o[ i ][ j ], j++ ); 00661 for( i = n; i < n2; i++ ) 00662 for( j = 0; j < n; ma_a[ i ][ j ] = ( i - n == j )? ( T )1: ( T )0, j++ ); 00663 00664 // Reduction 00665 for( j = 0; j < n; j++ ) { 00666 00667 a = ma_a[ j ][ j ]; 00668 if( a != 0 ) for( i = 0; i < n2; ma_a[ i ][ j ] = ma_a[ i ][ j ] / a, i++ ); 00669 for( k = 0; k < n; k++ ) { 00670 00671 if( ( k - j ) != 0 ) { 00672 00673 b = ma_a[ j ][ k ]; 00674 for( 00675 i = 0; 00676 i < n2; 00677 ma_a[ i ][ k ] = ma_a[ i ][ k ] - ( b * ma_a[ i ][ j ] ), i++ 00678 ); 00679 00680 } // fi 00681 00682 } // rof 00683 00684 } // rof 00685 00686 // Result assignation 00687 MatrixAssignMemory< T >( ma, ma_a, n, n ); 00688 MatrixFreeMemory< T >( ma_a, n2 ); 00689 00690 }
void gtm::MatrixLoadIdentity | ( | T ** | ma, | |
uint | n | |||
) | [inline] |
Functions for matrices.
Stream out function for matrices.
o | Output stream. | |
ma | Matrix. | |
n | Columns. | |
m | Rows. |
Definition at line 303 of file vmfuncs.h.
00304 { 00305 uint i, j; 00306 00307 o << n << " x " << m << endl; 00308 for( j = 0; j < m; j++ ) { 00309 00310 for( i = 0; i < n; o << ma[ i ][ j ] << " ", i++ ); 00311 o << endl; 00312 00313 } // rof 00314 00315 }
void gtm::MatrixProduct | ( | T ** | ma, | |
T ** | ma_l, | |||
T ** | ma_r, | |||
uint | n, | |||
uint | m, | |||
uint | 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::MatrixSubtract | ( | T ** | ma, | |
T ** | ma_l, | |||
T ** | ma_r, | |||
uint | n, | |||
uint | m | |||
) | [inline] |
Performs a matricial substraction.
ma | Result. | |
ma_l | Left operand. | |
ma_r | Right operand. | |
n | Columns. | |
m | Rows. |
Definition at line 469 of file vmfuncs.h.
00470 { 00471 uint i, j; 00472 00473 for( i = 0; i < n; i++ ) 00474 for( j = 0; j < m; ma[ i ][ j ] = ma_l[ i ][ j ] - ma_r[ i ][ j ], j++ ); 00475 00476 }
double gtm::round | ( | double | n | ) | [inline] |
void gtm::VectorAdd | ( | T * | v, | |
T * | v_l, | |||
T * | v_r, | |||
uint | n | |||
) | [inline] |
T* gtm::VectorAllocateMemory | ( | uint | n | ) | [inline] |
void gtm::VectorAssignMemory | ( | T * | v, | |
T * | v_o, | |||
uint | n | |||
) | [inline] |
void gtm::VectorAssignScalar | ( | T * | v, | |
T | s, | |||
uint | n | |||
) | [inline] |
T* gtm::VectorCopyMemory | ( | T * | v, | |
uint | 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, | |||
uint | n | |||
) | [inline] |
Performs a vectorial dot product.
v_l | Left operand. | |
v_r | Right operand. | |
n | Cardinality. |
Definition at line 228 of file vmfuncs.h.
00229 { 00230 T ret; 00231 uint i; 00232 00233 for( i = 0, ret = ( T )0; i < n; ret = ret + ( v_l[ i ] * v_r[ i ] ), i++ ); 00234 return( ret ); 00235 00236 }
void gtm::VectorFreeMemory | ( | T * | v | ) | [inline] |
T gtm::VectorNorm | ( | T * | v, | |
uint | n | |||
) | [inline] |
void gtm::VectorNormalize | ( | T * | v, | |
T * | v_o, | |||
uint | n | |||
) | [inline] |
Calculates a normal vector, usign the L2 norm.
v | Result. | |
v_o | Original vector. | |
n | Cardinality. |
Definition at line 279 of file vmfuncs.h.
00280 { 00281 uint i; 00282 T norm = VectorNorm< T >( v_o, n ); 00283 00284 norm = ( norm == ( T )0 )? ( T )1: norm; 00285 for( i = 0; i < n; v[ i ] = v_o[ i ] / norm, i++ ); 00286 00287 }
void gtm::VectorPrint | ( | std::ostream & | o, | |
T * | v, | |||
uint | 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, | |||
uint | n | |||
) | [inline] |
void gtm::VectorSubtract | ( | T * | v, | |
T * | v_l, | |||
T * | v_r, | |||
uint | n | |||
) | [inline] |