[SML Overview]

# class SMLMatrix3f

    #include smlmath.h

SMLMatrix3f class defines 3x3 matrix of single precision floats. It includes data and methods which allow to form matrices, multiply two matrices, transpose them, define matrix of rotation with a certain angle around some given axis, and on the base of given rotation matrix obtain coordinates of the axis, around which this rotation is carried out, and angle of rotation.

## Public Interface

### Constructors and Destructor

constructors | destructor

### Access Elements

operator= | Set | Get
TransformPoint | Multiply | GetMatrix
Copy | Identity | Zero
Cross | Rotate | GetMatrix4f
SetByMatrix4f | Output | Transpose
QuaternionMatrix |  |

SMLLIBENTRY SMLMatrix3f();

#### Discussion

Default SMLmatrix3f object constructor. This matrix is initialized as identity (1.0 on main diagonal, 0.0 for other elements).

Example:

    SMLMatrix3f A();

#### Parameters

No.

[top]

SMLLIBENTRY SMLMatrix3f(float* src);

#### Discussion

SMLMatrix3f object constructor. Matrix data is initialized by float array src assuming row-wise representation.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f  A(src);

#### Parameters

src - pointer to a float-type object.

[top]

SMLLIBENTRY SMLMatrix3f(const SMLMatrix3f& src);

#### Discussion

SMLmatrix3f object copy-constructor. This matrix is initialized by src data.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    SMLMatrix3f B(A);

#### Parameters

src - reference to SMLMatrix3f-type object.

[top]

SKINLIBENTRY ~SMLMatrix3f();

#### Discussion

Destructor for SMLmatrix3f object (it is empty).

#### Parameters

No.

[top]

SMLLIBENTRY const SMLMatrix3f& operator=(const SMLMatrix3f& src);

#### Discussion

Method is an overloaded operator-function. It makes elements of matrix equal to those of matrix src.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    SMLMatrix3f B();
    B = A;

#### Parameters

src - object of SMLMatrix3f type.

#### Return Value

Returns reference to current object of SMLMatrix3f type.

[top]

SMLLIBENTRY void Set(int i1, int i2, float v);

#### Discussion

Method sets matrix element with index i1, i2 equal to value of v.

Example:

    SMLMatrix3f A();
    A.Set(1, 2, 3.0f);

#### Parameters

i1, i2 - index of matrix element

v - new value of matrix element.

[top]

SMLLIBENTRY float Get(int i1, int i2) const;

#### Discussion

Method gets value of the matrix element with index i1, i2 .

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    float fvalue;
    SMLMatrix3f A(src);
    fvalue = A.Get(1, 1); // fvalue = 5

#### Parameters

i1, i2 - index of matrix element

#### Return Value

Returns the value of the matrix element with index i1, i2 .

[top]

SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& src) const;

#### Discussion

Method computes product of this matrix and vector src. Result of transformation is written into vector src.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    SMLVec3f B(2, 4, 6);
    SMLVec3f C();
    A.TransformPoint(B, C);

#### Parameters

src - reference to a vector to be transformed.

#### Output Parameters

src - result of transformation.

[top]

SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& src, int transpose) const;

#### Discussion

Method transforms vector src in accordance with component this matrix. If transpose is zero, method computes product of this matrix and vector src. If transpose is not zero method computes product of transposed this matrix and vector src. Result of transformation is written into vector src.

#### Parameters

src - reference to a vector to be transformed.

transpose - a transformation flag.

#### Output Parameters

src - result of transformation.

[top]

SMLLIBENTRY void TransformPoint1(const SMLVec3f& src, SMLVec3f& src) const;

#### Discussion

Method computes product of transposed this matrix and vector src. Result of transformation is written into vector src.

#### Parameters

src - reference to a vector to be transformed.

#### Output Parameters

src - result of transformation.

[top]

SMLLIBENTRY const SMLMatrix3f& Multiply(const SMLMatrix3f& a, const SMLMatrix3f& b);

#### Discussion

Computes this = a b (matrix multiplication).

Example:

    float src1[9] = {1,2,3,4,5,6,7,8,9};
    float src2[9] = {11,12,13,14,15,16,17,18,19};
    SMLMatrix3f A(src1);
    SMLMatrix3f B(src2);
    SMLMatrix3f C();
    C.Mult(A, B);

#### Parameters

a - first operand.

b - second operand.

#### Return Value

Returns reference to the current object of SMLMatrix3f type.

[top]

SMLLIBENTRY const SMLMatrix3f& Multiply(const SMLMatrix3f& a, const SMLMatrix3f& b, int ta, int tb);

#### Discussion

Computes multiplication of matrices a and b and writes it into this matrix as follows

this = a b for ta == 0 && tb == 0, or

this = aT b for ta != 0 && tb == 0, or

this = a bT for ta == 0 && tb != 0, or

