Documentation for vtkMath

vtkMath - performs common math operations

Super Class: vtkObject

Description:

vtkMath is provides methods to perform common math operations. These include providing constants such as Pi; conversion from degrees to radians; vector operations such as dot and cross products and vector norm; matrix determinant for 2x2 and 3x3 matrices; and random number generation.

 

Methods:

static vtkMath *New ()
const char *GetClassName ()
static float Pi ()
static float DegreesToRadians ()
static float Dot (float ,float )
static double Dot (double ,double )
static void Cross (float ,float ,float )
static float Norm (float )
static float Normalize (float )
static float Distance2BetweenPoints (float ,float )
static float Dot2D (float ,float )
static double Dot2D (double ,double )
static float Norm2D (float )
static float Normalize2D (float )
static float Determinant2x2 (float ,float )
static double Determinant2x2 (double ,double ,double ,double )
static float Determinant3x3 (float ,float ,float )
static double Determinant3x3 (double ,double ,double ,double ,double ,double ,double ,double ,double )
static int SolveLinearSystem (double ,double * ,int )
static int InvertMatrix (double ,double ,int )
static int LUFactorLinearSystem (double ,int * ,int )
static void LUSolveLinearSystem (double ,int * ,double * ,int )
static double EstimateMatrixCondition (double ,int )
static void RandomSeed (long )
static float Random ()
static float Random (float ,float )
static int Jacobi (float ,float * ,float )
static double *SolveCubic (double ,double ,double ,double )
static double *SolveQuadratic (double ,double ,double )
static double *SolveLinear (double ,double )
static int SolveCubic (double ,double ,double ,double ,double * ,double * ,double * ,int *)
static int SolveQuadratic (double ,double ,double ,double * ,double * ,int *)
static int SolveLinear (double ,double ,double * ,int *)

 

Detailed Method Descriptions:

Useful constants.

static float Pi ()
static float DegreesToRadians ()

Dot product of two 3-vectors (float version).

static float Dot (float ,float )

Dot product of two 3-vectors (double-precision version).

static double Dot (double ,double )

Cross product of two 3-vectors. Result vector in z[3].

static void Cross (float ,float ,float )

Compute the norm of 3-vector.

static float Norm (float )

Normalize (in place) a 3-vector. Returns norm of vector.

static float Normalize (float )

Compute distance squared between two points.

static float Distance2BetweenPoints (float ,float )

Dot product of two 2-vectors. The third (z) component is ignored.

static float Dot2D (float ,float )

Dot product of two 2-vectors. The third (z) component is ignored. (Double-precision version.)

static double Dot2D (double ,double )

Compute the norm of a 2-vector. Ignores z-component.

static float Norm2D (float )

Normalize (in place) a 2-vector. Returns norm of vector. Ignores z-component.

static float Normalize2D (float )

Compute determinant of 2x2 matrix. Two columns of matrix are input.

static float Determinant2x2 (float ,float )

Calculate the determinant of a 2x2 matrix: | a b | | c d |

static double Determinant2x2 (double ,double ,double ,double )

Compute determinant of 3x3 matrix. Three columns of matrix are input.

static float Determinant3x3 (float ,float ,float )

Calculate the determinent of a 3x3 matrix in the form: | a1, b1, c1 | | a2, b2, c2 | | a3, b3, c3 |

static double Determinant3x3 (double ,double ,double ,double ,double ,double ,double ,double ,double )

Solve linear equations Ax = b using Crout's method. Input is square matrix A and load vector x. Solution x is written over load vector. The dimension of the matrix is specified in size. If error is found, method returns a 0.

static int SolveLinearSystem (double ,double * ,int )

Invert input square matrix A into matrix AI. Note that A is modified during the inversion. The size variable is the dimension of the matrix. Returns 0 if inverse not computed.

static int InvertMatrix (double ,double ,int )

