VRay SDK for C#
Loading...
Searching...
No Matches
VRay.Matrix Class Reference

A class representing a 3x3 matrix. It usually represents a linear transformation in 3D space. More...

Inherits IEquatable< Matrix >, and IComparable< Matrix >.

Public Member Functions

 Matrix ()
 Constructs an empty matrix with all elements set to zero.
 
 Matrix (float d)
 Constructs a matrix with the specified value for the main diagonal. More...
 
 Matrix (Vector a, Vector b, Vector c)
 Constructor from the three columns of the matrix. The vector coordinates are copied into the matrix own columns. The references are not preserved. More...
 
 Matrix (Vector diagonal)
 Constructs a matrix using the passed Vector values for the new matrix main diagonal. More...
 
 Matrix (Vector[] columns)
 Constructs a matrix from an array of 3 vectors used as columns. More...
 
Matrix AddDiagonal (Vector a)
 Returns a new matrix adding the passed vector values to the main diagonal of this one. More...
 
int CompareTo (Matrix m)
 Compares the matrices. More...
 
bool Equals (Matrix m)
 Returns true if the elements of the two matrices are exactly equal (unlike operator== which uses epsilon).
 
override bool Equals (object obj)
 Returns true if the elements of the two matrices are exactly equal (unlike operator== which uses epsilon).
 
double GetDeterminant ()
 Returns the determinant. More...
 
override int GetHashCode ()
 
Vector GetRow (int i)
 Gets the values for the i-th row. More...
 
Matrix Inverse ()
 Returns the inverse matrix of this one. More...
 
Matrix NormalTransformMatrix (bool flip=false)
 Creates a new matrix for transforming the normals of an object. More...
 
Matrix Orthogonal ()
 Returns orthogonal matrix (each column vector is orthogonal to the other two in 3D space).
 
Matrix Orthonormal ()
 Returns orthonormal matrix (each column vector is normalized and orthogonal to the other two in 3D space). More...
 
Matrix ReplaceColumn (int i, Vector column)
 Gets a new matrix the the i-th column values replaced with the given one. More...
 
Matrix ReplaceRow (int i, Vector row)
 Gets a new matrix the the i-th row values replaced with the given one. More...
 
Matrix Rotate (Vector axis)
 Returns a new matrix which is this one rotated around the given axis. More...
 
Vector RotationAngles ()
 Returns the tree three angles, used to compose the matrix, called Euler angles if [M] = [Rx] * [Ry] * [Rz], that is {x,y,z}, given [M], where [Ri] is a rotation matrix for a given axis and angle. Check the rotation matrix composition functions MakeRotationMatrixX(float), MakeRotationMatrixY(float) and MakeRotationMatrixZ(float) More...
 
Vector Scale ()
 Returns the scaling component of matrix: if [M] = [R] x {S}, that is {S}, given [M] More...
 
override string ToString ()
 
Matrix Transpose ()
 Returns a Transposed matrix of this one. More...
 
Matrix WithoutScale ()
 Returns a matrix with normalized columns. This effectively removes scaling from a transform matrix. More...
 

Static Public Member Functions

static Matrix FromRows (Vector row0, Vector row1, Vector row2)
 Constructs a matrix from the three rows. The vector row coordinates are copied into the new matrix own columns. More...
 
static Matrix FromString (string matrix)
 Parses a matrix string value and returns a matrix instance. More...
 
static Matrix MakeDiagonal (Vector values)
 Returns a diagonal matrix. More...
 
static Matrix MakeOuterProduct (Vector a, Vector b)
 Returns an outer product matrix of the two given vectors. More...
 
static Matrix MakeRotationMatrixX (float radians)
 Creates a new affine transformation matrix for rotation around the X axis. More...
 
static Matrix MakeRotationMatrixY (float radians)
 Creates a new affine transformation matrix for rotation around the Y axis. More...
 
static Matrix MakeRotationMatrixZ (float radians)
 Creates a new affine transformation matrix for rotation around the Z axis. More...
 
static bool operator!= (Matrix m0, Matrix m1)
 
static Matrix operator* (float left, Matrix right)
 
static Matrix operator* (Matrix left, float right)
 
static Vector operator* (Matrix m, Vector v)
 Multiplies a matrix by a vector. Note that this is different from multiplying the same vector by the same matrix. More...
 
static Matrix operator* (Matrix m1, Matrix m2)
 Multiplies two matrices. The result is a new matrix instance. More...
 
static Vector operator* (Vector v, Matrix m)
 Multiplies a vector by a matrix. Note that this is different from multiplying the same matrix by the same vector. More...
 
static Matrix operator+ (Matrix left, float right)
 
static Matrix operator+ (Matrix left, Matrix right)
 
static Matrix operator- (Matrix left, float right)
 
