helix.linalgebra

Module consists of basic mathematical objects oriented to working with 3D graphics.

Those are 2,3,4-D vectors, quaternion, 3x3 and 4x4 matrices. In case of specialization for 3D graphics there are always some features and deviation from classical math. Here I summarize such features of helix'es linear algebra:
  • In helix paradigm of column-vector is taken. So multiplication of matrix by vector makes sense but multiplication of vector by matrix makes not. This approach conforms to rules accepted in classical math and coincides with OpenGL rules. However this is opposite to Direct3D paradigm where vector is a row. So, in helix, to combine sequence of transforms specified with matrices A, B, C in order A then B then C, you have to multiply them in back-to-front order order: M=C*B*A.


  • When an issue deal with euler angles following definitions are accepted. Yaw is rotation around Y, Pitch is rotaion around X, Roll is rotation around Z Rotations are always applied in order: Roll then Pitch then Yaw.


  • Helix matrices use column-major memory layout. I.e. matrix
    abc
    def
    ghi
    in memory will looks like: a, d, g, b, e, h, c, f, i. This order is the same as in OpenGL API, but opposite to Direct3D API. However as mentioned above, Direct3D uses vector-row paradigm that is opposite to classical math, so D3D requires transposed matrix as compared to classical math to get desired transformation. As a result you haven't to transpose helix matrix while transmission to API even in Direct3D case. Normaly you haven't to remember about memory layout, just use it as in classical math, this feature is significant only in routines that operate with data pointers and plain array representation. There are reminders in such methods' documentation.


Authors:
Victor Nakoryakov, nail-mail[at]mail.ru

enum Ort ;
Defines ort names that are usualy used as indices.

X
Y
Z
W


template LinearAlgebra (float_t)
Wrapper template to provide possibility to use different float types in implemented structs and routines.

struct Vector2 ;
Two dimensional vector.

For formal definition of vector, meaning of possible operations and related information see http://en.wikipedia.org/wiki/Vector_(spatial).

float_t x ;
float_t y ;
Components of vector.

Vector2 nan ;
Vector with both components seted to NaN.

Vector2 unitX ;
Vector2 unitY ;
Unit vector codirectional with corresponding axis.

Vector2 opCall (float_t x, float_t y);
Method to construct vector in C-like syntax.

Examples:
        Vector2 myVector = Vector2(1, 2);


void set (float_t x, float_t y);
Sets values of components to passed values.

real norm ();
Returns:
Norm (also known as length, magnitude) of vector.

real normSquare ();
Returns:
Square of vector's norm.

Since this method doesn't need calculation of square root it is better to use it instead of norm() when you can. For example, if you want just to know which of 2 vectors is longer it's better to compare their norm squares instead of their norm.

void normalize ();
Normalizes this vector.

Vector2 normalized ();
Returns:
Normalized copy of this vector.