this = aT bT for ta != 0 && tb != 0

#### Parameters

a - first operand.

b - second operand.

ta - transposition flag for first operand.

tb - transposition flag for second operand.

#### Return Value

Returns reference to the current object of SMLMatrix3f type.

[top]

SMLLIBENTRY float** GetMatrix();

#### Discussion

Method returns this matrix as row-wise 2 dimensional array of floats.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    float dst[3][3];
    SMLMatrix3f A(src);
    dst = A.GetMatrix();

#### Parameters

No.

#### Return Value

Pointer to matrix data.

[top]

SMLLIBENTRY void Copy(const SMLMatrix3f&src);

#### Discussion

Method makes elements of this matrix equal to those of this matrix of object src.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    SMLMatrix3f B();
    B.Copy(A);

#### Parameters

src - reference to SMLMatrix3f-type object whose this matrix is to be copied.

[top]

SMLLIBENTRY void Identity();

#### Discussion

Method overwrites this matrix with unit diagonal matrix.

Example:

    SMLMatrix3f A();
    A.Identity();

#### Parameters

No.

SMLLIBENTRY void Zero();

#### Discussion

Method initializes all this matrix with 0.

Example:

    SMLMatrix3f A();
    A.Zero();

#### Parameters

No.

[top]

SMLLIBENTRY void Cross(const SMLVec3f& v);

#### Discussion

It is convenient to represent the cross product of 2 vectors in matrix equations where the cross product operation is separated from the vector it operates on. The cross operator ^ may be defined by - b = a X b. Notice that transpose of cross operation is its negation.

Method creates cross this matrix from coordinates of vector v as follows

0 | -v.z | v.y
v.z | 0 | -v.y
-v.y | v.x | 0

Example:

    SMLMatrix3f A();
    SMLVec3f B(2, 4, 6);
     A.Cross(B);

#### Parameters

vec - SMLVec3f-type object whose coordinates are used for the cross matrix.

[top]

SMLLIBENTRY void Rotate(float radians, float x, float y, float z);

#### Discussion

Method creates transformation this matrix, which describes the coordinate system rotation with angle radians around the axis defined by coordinates x, y, z.

Example:

    SMLMatrix3f A();
    A.Rotate(0.65f, 2.0f, 1.0f, 3.0f);

#### Parameters

radians - angle of rotation.

x, y, z - coordinates of axis of rotation.

[top]

SMLLIBENTRY void Rotate(float radians, const SMLVec3f& axis);

#### Discussion

Method creates transformation this matrix, which describes the coordinate system rotation with angle radians around the axis defined by vector axis.

Example:

    SMLMatrix3f A();
    SMLVec3f B(2, 4, 6);
    A.Rotate(0.65f, B);

#### Parameters

radians - angle of rotation.

axis - SMLVec3f-type object whose coordinates are used for the transformation matrix.

[top]

SMLLIBENTRY void GetMatrix4f(SMLMatrix4f& m);

#### Discussion

Method creates this matrix of SMLMatrix4f-type object. This matrix is obtained from current SMLMatrix3f-type object-s this matrix. Elements of the last row and the last column of the formed matrix are set to zero, and element with index (4,4) is set to 1.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    SMLMatrix4f B();
    A.GetMatrix4f(B);

#### Output Parameters

m - reference to SMLMatrix4f-type object.

[top]

SMLLIBENTRY void SetByMatrix4f(SMLMatrix4f& m);

#### Discussion

Method creates this matrix on the base of matrix of SMLMatrix4f-type object. New matrix is the matrix of SMLMatrix4f-type object without elements of its last row and column.

Example:

    float src[16] = {1,2,3,4,5,6,7,8,9,2,4,5,7,3,8,9};
    SMLMatrix3f A();
    SMLMatrix4f B(src);
    A.SetByMatrix4f(B);

#### Parameters

m - reference to SMLMatrix4f-type object.

[top]

void Output(char* label1 = NULL, char* label2 = NULL);

#### Discussion

Print out matrix data using OutputDebugString function with caption formed by concatenation of label1 and label2. This method may be used for application debugging under VC integrated environment.

#### Parameters

label1,label2 - strings for formed caption.

[top]

SMLLIBENTRY void Transpose();

#### Discussion

Method transposes this matrix.

Example:

    float src[9] = {1,2,3,4,5,6,7,8,9};
    SMLMatrix3f A(src);
    A.Transpose();

#### Parameters

No.

[top]

SMLLIBENTRY void QuaternionMatrix(const SMLVec4f& quat);

#### Discussion

Method is used to create matrix, which corresponds to quaternion quat.

Example:

    SMLMatrix3f A();
    SMLVec4f B(2, 4, 6, 3);
    A.QuaternionMatrix(B);

#### Parameters

axis- SMLVec4f-type object whose coordinates are used for the create matrix.

[top]