Factor linear equations Ax = b using LU decompostion A = LU where L is lower triangular matrix and U is upper triangular matrix. Input is square matrix A, integer array of pivot indices index[0->n-1], and size of square matrix n. Output factorization LU is in matrix A. If error is found, method returns 0.

static int LUFactorLinearSystem (double ,int * ,int )

Solve linear equations Ax = b using LU decompostion A = LU where L is lower triangular matrix and U is upper triangular matrix. Input is factored matrix A=LU, integer array of pivot indices index[0->n-1], load vector x[0->n-1], and size of square matrix n. Note that A=LU and index[] are generated from method LUFactorLinearSystem). Also, solution vector is written directly over input load vector.

static void LUSolveLinearSystem (double ,int * ,double * ,int )

Estimate the condition number of a LU factored matrix. Used to judge the accuracy of the solution. The matrix A must have been previously factored using the method LUFactorLinearSystem. The condition number is the ratio of the infinity matrix norm (i.e., maximum value of matrix component) divided by the minimum diagonal value. (This works for triangular matrices only: see Conte and de Boor, Elementary Numerical Analysis.)

static double EstimateMatrixCondition (double ,int )

Initialize seed value. NOTE: Random() has the bad property that the first random number returned after RandomSeed() is called is proportional to the seed value! To help solve this, call RandomSeed() a few times inside seed. This doesn't ruin the repeatability of Random().

static void RandomSeed (long )

Generate random numbers between 0.0 and 1.0. This is used to provide portability across different systems.

static float Random ()

Generate random number between (min,max).

static float Random (float ,float )

Jacobi iteration for the solution of eigenvectors/eigenvalues of a 3x3 real symmetric matrix. Square 3x3 matrix a; output eigenvalues in w; and output eigenvectors in v. Resulting eigenvalues/vectors are sorted in decreasing order; eigenvectors are normalized.

static int Jacobi (float ,float * ,float )

Solves a cubic equation c0*t^3 + c1*t^2 + c2*t + c3 = 0 when c0, c1, c2, and c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Return array contains number of (real) roots (counting multiple roots as one) followed by roots themselves. The value in roots[4] is a integer giving further information about the roots (see return codes for int SolveCubic()).

static double *SolveCubic (double ,double ,double ,double )

Solves a quadratic equation c1*t^2 + c2*t + c3 = 0 when c1, c2, and c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Return array contains number of (real) roots (counting multiple roots as one) followed by roots themselves. Note that roots[3] contains a return code further describing solution - see documentation for SolveCubic() for meaining of return codes.

static double *SolveQuadratic (double ,double ,double )

Solves a linear equation c2*t + c3 = 0 when c2 and c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Return array contains number of roots followed by roots themselves.

static double *SolveLinear (double ,double )

Solves a cubic equation when c0, c1, c2, And c3 Are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Roots and number of real roots are stored in user provided variables r1, r2, r3, and num_roots. Note that the function can return the following integer values describing the roots: (0)-no solution; (-1)-infinite number of solutions; (1)-one distinct real root of multiplicity 3 (stored in r1); (2)-two distinct real roots, one of multiplicity 2 (stored in r1 & r2); (3)-three distinct real roots; (-2)-quadratic equation with complex conjugate solution (real part of root returned in r1, imaginary in r2); (-3)-one real root and a complex conjugate pair (real root in r1 and real part of pair in r2 and imaginary in r3).

static int SolveCubic (double ,double ,double ,double ,double * ,double * ,double * ,int *)

Solves A Quadratic Equation c1*t^2 + c2*t + c3 = 0 when c1, c2, and c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Roots and number of roots are stored in user provided variables r1, r2, num_roots

static int SolveQuadratic (double ,double ,double ,double * ,double * ,int *)

Solves a linear equation c2*t + c3 = 0 when c2 and c3 are REAL. Solution is motivated by Numerical Recipes In C 2nd Ed. Root and number of (real) roots are stored in user provided variables r2 and num_roots.

static int SolveLinear (double ,double ,double * ,int *)