bool isUnit (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this vector is unit.

Params:

Ort dominatingAxis ();
Returns:
Axis for which projection of this vector on it will be longest.

bool isnormal ();
Returns:
Whether all components are normalized numbers.

float_t* ptr ();
Returns:
float_t pointer to x component of this vector. It's like a ptr method for arrays.

float_t opIndex (Ort ort);
Returns:
Component corresponded to passed index.

void opIndexAssign (float_t value, Ort ort);
Assigns new value to component corresponded to passed index.

bool opEquals (Vector2 v);
Vector2 opNeg ();
Vector2 opAdd (Vector2 v);
void opAddAssign (Vector2 v);
Vector2 opSub (Vector2 v);
void opSubAssign (Vector2 v);
Vector2 opMul (real k);
void opMulAssign (real k);
Vector2 opMul_r (real k);
Vector2 opDiv (real k);
void opDivAssign (real k);
Standard operators that have intuitive meaning, same as in classical math.

Note that division operators do no cheks of value of k, so in case of division by 0 result vector will have infinity components. You can check this with isnormal() method.

Vector2f toVector2f ();
Returns:
Copy of this vector with float type components

Vector2d toVector2d ();
Returns:
Copy of this vector with double type components

Vector2r toVector2r ();
Returns:
Copy of this vector with real type components

Vector3 xy0 ();
Vector3 x0y ();
Routines known as swizzling.

Returns:
New vector constructed from this one and having component values that correspond to method name.

real dp (Vector2 a, Vector2 b);
Returns:
Dot product between passed vectors.

alias equal ;
Introduces approximate equality function for Vector2.

alias lerp ;
Introduces linear interpolaton function for Vector2.

struct Vector3 ;
Three dimensional vector.

For formal definition of vector, meaning of possible operations and related information see http://en.wikipedia.org/wiki/Vector_(spatial).

float_t x ;
float_t y ;
float_t z ;
Components of vector.

Vector3 nan ;
Vector with all components seted to NaN.

Vector3 unitX ;
Vector3 unitY ;
Vector3 unitZ ;
Unit vector codirectional with corresponding axis.

Vector3 opCall (float_t x, float_t y, float_t z);
Method to construct vector in C-like syntax.

Examples:
        Vector3 myVector = Vector3(1, 2, 3);


void set (float_t x, float_t y, float_t z);
Sets values of components to passed values.

real norm ();
Returns:
Norm (also known as length, magnitude) of vector.

real normSquare ();
Returns:
Square of vector's norm.

Since this method doesn't need calculation of square root it is better to use it instead of norm() when you can. For example, if you want just to know which of 2 vectors is longer it's better to compare their norm squares instead of their norm.

void normalize ();
Normalizes this vector.

Vector3 normalized ();
Returns:
Normalized copy of this vector.

bool isUnit (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this vector is unit.

Params:

Ort dominatingAxis ();
Returns:
Axis for which projection of this vector on it will be longest.

bool isnormal ();
Returns:
Whether all components are normalized numbers.

float_t* ptr ();
Returns:
float_t pointer to x component of this vector. It's like a ptr method for arrays.

float_t opIndex (Ort ort);
Returns:
Component corresponded to passed index.

void opIndexAssign (float_t value, Ort ort);
Assigns new value to component corresponded to passed index.

bool opEquals (Vector3 v);
Vector3 opNeg ();
Vector3 opAdd (Vector3 v);
void opAddAssign (Vector3 v);
Vector3 opSub (Vector3 v);
void opSubAssign (Vector3 v);
Vector3 opMul (real k);
void opMulAssign (real k);
Vector3 opMul_r (real k);
Vector3 opDiv (real k);
void opDivAssign (real k);
Standard operators that have intuitive meaning, same as in classical math.

Note that division operators do no cheks of value of k, so in case of division by 0 result vector will have infinity components. You can check this with isnormal() method.

Vector3f toVector3f ();
Returns:
Copy of this vector with float type components

Vector3d toVector3d ();
Returns:
Copy of this vector with double type components

Vector3r toVector3r ();
Returns:
Copy of this vector with real type components

Vector4 xyz0 ();
Vector4 xyz1 ();
Vector2 xy ();
Vector2 xz ();
Routines known as swizzling.

Returns:
New vector constructed from this one and having component values that correspond to method name.

void xy (Vector2 v);
void xz (Vector2 v);
Routines known as swizzling. Assigns new values to some components corresponding to method name.

real dp (Vector3 a, Vector3 b);
Returns:
Dot product between passed vectors.

Vector3 cp (Vector3 a, Vector3 b);
Returns:
Cross product between passed vectors. Result is vector c so that a, b, c forms right-hand tripple.

bool isBasisOrthogonal (Vector3 r, Vector3 s, Vector3 t, int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether passed basis is orthogonal.

Params:

References:
http://en.wikipedia.org/wiki/Orthogonal_basis

bool isBasisOrthonormal (Vector3 r, Vector3 s, Vector3 t, int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether passed basis is orthonormal.

Params:

References:
http://en.wikipedia.org/wiki/Orthonormal_basis

alias equal ;
Introduces approximate equality function for Vector3.

alias lerp ;
Introduces linear interpolation function for Vector3.

struct Vector4 ;
4D vector.

For formal definition of vector, meaning of possible operations and related information see http://en.wikipedia.org/wiki/Vector_(spatial), http://en.wikipedia.org/wiki/Homogeneous_coordinates.

float_t x ;
float_t y ;
float_t z ;
float_t w ;
Components of vector.

Vector4 nan ;
Vector with all components seted to NaN.

Vector4 unitX ;
Vector4 unitY ;
Vector4 unitZ ;
Vector4 unitW ;
Unit vector codirectional with corresponding axis.

Vector4 opCall (float_t x, float_t y, float_t z, float_t w);
Vector4 opCall (Vector3 xyz, float_t w);
Methods to construct vector in C-like syntax.

Examples:
        Vector4 myVector = Vector4(1, 2, 3, 1);
        Vector4 myVector = Vector4(Vector3(1, 2, 3), 0);


void set (float_t x, float_t y, float_t z, float_t w);
void set (Vector3 xyz, float_t w);
Sets values of components to passed values.

real norm ();
Returns:
Norm (also known as length, magnitude) of vector.

W-component is taken into account.

real normSquare ();
Returns:
Square of vector's norm.

W-component is taken into account.

Since this method doesn't need calculation of square root it is better to use it instead of norm() when you can. For example, if you want just to know which of 2 vectors is longer it's better to compare their norm squares instead of their norm.

void normalize ();
Normalizes this vector.

Vector4 normalized ();
Returns:
Normalized copy of this vector.

bool isUnit (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this vector is unit.

Params:

Ort dominatingAxis ();
Returns:
Axis for which projection of this vector on it will be longest.

W-component is taken into account.

bool isnormal ();
Returns:
Whether all components are normalized numbers.

float_t* ptr ();
Returns:
float_t pointer to x component of this vector. It's like a ptr method for arrays.

float_t opIndex (Ort ort);
Returns:
Component corresponded to passed index.

void opIndexAssign (float_t value, Ort ort);
Assigns new value to component corresponded to passed index.

bool opEquals (Vector4 v);
Vector4 opNeg ();
Vector4 opAdd (Vector4 v);
void opAddAssign (Vector4 v);
Vector4 opSub (Vector4 v);
void opSubAssign (Vector4 v);
Vector4 opMul (real k);
void opMulAssign (real k);
Vector4 opMul_r (real k);
Vector4 opDiv (real k);
void opDivAssign (real k);
Standard operators that have intuitive meaning, same as in classical math.

Note that division operators do no cheks of value of k, so in case of division by 0 result vector will have infinity components. You can check this with isnormal() method.

Vector4f toVector4f ();
Returns:
Copy of this vector with float type components

Vector4d toVector4d ();
Returns:
Copy of this vector with double type components

Vector4r toVector4r ();
Returns:
Copy of this vector with real type components

Vector3 xyz ();
Routine known as swizzling.

Returns:
Vector3 that has the same x, y, z components values.

void xyz (Vector3 v);
Routine known as swizzling. Assigns new values to x, y, z components corresponding to argument's components values.

real dp (Vector4 a, Vector4 b);
Returns:
Dot product between passed vectors.

alias equal ;
Introduces approximate equality function for Vector4.

alias lerp ;
Introduces linear interpolation function for Vector4.

struct Quaternion ;
Quaternion.

For formal definition of quaternion, meaning of possible operations and related information see http://en.wikipedia.org/wiki/Quaternion, http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation.

float_t x ;
float_t y ;
float_t z ;
Components of quaternion.

Vector3 vector ;
Vector part. Can be used instead of explicit members x, y and z.

float_t w ;
Scalar part.

float_t scalar ;
Another name for scalar part.

Quaternion identity ;
Identity quaternion.

Quaternion nan ;
Quaternion with all components seted to NaN.

Quaternion opCall (float_t x, float_t y, float_t z, float_t w);
Quaternion opCall (Vector3 vector, float_t scalar);
Quaternion opCall (Matrix33 mat);
Methods to construct quaternion in C-like syntax.

Examples:
        Quaternion q1 = Quaternion(0, 0, 0, 1);
        Quaternion q2 = Quaternion(Vector3(0, 0, 0), 1);
        Quaternion q3 = Quaternion(Matrix33.rotationY(PI / 6), 1);


void set (float_t x, float_t y, float_t z, float_t w);
void set (Vector3 vector, float_t scalar);
Sets values of components according to passed values.

void set (Matrix33 mat);
Sets quaternion, so that, it will represent same rotation as in mat matrix argument.

Params:
Matrix33 mat Matrix to extract rotation from. Should be pure rotation matrix.

Throws:
AssertError if mat is not pure rotation matrix and module was compiled with contract checkings are enabled.

Quaternion rotationX (float_t radians);
Quaternion rotationY (float_t radians);
Quaternion rotationZ (float_t radians);
Construct quaternion that represents rotation around corresponding axis.

Quaternion rotation (float_t yaw, float_t pitch, float_t roll);
Constructs quaternion that represents rotation specified by euler angles passed as arguments. Order of rotation application is: roll (Z axis), pitch (X axis), yaw (Y axis).

Quaternion rotation (Vector3 axis, float_t radians);
Constructs quaternion that represents rotation around 'axis' axis by 'radians' angle.

real norm ();
Returns:
Norm (also known as length, magnitude) of quaternion.

real normSquare ();
Returns:
Square of vector's norm.

Method doesn't need calculation of square root.

void normalize ();
Normalizes this quaternion.

Quaternion normalized ();
Returns:
Normalized copy of this quaternion.

bool isUnit (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this quaternion is unit.

Params:

Quaternion conj ();
Returns:
Conjugate quaternion.

void invert ();
Invert this quaternion.

Quaternion inverse ();
Returns:
Inverse copy of this quaternion.

real yaw ();
real pitch ();
real roll ();
Returns:
Extracted euler angle with the assumption that rotation is applied in order: roll (Z axis), pitch (X axis), yaw (Y axis).

bool isnormal ();
Returns:
Whether all components are normalized.

float_t* ptr ();
Returns:
float_t pointer to x component of this vector. It's like a ptr method for arrays.

float_t opIndex (Ort ort);
Returns:
Component corresponded to passed index.

void opIndexAssign (float_t value, Ort ort);
Assigns new value to component corresponded to passed index.

bool opEquals (Quaternion q);
Quaternion opNeg ();
Quaternion opAdd (Quaternion q);
void opAddAssign (Quaternion q);
Quaternion opSub (Quaternion q);
void opSubAssign (Quaternion q);
Quaternion opMul (float_t k);
Quaternion opMul_r (float_t k);
Quaternion opDiv (float_t k);
void opDivAssign (float_t k);
Standard operators that have meaning exactly the same as for Vector4.

Note that division operators do no cheks of value of k, so in case of division by 0 result vector will have infinity components. You can check this with isnormal() method.

Quaternion opMul (Quaternion q);
void opMulAssign (Quaternion q);
Quaternion multiplication operators. Result of Q1*Q2 is quaternion that represents rotation which has meaning of application Q2's rotation and the Q1's rotation.

Quaternionf toQuaternionf ();
Returns:
Copy of this quaternion with float type components.

Quaterniond toQuaterniond ();
Returns:
Copy of this vector with double type components.

Quaternionr toQuaternionr ();
Returns:
Copy of this vector with real type components.

alias equal ;
Introduces approximate equality function for Quaternion.

alias lerp ;
Introduces linear interpolation function for Quaternion.

Quaternion slerp (Quaternion q0, Quaternion q1, real t);
Returns:
Product of spherical linear interpolation between q0 and q1 with parameter t.

References:
http://en.wikipedia.org/wiki/Slerp.

struct Matrix33 ;
3x3 Matrix.

For formal definition of quaternion, meaning of possible operations and related information see http://en.wikipedia.org/wiki/Matrix(mathematics), http://en.wikipedia.org/wiki/Transformation_matrix.

Matrix33 identity ;
Identity matrix.

Matrix33 nan ;
Matrix with all elements seted to NaN.

Matrix33 zero ;
Matrix with all elements seted to 0.

Matrix33 opCall (float_t m00, float_t m01, float_t m02, float_t m10, float_t m11, float_t m12, float_t m20, float_t m21, float_t m22);
Matrix33 opCall (float_t[9] a);
Methods to construct matrix in C-like syntax.

In case with array remember about column-major matrix memory layout, note last line with assert in example.

Examples:
        Matrix33 mat1 = Matrix33(1,2,3,4,5,6,7,8,9);
        static float[9] a = [1,2,3,4,5,6,7,8,9];
        Matrix33 mat2 = Matrix33(a);

        assert(mat1 == mat2.transposed);


Matrix33 opCall (Vector3 basisX, Vector3 basisY, Vector3 basisZ);
Method to construct matrix in C-like syntax. Sets columns to passed vector arguments.

void set (float_t m00, float_t m01, float_t m02, float_t m10, float_t m11, float_t m12, float_t m20, float_t m21, float_t m22);
Sets elements to passed values.

void set (float_t[9] a);
Sets elements as a copy of a contents. Remember about column-major matrix memory layout.

void set (Vector3 basisX, Vector3 basisY, Vector3 basisZ);
Sets columns to passed basis vectors.

bool isnormal ();
Returns:
Whether all components are normalized numbers.

bool isIdentity (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix is identity.

Params:

bool isZero (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix is zero.

Params:

bool isOrthogonal (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix is orthogonal.

Params:

References:
http://en.wikipedia.org/wiki/Orthogonal_matrix.

bool isRotation (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix represents pure rotation. I.e. hasn't scale admixture.

Params:

Matrix33 scale (float_t x, float_t y, float_t z);
Constructs scale matrix with scale coefficients specified as arguments.

Matrix33 scale (Vector3 v);
Constructs scale matrix with scale coefficients specified as v's components.

Matrix33 rotationX (float_t radians);
Matrix33 rotationY (float_t radians);
Matrix33 rotationZ (float_t radians);
Construct matrix that represents rotation around corresponding axis.

Matrix33 rotation (float_t yaw, float_t pitch, float_t roll);
Constructs matrix that represents rotation specified by euler angles passed as arguments. Order of rotation application is: roll (Z axis), pitch (X axis), yaw (Y axis).

Matrix33 rotation (Vector3 axis, float_t radians);
Constructs matrix that represents rotation specified by axis and angle. Method works with assumption that axis is unit vector.

Throws:
AssertError on non-unit axis call attempt if module was compiled with contract checks enabled.

Matrix33 rotation (Quaternion q);
Constructs matrix that represents rotation same as in passed quaternion q. Method works with assumption that q is unit.

Throws:
AssertError on non-unit quaternion call attempt if you compile with contract checks enabled.

Matrix33 inverse ();
Returns:
Inverse copy of this matrix.

In case if this matrix is singular (i.e. determinant = 0) result matrix will has infinity elements. You can check this with isnormal() method.

void invert ();
Inverts this matrix.

In case if matrix is singular (i.e. determinant = 0) result matrix will has infinity elements. You can check this with isnormal() method.

real determinant ();
Returns:
Determinant

real norm ();
Returns:
Frobenius norm of matrix. I.e. square root from summ of all elements' squares.

References:
http://en.wikipedia.org/wiki/Frobenius_norm#Frobenius_norm.

real normSquare ();
Returns:
Square of Frobenius norm of matrix. I.e. summ of all elements' squares.

Method doesn't need calculation of square root.

References:
http://en.wikipedia.org/wiki/Frobenius_norm#Frobenius_norm.

void transpose ();
Transposes this matrix.

Matrix33 transposed ();
Returns:
Transposed copy of this matrix.

void polarDecomposition (out Matrix33 Q, out Matrix33 S);
Makes polar decomposition of this matrix. Denote this matrix with 'M', in that case M=Q*S.

Method is useful to decompose your matrix into rotation 'Q' and scale+shear 'S'. If you didn't use shear transform matrix S will be diagonal, i.e. represent scale. This can have many applications, particulary you can use method for suppressing errors in pure rotation matrices after long multiplication chain.

Params:
Matrix33 Q Output matrix, will be orthogonal after decomposition. Argument shouldn't be null.
Matrix33 S Output matrix, will be symmetric non-negative definite after decomposition. Argument shouldn't be null.

Examples:
        Matrix33 Q, S;
        Matrix33 rot = Matrix33.rotationZ(PI / 7);
        Matrix33 scale = Matrix33.scale(-1, 2, 3);
        Matrix33 composition = rot * scale;
        composition.polarDecomposition(Q, S);
        assert( equal(Q * S, composition) );


References:
http://www.cs.wisc.edu/graphics/Courses/cs-838-2002/Papers/polar-decomp.pdf

Matrix33 opNeg ();
Matrix33 opAdd (Matrix33 mat);
void opAddAssign (Matrix33 mat);
Matrix33 opSub (Matrix33 mat);
void opSubAssign (Matrix33 mat);
Matrix33 opMul (float_t k);
void opMulAssign (float_t k);
Matrix33 opMul_r (float_t k);
Matrix33 opDiv (float_t k);
void opDivAssign (float_t k);
bool opEquals (Matrix33 mat);
Matrix33 opMul (Matrix33 mat);
void opMulAssign (Matrix33 mat);
Vector3 opMul (Vector3 v);
Standard operators that have intuitive meaning, same as in classical math.

Note that division operators do no cheks of value of k, so in case of division by 0 result matrix will have infinity components. You can check this with isnormal() method.

float_t opIndex (uint row, uint col);
Returns:
Element at row'th row and col'th column.

void opIndexAssign (float_t f, uint row, uint col);
Assigns value f to element at row'th row and col'th column.

Vector3 opIndex (uint col);
Returns:
Vector representing col'th column.

void opIndexAssign (Vector3 v, uint col);
Replaces elements in col'th column with v's values.

float_t* ptr ();
Returns:
float_t pointer to [0,0] element of this matrix. It's like a ptr method for arrays.

Remember about column-major matrix memory layout.

Matrix33f toMatrix33f ();
Returns:
Copy of this matrix with float type elements.

Matrix33d toMatrix33d ();
Returns:
Copy of this matrix with double type elements.

Matrix33r toMatrix33r ();
Returns:
Copy of this matrix with real type elements.

alias equal ;
Introduces approximate equality function for Matrix33.

alias lerp ;
Introduces linear interpolation function for Matrix33.

struct Matrix44 ;
4x4 Matrix.

Helix matrices uses column-major memory layout.

Matrix44 identity ;
Identity matrix.

Matrix44 nan ;
Matrix with all elements seted to NaN.

Matrix44 zero ;
Matrix with all elements seted to 0.

Matrix44 opCall (float_t m00, float_t m01, float_t m02, float_t m03, float_t m10, float_t m11, float_t m12, float_t m13, float_t m20, float_t m21, float_t m22, float_t m23, float_t m30, float_t m31, float_t m32, float_t m33);
Matrix44 opCall (float_t[16] a);
Methods to construct matrix in C-like syntax.

In case with array remember about column-major matrix memory layout, note last line with assert in example - it'll be passed.

Examples:
        Matrix33 mat1 = Matrix33(
             1,  2,  3,  4,
             5,  6,  7,  8,
             9, 10, 11, 12,
            13, 14, 15, 16 );

        static float[16] a = [
             1,  2,  3,  4,
             5,  6,  7,  8,
             9, 10, 11, 12,
            13, 14, 15, 16 ];
        Matrix33 mat2 = Matrix33(a);

        assert(mat1 == mat2.transposed);


Matrix44 opCall (Vector4 basisX, Vector4 basisY, Vector4 basisZ, Vector4 basisW = Vector4(0,0,0,1));
Method to construct matrix in C-like syntax. Sets columns to passed vector arguments.

Matrix44 opCall (Vector3 basisX, Vector3 basisY, Vector3 basisZ, Vector3 translation = Vector3(0,0,0));
Method to construct matrix in C-like syntax. Constructs affine transform matrix based on passed vector arguments.

References:
http://en.wikipedia.org/wiki/Affine_transformation.

void set (float_t m00, float_t m01, float_t m02, float_t m03, float_t m10, float_t m11, float_t m12, float_t m13, float_t m20, float_t m21, float_t m22, float_t m23, float_t m30, float_t m31, float_t m32, float_t m33);
Sets elements to passed values.

void set (float_t[16] a);
Sets elements as a copy of a contents. Remember about column-major matrix memory layout.

void set (Vector4 basisX, Vector4 basisY, Vector4 basisZ, Vector4 basisW = Vector4(0,0,0,1));
Sets columns to passed basis vectors.

bool isnormal ();
Returns:
Whether all components are normalized numbers.

bool isIdentity (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix is identity.

Params:

bool isZero (int relprec = defrelprec, int absprec = defabsprec);
Returns:
Whether this matrix is zero.

Params:

void set (Vector3 basisX, Vector3 basisY, Vector3 basisZ, Vector3 translation = Vector3(0,0,0));
Resets this matrix to affine transform matrix based on passed vector arguments.

Matrix44 scale (float_t x, float_t y, float_t z);
Constructs scale matrix with scale coefficients specified as arguments.

Matrix44 scale (Vector3 v);
Constructs scale matrix with scale coefficients specified as v's components.

Matrix44 rotationX (float_t radians);
Matrix44 rotationY (float_t radians);
Matrix44 rotationZ (float_t radians);
Construct matrix that represents rotation around corresponding axis.

Matrix44 rotation (float_t yaw, float_t pitch, float_t roll);
Constructs matrix that represents rotation specified by euler angles passed as arguments. Order of rotation application is: roll (Z axis), pitch (X axis), yaw (Y axis).

Matrix44 rotation (Vector3 axis, float_t radians);
Constructs matrix that represents rotation specified by axis and angle. Method works with assumption that axis is unit vector.

Throws:
AssertError on non-unit axis call attempt if module was compiled with contract checks enabled.

Matrix44 rotation (Quaternion q);
Constructs matrix that represents rotation specified by quaternion. Method works with assumption that quaternion is unit.

Throws:
AssertError on non-unit quaternion call attempt if module was compiled with contract checks enabled.

Matrix44 translation (float_t x, float_t y, float_t z);
Constructs translation matrix with offset values specified as arguments.

Matrix44 translation (Vector3 v);
Constructs translation matrix with offset values specified as v's components.

Matrix44 perspective (float_t fov, float_t aspect, float_t near, float_t far);
Constructs one-point perspecive projection matrix.

Params:
float_t fov Field of view in vertical plane in radians.
float_t aspect Frustum's width / height coefficient. It shouldn't be 0.
float_t near Distance to near plane.
float_t near Distance to far plane.

Matrix44 lookAt (Vector3 eye, Vector3 target, Vector3 up);
Constructs view matrix.

Params:
Vector3 eye Viewer's eye position.
Vector3 target View target.
Vector3 up View up vector.

Arguments should not be complanar, elsewise matrix will contain infinity elements. You can check this with isnormal() method.

Matrix44 inverse ();
Returns:
Inverse copy of this matrix.

In case if this matrix is singular (i.e. determinant = 0) result matrix will has infinity elements. You can check this with isnormal() method.

void invert ();
Inverts this matrix.

In case if matrix is singular (i.e. determinant = 0) result matrix will has infinity elements. You can check this with isnormal() method.

real determinant ();
Returns:
Determinant

real norm ();
Returns:
Frobenius norm of matrix.

References:
http://en.wikipedia.org/wiki/Frobenius_norm#Frobenius_norm.

real normSquare ();
Returns:
Square of Frobenius norm of matrix.

Method doesn't need calculation of square root.

References:
http://en.wikipedia.org/wiki/Frobenius_norm#Frobenius_norm.

bool isAffine ();
Returns:
Whether this matrix represents affine transformation.

References:
http://en.wikipedia.org/wiki/Affine_transformation.

void transpose ();
Transposes this matrix.

Matrix44 transposed ();
Returns:
Transposed copy of this matrix.

Matrix33 cornerMinor ();
void cornerMinor (Matrix33 mat);
R/W property. Corner 3x3 minor.

Matrix44 opNeg ();
Matrix44 opAdd (Matrix44 mat);
void opAddAssign (Matrix44 mat);
Matrix44 opSub (Matrix44 mat);
void opSubAssign (Matrix44 mat);
Matrix44 opMul (float_t k);
void opMulAssign (float_t k);
Matrix44 opMul_r (float_t k);
Matrix44 opDiv (float_t k);
void opDivAssign (float_t k);
bool opEquals (Matrix44 mat);
Matrix44 opMul (Matrix44 mat);
void opMulAssign (Matrix44 mat);
Vector3 opMul (Vector3 v);
Vector4 opMul (Vector4 v);
Standard operators that have intuitive meaning, same as in classical math. Exception is multiplication with Vecto3 that doesn't make sense for classical math, in that case Vector3 is implicitl expanded to Vector4 with w=1.

Note that division operators do no cheks of value of k, so in case of division by 0 result matrix will have infinity components. You can check this with isnormal() method.

float_t opIndex (uint row, uint col);
Returns:
Element at row'th row and col'th column.

void opIndexAssign (float_t f, uint row, uint col);
Assigns value f to element at row'th row and col'th column.

Vector4 opIndex (uint col);
Returns:
Vector representing col'th column.

void opIndexAssign (Vector4 v, uint col);
Replaces elements in col'th column with v's values.

float_t* ptr ();
Returns:
float_t pointer to [0,0] element of this matrix. It's like a ptr method for arrays.

Remember about column-major matrix memory layout.

Matrix44f toMatrix44f ();
Returns:
Copy of this matrix with float type elements.

Matrix44d toMatrix44d ();
Returns:
Copy of this matrix with double type elements.

Matrix44r toMatrix44r ();
Returns:
Copy of this matrix with real type elements.

alias equal ;
Introduces approximate equality function for Matrix44.

alias lerp ;
Introduces linear interpolation function for Matrix44.

Page was generated with on Tue Feb 21 11:32:53 2006