struct ThreeDViewer.Mathematics.Matrix4¶
Overview¶
Represents a matrix of size 4x4. More…
struct Matrix4: IEquatable< Matrix4 > { // fields static const int Size = 4; static readonly Matrix4 Identity = new(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); static readonly Matrix4 ProjectionOrthoX = new(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); static readonly Matrix4 ProjectionOrthoY = new(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); static readonly Matrix4 ProjectionOrthoZ = new(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1); static readonly Matrix4 Zero = new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // properties double[,] Values; double V00; double V01; double V02; double V03; double V10; double V11; double V12; double V13; double V20; double V21; double V22; double V23; double V30; double V31; double V32; double V33; double Determinant; Matrix4 Normalized; double Trace; double this[int rowIndex, int columnIndex]; // methods Matrix4(double values[,]); Matrix4( double value00, double value01, double value02, double value03, double value10, double value11, double value12, double value13, double value20, double value21, double value22, double value23, double value30, double value31, double value32, double value33 ); Matrix4(Matrix4 matrix); Matrix4(Vector4[] values, bool isColums = true); Matrix4 Transpose(); override bool Equals(object other); bool Equals(Matrix4 other); bool Equals(object other, double tolerance); bool Equals(Matrix4 other, double tolerance); override int GetHashCode(); Matrix4 Invert(); override string ToString(); static Matrix4 operator + (Matrix4 mat, double scalar); static Matrix4 operator + (double scalar, Matrix4 mat); static Matrix4 operator - (Matrix4 mat, double scalar); static Matrix4 operator - (double scalar, Matrix4 mat); static Matrix4 operator * (Matrix4 mat, double scalar); static Matrix4 operator * (double scalar, Matrix4 mat); static Matrix4 operator/ (Matrix4 mat, double scalar); static Matrix4 operator - (Matrix4 mat); static Matrix4 operator + (Matrix4 left, Matrix4 right); static Matrix4 operator - (Matrix4 left, Matrix4 right); static Matrix4 operator * (Matrix4 left, Matrix4 right); static bool operator == (Matrix4 left, Matrix4 right); static bool operator != (Matrix4 left, Matrix4 right); static Matrix4 CreateRotationX(double angle); static Matrix4 CreateRotationY(double angle); static Matrix4 CreateRotationZ(double angle); static Matrix4 CreateRotation(Vector3 rotation); static Matrix4 CreateRotationAbitraryAxis(Axis rotationAxis, double angle); static Matrix4 CreateScale(double scaleFactor); static Matrix4 CreatePerspectiveOffCenter( double left, double right, double bottom, double top, double depthNear, double depthFar ); static Matrix4 CreatePerspectiveFieldOfView( double fovy, double aspect, double depthNear, double depthFar ); static Matrix4 CreateTranslation(double x, double y, double z); static Matrix4 CreateTranslation(Vector3 vector); static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up); static Matrix4 Transpose(Matrix4 mat); static Matrix4 Normalize(Matrix4 mat); };
Detailed Documentation¶
Represents a matrix of size 4x4.
Every coordinates are in [y, x] format (or [row, column]).
Fields¶
static const int Size = 4
Size of the matrix.
static readonly Matrix4 Identity = new(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
The identity matrix.
static readonly Matrix4 ProjectionOrthoX = new(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
Matrix for projection onto the x = 0 plane.
static readonly Matrix4 ProjectionOrthoY = new(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
Matrix for projection onto the y = 0 plane.
static readonly Matrix4 ProjectionOrthoZ = new(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
Matrix for projection onto the z = 0 plane.
static readonly Matrix4 Zero = new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
The zero matrix.
Properties¶
double[,] Values
Gets the values of the matrix.
double V00
Gets the value at 0, 0 on the matrix.
double V01
Gets the value at 0, 1 on the matrix.
double V02
Gets the value at 0, 2 on the matrix.
double V03
Gets the value at 0, 3 on the matrix.
double V10
Gets the value at 1, 0 on the matrix.
double V11
Gets the value at 1, 1 on the matrix.
double V12
Gets the value at 1, 2 on the matrix.
double V13
Gets the value at 1, 3 on the matrix.
double V20
Gets the value at 2, 0 on the matrix.
double V21
Gets the value at 2, 1 on the matrix.
double V22
Gets the value at 2, 2 on the matrix.
double V23
Gets the value at 2, 3 on the matrix.
double V30
Gets the value at 3, 0 on the matrix.
double V31
Gets the value at 3, 1 on the matrix.
double V32
Gets the value at 3, 2 on the matrix.
double V33
Gets the value at 3, 3 on the matrix.
double Determinant
Gets the determinant of the matrix.
Matrix4 Normalized
Gets the normalized matrix.
double Trace
Gets the trace of the matrix, the sum of the values along the diagonal axis.
double this[int rowIndex, int columnIndex]
Gets the value at the specified row and column.
Parameters:
rowIndex |
The index of the row. |
columnIndex |
The index of the column. |
Returns:
The element at the given row and column index.
Methods¶
Matrix4(double values[,])
Initializes a new instance of the Matrix4 struct.
Parameters:
values |
Values of the matrix. Should be 4x4. |
Matrix4( double value00, double value01, double value02, double value03, double value10, double value11, double value12, double value13, double value20, double value21, double value22, double value23, double value30, double value31, double value32, double value33 )
Initializes a new instance of the Matrix4 struct.
Parameters:
value00 |
Value of the matrix in the 0, 0 position. |
value01 |
Value of the matrix in the 0, 1 position. |
value02 |
Value of the matrix in the 0, 2 position. |
value03 |
Value of the matrix in the 0, 3 position. |
value10 |
Value of the matrix in the 1, 0 position. |
value11 |
Value of the matrix in the 1, 1 position. |
value12 |
Value of the matrix in the 1, 2 position. |
value13 |
Value of the matrix in the 1, 3 position. |
value20 |
Value of the matrix in the 2, 0 position. |
value21 |
Value of the matrix in the 2, 1 position. |
value22 |
Value of the matrix in the 2, 2 position. |
value23 |
Value of the matrix in the 2, 3 position. |
value30 |
Value of the matrix in the 3, 0 position. |
value31 |
Value of the matrix in the 3, 1 position. |
value32 |
Value of the matrix in the 3, 2 position. |
value33 |
Value of the matrix in the 3, 3 position. |
Matrix4(Matrix4 matrix)
Initializes a new instance of the Matrix4 struct.
Parameters:
matrix |
Matrix struct to take the values from. |
Matrix4(Vector4[] values, bool isColums = true)
Initializes a new instance of the Matrix4 struct.
///
Parameters:
values |
Values of the Matrix. |
isColums |
Tells if the vector is a column vector or a row vector. |
Matrix4 Transpose()
Computes the transpose of this matrix.
Returns:
The transpose of this matrix.
bool Equals(object other, double tolerance)
Comparator within a tolerance.
Parameters:
other |
Matrix to compare with. |
tolerance |
Tolerance to apply in the comparison. |
Returns:
True if two matrices are equal withing a tolerance.
bool Equals(Matrix4 other, double tolerance)
Comparator within a tolerance.
Parameters:
other |
Matrix to compare with. |
tolerance |
Tolerance to apply in the comparison. |
Returns:
True if two matrices are equal withing a tolerance.
Matrix4 Invert()
Inverts this instance.
Taken from here : https://github.com/opentk/opentk/blob/master/src/OpenTK.Mathematics/Matrix/Matrix4d.cs#L1582.
Parameters:
InvalidOperationException |
Thrown when the matrix is singular and cannot be inverted. |
Returns:
The inverted matrix.
static Matrix4 operator + (Matrix4 mat, double scalar)
Adds a matrix and a scalar.
Parameters:
mat |
Matrix to add to. |
scalar |
Scalar to add to the matrix. |
Returns:
The added matrix.
static Matrix4 operator + (double scalar, Matrix4 mat)
Adds a matrix and a scalar.
Parameters:
mat |
Matrix to add to. |
scalar |
Scalar to add to the matrix. |
Returns:
The added matrix.
static Matrix4 operator - (Matrix4 mat, double scalar)
Substracts a matrix and a scalar.
Parameters:
mat |
Matrix to substract to. |
scalar |
Scalar to substract to the matrix. |
Returns:
The substracted matrix.
static Matrix4 operator - (double scalar, Matrix4 mat)
Substracts a matrix and a scalar.
Parameters:
mat |
Matrix to substract to. |
scalar |
Scalar to substract to the matrix. |
Returns:
The substracted matrix.
static Matrix4 operator * (Matrix4 mat, double scalar)
Multiplies a matrix and a scalar.
Parameters:
mat |
Matrix to multiply. |
scalar |
Scalar to multiply with the matrix. |
Returns:
The multiplied matrix.
static Matrix4 operator * (double scalar, Matrix4 mat)
Multiplies a matrix and a scalar.
Parameters:
mat |
Matrix to multiply. |
scalar |
Scalar to multiply with the matrix. |
Returns:
The multiplied matrix.
static Matrix4 operator/ (Matrix4 mat, double scalar)
Divides a matrix by a scalar.
Parameters:
mat |
Matrix to divide. |
scalar |
Scalar to divide the matrix with. |
Returns:
The divided matrix.
static Matrix4 operator - (Matrix4 mat)
Inverses the sign of a matrix.
Parameters:
mat |
Matrix to inverse the sign of. |
Returns:
The sign inverted matrix.
static Matrix4 operator + (Matrix4 left, Matrix4 right)
Adds two matrices.
Parameters:
left |
The matrix on the left. |
right |
The matrix on the right. |
Returns:
The added matrix.
static Matrix4 operator - (Matrix4 left, Matrix4 right)
Substracts two matrices.
Parameters:
left |
The matrix on the left. |
right |
The matrix on the right. |
Returns:
The substracted matrix.
static Matrix4 operator * (Matrix4 left, Matrix4 right)
Multiplies two matrices.
Parameters:
left |
The left matrix. |
right |
The right matrix. |
Returns:
The dot product of the matrices.
static bool operator == (Matrix4 left, Matrix4 right)
Check if two matrices are equal.
Parameters:
left |
The left matrix. |
right |
The right matrix. |
Returns:
True if the matrices are equal.
static bool operator != (Matrix4 left, Matrix4 right)
Check if two matrices are not equal.
Parameters:
left |
The left matrix. |
right |
The right matrix. |
Returns:
True if the matrices are not equal.
static Matrix4 CreateRotationX(double angle)
Builds a rotation matrix for a rotation around x-axis.
Parameters:
angle |
The counter clockwise angle in radians. |
Returns:
The rotation matrix.
static Matrix4 CreateRotationY(double angle)
Builds a rotation matrix for a rotation around y-axis.
Parameters:
angle |
The counter clockwise angle in radians. |
Returns:
The rotation matrix.
static Matrix4 CreateRotationZ(double angle)
Builds a rotation matrix for a rotation around z-axis.
Parameters:
angle |
The counter clockwise angle in radians. |
Returns:
The rotation matrix.
static Matrix4 CreateRotation(Vector3 rotation)
Builds a combined rotation matrix around the X, Y and Z axes. Angles in radians.
Parameters:
rotation |
Rotation that will be applied in the matrix. |
Returns:
The rotation matrix.
static Matrix4 CreateRotationAbitraryAxis(Axis rotationAxis, double angle)
Builds a rotation matrix around an arbitrary axis.
Parameters:
rotationAxis |
The arbitrary axis to rotate about. |
angle |
The angle of the rotation. |
Returns:
The constructed rotation matrix.
static Matrix4 CreateScale(double scaleFactor)
Builds a scale matrix.
Parameters:
scaleFactor |
The scaling factor for this matrix. |
Returns:
The scale matrix.
static Matrix4 CreatePerspectiveOffCenter( double left, double right, double bottom, double top, double depthNear, double depthFar )
Creates an perspective projection matrix.
Taken from here : https://github.com/opentk/opentk/blob/082c8d228d0def042b11424ac002776432f44f47/src/OpenTK.Mathematics/Matrix/Matrix4d.cs#L1024.
Parameters:
left |
Left edge of the view frustum. |
right |
Right edge of the view frustum. |
bottom |
Bottom edge of the view frustum. |
top |
Top edge of the view frustum. |
depthNear |
Distance to the near clip plane. |
depthFar |
Distance to the far clip plane. |
System.ArgumentOutOfRangeException |
Thrown under the following conditions:
|
Returns:
A perspective projection matrix.
static Matrix4 CreatePerspectiveFieldOfView( double fovy, double aspect, double depthNear, double depthFar )
Creates a perspective projection matrix.
Parameters:
fovy |
Angle of the field of view in the y direction (in radians). |
aspect |
Aspect ratio of the view (width / height). |
depthNear |
Distance to the near clip plane. |
depthFar |
Distance to the far clip plane. |
System.ArgumentOutOfRangeException |
Thrown under the following conditions:
|
Returns:
A perspective projection matrix.
static Matrix4 CreateTranslation(double x, double y, double z)
Build a translation matrix.
Parameters:
x |
X translation. |
y |
Y translation. |
z |
Z translation. |
Returns:
The resulting Matrix4 instance.
static Matrix4 CreateTranslation(Vector3 vector)
Builds a translation matrix from a vector.
Parameters:
vector |
The translation vector. |
Returns:
The resulting Matrix4 instance.
static Matrix4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
Builds a world space to view space matrix.
Parameters:
eye |
Eye (camera) position in world space. |
target |
Target position in world space. |
up |
Up vector in world space (should not be parallel to the camera direction, that is target - eye). |
Returns:
A Matrix that transforms world space to camera (view) space.
static Matrix4 Transpose(Matrix4 mat)
Computes the transpose of the given matrix.
Parameters:
mat |
Matrix to compute the transpose of. |
Returns:
The transpose of the given matrix.
static Matrix4 Normalize(Matrix4 mat)
Divides each element in the Matrix by the Determinant.
Parameters:
mat |
Matrix to normalize. |
Returns:
The normalized matrix.