The matrix classes

Definition

Here are different methods to create a matrix object:
        // Produces an zero filles matrix3
        tmath::matrix<type,row, column> m1;     
                
        // Initiates the vectorn<T,3> with values                               
        tmath::matrix<float,3,3> m2(0.0f, 1.0f, 25.65f, 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 3.0f);
        
        // Initiates the matrix3 by another matrix3
        tmath::matrix<float,3,3> m3(v2);        
        
        // Initiates the matrix3 by an array of values
        float values[9] = {0.0f, 1.0f, 25.65f, 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 3.0f};
        tmath::matrix<float,3,3> m3(values);    

Addition, Subtraction

A matrix can be added or subtracted like following example:

        tmath::matrix<float,3,3> m1;
        tmath::matrix<float,3,3> m2;
        tmath::matrix<float,3,3> m3;
        
        // Addition
        m3 = m1 + m2;
        m3 += m1;
        
        // Subtraction
        m3 = m1 - m2;
        m3 -= m1;

Multiplication and Division

Two matrices are multiplicated by row-column order.

        tmath::matrix<float,3,3> m1;
        tmath::matrix<float,3,3> m2;
        tmath::matrix<float,3,3> m3;
        
        // Multiplication with a matrix
        m3 = m1 * m2;
        
        // Multiplication with a scalar 
        m2 = m1 * 1.0f;
        
        // Dito
        m3 = 1.0f * m1;

A matrix can be multiplicated with a vector, too. The resut is a vectorn<T,3>

        tmath::matrix<float,3,3>> m1;
        tmath::vectorn<float,3> v1, res;

        res = m1 * v1;  

Other functions

To create a null or identity matrix use the null() and identity() function:
        tmath::matrix<float,3,3> m1,m2;
        tmath::null(m1);
        tmath::identity(m2);

To transpose a matrix use the transp() function

        tmath::matrix<float,3,3> m(0.0f, 1.0f, 25.65f, 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 3.0f), mres;
        mres = tmath::transp(m);

If you need the inverse of the matrix use the inv() function:

        tmath::matrix<float,3,3> m(0.0f, 1.0f, 25.65f, 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 3.0f), mres;
        mres = tmath::inv(m);

To calculate the determinant of the matrix use the det() function:

        tmath::matrix<float,3,3> m(0.0f, 1.0f, 25.65f, 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 3.0f), mres;
        mres = tmath::det(m);

Access to the components

There are two possible access methods. One is to use the .xx .xy .xz ... variable names.

        tmath::matrix<float,3,3 m1;
        float xx = m1.xx;
        float xy = m1.xy;
        float xz = m1.xz;
        float yx = m1.yx;
        float yy = m1.yy;
        float yz = m1.yz;
        ...

Second, you can use the matrix itself as a pointer of an array. You can access the components with the [] operator.

        tmath::matrix<float,3,3> m1;
        float* v = m1;
        float xcomp = v[0]; // xx
        float ycomp = v[1]; // xy
        float zcomp = v[2]; // xz
        ...

Please keep in mind that the element access via the [] operator are not designed for security checking. This means no border checks are done.

String Output

You can use the std::cout method to print out the components of the matrix.
        tmath::matrix<float,3,3> m1;
        std::cout << m1 << std::endl; 

Conversion

You can convert between a matrix<float,3,3> and matrix<float,4,4>.
        tmath::matrix3 m1(....);
        tmath::matrix4 m2;
        tmath::conv(m1,m2);
Of course, you can convert it the other way around. The last row of the matrix converted from a matrix<float,3,3> is filled with (0.0f, 0.0f, 0.0f, 0.0f);
Generated on Mon Sep 10 17:42:12 2007 for TinyMath by  doxygen 1.5.2