static Matrix operator- (Matrix left, Matrix right)
 
static Matrix operator- (Matrix m)
 
static float operator/ (float x, Matrix m)
 Divide a number by the determinant of a matrix. Does not check if the determinant is zero.
 
static Matrix operator/ (Matrix left, float right)
 
static bool operator== (Matrix m0, Matrix m1)
 
static Matrix operator^ (Matrix m, Vector a)
 Cross product of a matrix and a vector.
 
static Matrix operator^ (Vector a, Matrix m)
 Cross product of a vector and a matrix.
 
static Matrix OuterProductMatrix (Vector a, Vector b)
 

Static Public Attributes

static readonly Matrix Identity = new Matrix(1)
 
static readonly Matrix Zero = new Matrix()
 

Properties

Vector Column0 [get]
 Returns Column0. More...
 
Vector Column1 [get]
 Returns Column1. More...
 
Vector Column2 [get]
 Returns Column2. More...
 
Vector Row0 [get]
 Returns Row0. More...
 
Vector Row1 [get]
 Returns Row1. More...
 
Vector Row2 [get]
 Returns Row2. More...
 
Vector this[int i] [get]
 Gets the i-th column. More...
 

Detailed Description

A class representing a 3x3 matrix. It usually represents a linear transformation in 3D space.

Constructor & Destructor Documentation

◆ Matrix() [1/4]

VRay.Matrix.Matrix ( Vector[]  columns)

Constructs a matrix from an array of 3 vectors used as columns.

Parameters
columnsThe array of vectors.

◆ Matrix() [2/4]

VRay.Matrix.Matrix ( Vector  a,
Vector  b,
Vector  c 
)

Constructor from the three columns of the matrix. The vector coordinates are copied into the matrix own columns. The references are not preserved.

Parameters
aThe first column.
bThe second column.
cThe third column.

◆ Matrix() [3/4]

VRay.Matrix.Matrix ( float  d)

Constructs a matrix with the specified value for the main diagonal.

Parameters
dThe value for the main diagonal.

◆ Matrix() [4/4]

VRay.Matrix.Matrix ( Vector  diagonal)

Constructs a matrix using the passed Vector values for the new matrix main diagonal.

Parameters
diagonalThe values for the main diagonal.

Member Function Documentation

◆ AddDiagonal()

Matrix VRay.Matrix.AddDiagonal ( Vector  a)

Returns a new matrix adding the passed vector values to the main diagonal of this one.

Parameters
aThe vector containing the diagonal values.
Returns
A new matrix.

◆ CompareTo()

int VRay.Matrix.CompareTo ( Matrix  m)

Compares the matrices.

Parameters
mThe matrix to compare to
Returns
-1 if this matrix is less than the passed one, 0 if they are equal, +1 if greater.

◆ FromRows()

static Matrix VRay.Matrix.FromRows ( Vector  row0,
Vector  row1,
Vector  row2 
)
static

Constructs a matrix from the three rows. The vector row coordinates are copied into the new matrix own columns.

Parameters
row0The first row.
row1The second row.
row2The third wow.

◆ FromString()

static Matrix VRay.Matrix.FromString ( string  matrix)
static

Parses a matrix string value and returns a matrix instance.

Parameters
matrixThe string representation of the matrix.
Returns
The matrix instance.

◆ GetDeterminant()

double VRay.Matrix.GetDeterminant ( )

Returns the determinant.

Returns
The determinant as double.

◆ GetRow()

Vector VRay.Matrix.GetRow ( int  i)

Gets the values for the i-th row.

Parameters
iThe row number.
Returns
A Vector instance with the values for the i-th row of the matrix.

◆ Inverse()

Matrix VRay.Matrix.Inverse ( )

Returns the inverse matrix of this one.

Returns
The inverse matrix on success. Matrix.Zero on failure. (You can reference compare the result to Matrix.Zero)

◆ MakeDiagonal()

static Matrix VRay.Matrix.MakeDiagonal ( Vector  values)
static

Returns a diagonal matrix.

Parameters
valuesThe three diagonal values. They can be different.
Returns
A new matrix with diagonal set to the passed vector values

◆ MakeOuterProduct()

static Matrix VRay.Matrix.MakeOuterProduct ( Vector  a,
Vector  b 
)
static

Returns an outer product matrix of the two given vectors.

Parameters
aFirst vector
bSecond vector
Returns
The resultant matrix.

◆ MakeRotationMatrixX()

static Matrix VRay.Matrix.MakeRotationMatrixX ( float  radians)
static

Creates a new affine transformation matrix for rotation around the X axis.

Parameters
radiansThe rotating angle in radians.
Returns
A new matrix.

◆ MakeRotationMatrixY()

