record TMatrix3

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TMatrix3 = record

Description

A 3x3 matrix in row-major order (M[Row, Column]). You can access the elements directly using M[0,0]..M[2,2] or m11..m33. You can also access the matrix using its three rows R[0]..R[2] (which map directly to the elements M[]).

TMatrix3 is compatible with TMatrix in the Delphi RTL. You can typecast between these two types or implicitly convert from one to the other through assignment (eg. MyMatrix3 := MyMatrix).

When the conditional define FM_COLUMN_MAJOR is set, the matrix is stored in column-major order instead (M[Column, Row]), and the Rows property and R fields are replaced by Columns and C respectively. Also, in that case assigning an RTL TMatrix to a TMatrix3 will transpose the matrix to keep behavior the same.

Overview

Fields

V: array [0..2] of TVector3
R: array [0..2] of TVector3
M: array [0..2, 0..2] of Single
m11: Single;
m12: Single;
m13: Single;
m21: Single;
m22: Single;
m23: Single;
m31: Single
m32: Single
m33: Single

Methods

procedure Init; overload; inline;
procedure Init(const ADiagonal: Single); overload; inline;
procedure Init(const ARow0, ARow1, ARow2: TVector3); overload; inline;
procedure Init(const A11, A12, A13, A21, A22, A23, A31, A32, A33: Single); overload; inline;
procedure Init(const AMatrix: TMatrix2); overload; inline;
procedure InitScaling(const AScale: Single); overload;
procedure InitScaling(const AScaleX, AScaleY: Single); overload; inline;
procedure InitScaling(const AScale: TVector2); overload; inline;
procedure InitTranslation(const ADeltaX, ADeltaY: Single); overload; inline;
procedure InitTranslation(const ADelta: TVector2); overload; inline;
procedure InitRotation(const AAngle: Single);
class operator Implicit(const A: TMatrix): TMatrix3; inline;
class operator Implicit(const A: TMatrix3): TMatrix; inline;
class operator Equal(const A, B: TMatrix3): Boolean; inline;
class operator NotEqual(const A, B: TMatrix3): Boolean; inline;
class operator Negative(const A: TMatrix3): TMatrix3;
class operator Add(const A: TMatrix3; const B: Single): TMatrix3;
class operator Add(const A: Single; const B: TMatrix3): TMatrix3;
class operator Add(const A, B: TMatrix3): TMatrix3;
class operator Subtract(const A: TMatrix3; const B: Single): TMatrix3;
class operator Subtract(const A: Single; const B: TMatrix3): TMatrix3;
class operator Subtract(const A, B: TMatrix3): TMatrix3;
class operator Multiply(const A: TMatrix3; const B: Single): TMatrix3;
class operator Multiply(const A: Single; const B: TMatrix3): TMatrix3;
class operator Multiply(const A: TMatrix3; const B: TVector3): TVector3;
class operator Multiply(const A: TVector3; const B: TMatrix3): TVector3;
class operator Multiply(const A, B: TMatrix3): TMatrix3;
class operator Divide(const A: TMatrix3; const B: Single): TMatrix3;
class operator Divide(const A: Single; const B: TMatrix3): TMatrix3;
class operator Divide(const A: TMatrix3; const B: TVector3): TVector3; inline;
class operator Divide(const A: TVector3; const B: TMatrix3): TVector3; inline;
class operator Divide(const A, B: TMatrix3): TMatrix3; inline;
function CompMult(const AOther: TMatrix3): TMatrix3;
function Transpose: TMatrix3;
procedure SetTransposed;
function Inverse: TMatrix3;
procedure SetInversed;

Properties

property Rows[constAIndex:Integer]: TVector3 read GetRow write SetRow;
property Components[constARow,AColumn:Integer]: Single read GetComponent write SetComponent;
property Determinant: Single read GetDeterminant;

Description

Fields

V: array [0..2] of TVector3

Row or column vectors, depending on FM_COLUMN_MAJOR define

R: array [0..2] of TVector3

The three row vectors making up the matrix

M: array [0..2, 0..2] of Single

The elements of the matrix in row-major order

m11: Single;
 
m12: Single;
 
m13: Single;
 
m21: Single;
 
m22: Single;
 
m23: Single;
 
m31: Single
 
m32: Single
 
m33: Single
 

Methods

procedure Init; overload; inline;

Initializes the matrix to an identity matrix (filled with 0 and value 1 for the diagonal)

procedure Init(const ADiagonal: Single); overload; inline;

Fills the matrix with zeros and sets the diagonal.

Parameters
ADiagonal
the value to use for the diagonal. Use 1 to set the matrix to an identity matrix.
procedure Init(const ARow0, ARow1, ARow2: TVector3); overload; inline;

Initializes the matrix using three row vectors.

Parameters
ARow0
the first row of the matrix.
ARow1
the second row of the matrix.
ARow2
the third row of the matrix.
procedure Init(const A11, A12, A13, A21, A22, A23, A31, A32, A33: Single); overload; inline;

Initializes the matrix with explicit values.

Parameters: A11-A33: the values of the matrix elements, in row-major order.

procedure Init(const AMatrix: TMatrix2); overload; inline;

Initializes the matrix with a 2x2 matrix. The 2x2 matrix is copied to the top-left corner of the 3x3 matrix, and the remaining elements are set according to an identity matrix.

Parameters
AMatrix
the source 2x2 matrix.
procedure InitScaling(const AScale: Single); overload;

Creates a scaling matrix that scales uniformly.

Parameters
AScale
the uniform scale factor
procedure InitScaling(const AScaleX, AScaleY: Single); overload; inline;

Creates a scaling matrix.

Parameters
AScaleX
the value to scale by on the X axis
AScaleY
the value to scale by on the Y axis
procedure InitScaling(const AScale: TVector2); overload; inline;

Creates a scaling matrix.

Parameters
AScale
the scale factors
procedure InitTranslation(const ADeltaX, ADeltaY: Single); overload; inline;

Creates a translation matrix.

Parameters
ADeltaX
translation in the X direction
ADeltaY
translation in the Y direction
procedure InitTranslation(const ADelta: TVector2); overload; inline;

Creates a translation matrix.

Parameters
ADelta
translation vector
procedure InitRotation(const AAngle: Single);

Creates a rotation the matrix using a rotation angle in radians.

Parameters
AAngle
the rotation angle in radians
class operator Implicit(const A: TMatrix): TMatrix3; inline;

Implicitly converts a TMatrix to a TMatrix3.

class operator Implicit(const A: TMatrix3): TMatrix; inline;

Implicitly converts a TMatrix3 to a TMatrix.

class operator Equal(const A, B: TMatrix3): Boolean; inline;

Checks two matrices for equality.

Returns

True if the two matrices match each other exactly.

class operator NotEqual(const A, B: TMatrix3): Boolean; inline;

Checks two matrices for inequality.

Returns

True if the two matrices are not equal.

class operator Negative(const A: TMatrix3): TMatrix3;

Negates a matrix.

Returns

The negative value of the matrix (with all elements negated).

class operator Add(const A: TMatrix3; const B: Single): TMatrix3;

Adds a scalar value to each element of a matrix.

class operator Add(const A: Single; const B: TMatrix3): TMatrix3;

Adds a scalar value to each element of a matrix.

class operator Add(const A, B: TMatrix3): TMatrix3;

Adds two matrices component-wise.

class operator Subtract(const A: TMatrix3; const B: Single): TMatrix3;

Subtracts a scalar value from each element of a matrix.

class operator Subtract(const A: Single; const B: TMatrix3): TMatrix3;

Subtracts a matrix from a scalar value.

class operator Subtract(const A, B: TMatrix3): TMatrix3;

Subtracts two matrices component-wise.

class operator Multiply(const A: TMatrix3; const B: Single): TMatrix3;

Multiplies a matrix with a scalar value.

class operator Multiply(const A: Single; const B: TMatrix3): TMatrix3;

Multiplies a matrix with a scalar value.

class operator Multiply(const A: TMatrix3; const B: TVector3): TVector3;

Performs a matrix * row vector linear algebraic multiplication.

class operator Multiply(const A: TVector3; const B: TMatrix3): TVector3;

Performs a column vector * matrix linear algebraic multiplication.

class operator Multiply(const A, B: TMatrix3): TMatrix3;

Multiplies two matrices using linear algebraic multiplication.

class operator Divide(const A: TMatrix3; const B: Single): TMatrix3;

Divides a matrix by a scalar value.

class operator Divide(const A: Single; const B: TMatrix3): TMatrix3;

Divides a scalar value by a matrix.

class operator Divide(const A: TMatrix3; const B: TVector3): TVector3; inline;

Divides a matrix by a vector. This is equivalent to multiplying the inverse of the matrix with a row vector using linear algebraic multiplication.

class operator Divide(const A: TVector3; const B: TMatrix3): TVector3; inline;

Divides a vector by a matrix. This is equivalent to multiplying a column vector with the inverse of the matrix using linear algebraic multiplication.

class operator Divide(const A, B: TMatrix3): TMatrix3; inline;

Divides two matrices. This is equivalent to multiplying the first matrix with the inverse of the second matrix using linear algebraic multiplication.

function CompMult(const AOther: TMatrix3): TMatrix3;

Multiplies this matrix with another matrix component-wise.

Note: For linear algebraic matrix multiplication, use the multiply (*) operator instead.

Parameters
AOther
the other matrix.
Returns

This matrix multiplied by AOther component-wise. That is, Result.M[I,J] := M[I,J] * AOther.M[I,J].

function Transpose: TMatrix3;

Creates a transposed version of this matrix.

Note: Does not change this matrix. To update this itself, use SetTransposed.

Returns

The transposed version of this matrix.

procedure SetTransposed;

Transposes this matrix.

Note: If you do not want to change this matrix, but get a transposed version instead, then use Transpose.

function Inverse: TMatrix3;

Calculates the inverse of this matrix.

Note: Does not change this matrix. To update this itself, use SetInversed.

Note: The values in the returned matrix are undefined if this matrix is singular or poorly conditioned (nearly singular).

Returns

The inverse of this matrix.

procedure SetInversed;

Inverts this matrix.

Note: If you do not want to change this matrix, but get an inversed version instead, then use Inverse.

Note: The values in the inversed matrix are undefined if this matrix is singular or poorly conditioned (nearly singular).

Properties

property Rows[constAIndex:Integer]: TVector3 read GetRow write SetRow;

Returns the rows of the matrix. This is identical to accessing the R-field.

Parameters
AIndex
index of the row to return (0-2). Range is checked with an assertion.
property Components[constARow,AColumn:Integer]: Single read GetComponent write SetComponent;

Returns the elements of the matrix (in row-major order). This is identical to accessing the M-field, but this property can be used as a default array property.

Parameters
ARow
the row index (0-2). Range is checked with an assertion.
AColumn
the column index (0-2). Range is checked with an assertion.
property Determinant: Single read GetDeterminant;

The determinant of this matrix.


Generated by PasDocEx, based on PasDoc 0.14.0.