static Matrix VRay.Matrix.MakeRotationMatrixY ( float  radians)
static

Creates a new affine transformation matrix for rotation around the Y axis.

Parameters
radiansThe rotating angle in radians.
Returns
A new matrix.

◆ MakeRotationMatrixZ()

static Matrix VRay.Matrix.MakeRotationMatrixZ ( float  radians)
static

Creates a new affine transformation matrix for rotation around the Z axis.

Parameters
radiansThe rotating angle in radians.
Returns
A new matrix.

◆ NormalTransformMatrix()

Matrix VRay.Matrix.NormalTransformMatrix ( bool  flip = false)

Creates a new matrix for transforming the normals of an object.

Parameters
flipInvert/flip the the result. (You can use the determinant to check if flipping is needed).
Returns
A new matrix.

◆ operator*() [1/3]

static Vector VRay.Matrix.operator* ( Matrix  m,
Vector  v 
)
static

Multiplies a matrix by a vector. Note that this is different from multiplying the same vector by the same matrix.

Parameters
mThe matrix argument.
vThe vector argument.
Returns
A vector which is the result of multiplying the matrix by the vector.

◆ operator*() [2/3]

static Matrix VRay.Matrix.operator* ( Matrix  m1,
Matrix  m2 
)
static

Multiplies two matrices. The result is a new matrix instance.

Parameters
m1The first matrix.
m2The second matrix.
Returns
The result of the matrix multiplication.

◆ operator*() [3/3]

static Vector VRay.Matrix.operator* ( Vector  v,
Matrix  m 
)
static

Multiplies a vector by a matrix. Note that this is different from multiplying the same matrix by the same vector.

Parameters
vThe vector argument.
mThe matrix argument.
Returns
A vector which is the result of multiplying the vector by the matrix.

◆ Orthonormal()

Matrix VRay.Matrix.Orthonormal ( )

Returns orthonormal matrix (each column vector is normalized and orthogonal to the other two in 3D space).

Returns
A new matrix orthonormal of this one.

◆ ReplaceColumn()

Matrix VRay.Matrix.ReplaceColumn ( int  i,
Vector  column 
)

Gets a new matrix the the i-th column values replaced with the given one.

Parameters
iThe column number.
columnThe new value of the column.
Returns
A new matrix with the replaced column.

◆ ReplaceRow()

Matrix VRay.Matrix.ReplaceRow ( int  i,
Vector  row 
)

Gets a new matrix the the i-th row values replaced with the given one.

Parameters
iThe row number.
rowThe new value of the row.
Returns
A new matrix with the replaced row.

◆ Rotate()

Matrix VRay.Matrix.Rotate ( Vector  axis)

Returns a new matrix which is this one rotated around the given axis.

Parameters
axisAn axis vector to rotate around. The length of the axis is the tangent of the angle of rotation.
Returns
A new matrix.

◆ RotationAngles()

Vector VRay.Matrix.RotationAngles ( )

Returns the tree three angles, used to compose the matrix, called Euler angles if [M] = [Rx] * [Ry] * [Rz], that is {x,y,z}, given [M], where [Ri] is a rotation matrix for a given axis and angle. Check the rotation matrix composition functions MakeRotationMatrixX(float), MakeRotationMatrixY(float) and MakeRotationMatrixZ(float)

Returns
The Euler angles as components of a vector

◆ Scale()

Vector VRay.Matrix.Scale ( )

Returns the scaling component of matrix: if [M] = [R] x {S}, that is {S}, given [M]

Returns
The scale vector.

◆ Transpose()

Matrix VRay.Matrix.Transpose ( )

Returns a Transposed matrix of this one.

Returns
A new matrix.

◆ WithoutScale()

Matrix VRay.Matrix.WithoutScale ( )

Returns a matrix with normalized columns. This effectively removes scaling from a transform matrix.

Returns
A new matrix.

Property Documentation

◆ Column0

Vector VRay.Matrix.Column0
get

Returns Column0.

Returns
The column Vector at position 0.

◆ Column1

Vector VRay.Matrix.Column1
get

Returns Column1.

Returns
The column Vector at position 1.

◆ Column2

Vector VRay.Matrix.Column2
get

Returns Column2.

Returns
The column Vector at position 2.

◆ Row0

Vector VRay.Matrix.Row0
get

Returns Row0.

Returns
The row Vector at position 0.

◆ Row1

Vector VRay.Matrix.Row1
get

Returns Row1.

Returns
The row Vector at position 1.

◆ Row2

Vector VRay.Matrix.Row2
get

Returns Row2.

Returns
The row Vector at position 2.

◆ this[int i]

Vector VRay.Matrix.this[int i]
get

Gets the i-th column.

Parameters
iThe column number.
Returns
The column Vector at position i.

The documentation for this class was generated from the following file: