Struct mat4d_t
4x4 matrix, column-major in 16 inline doubles: a sequential-layout value type, the mirror of the
C++ geom::mat4<double> (128 bytes, T m[16]). It has no in-place mutating method:
write an element through m or the this[int, int] indexer on a variable,
field or array element (never on a property, which hands out a copy), assign Trans,
or build a new matrix with a constructor, GetInverse(), TransposeMat,
NoTransMat, GetScaleMat(double) and the other Get* members.
new mat4d_t() is the identity matrix; default(mat4d_t) is the zero matrix, as the C++
mat4() is.
public struct mat4d_t : IEquatable<mat4d_t>, IWriteBin, IEqualityOperators<mat4d_t, mat4d_t, bool>, IAdditionOperators<mat4d_t, mat4d_t, mat4d_t>, ISubtractionOperators<mat4d_t, mat4d_t, mat4d_t>, IUnaryNegationOperators<mat4d_t, mat4d_t>, IMultiplyOperators<mat4d_t, mat4d_t, mat4d_t>, IMultiplyOperators<mat4d_t, double, mat4d_t>, IMultiplyOperators<mat4d_t, vec3d_t, vec3d_t>, IMultiplyOperators<mat4d_t, dvec3d_t, dvec3d_t>, IDivisionOperators<mat4d_t, double, mat4d_t>
- Implements
- Inherited Members
- Extension Methods
Constructors
mat4d_t()
Initializes the identity matrix.
public mat4d_t()
mat4d_t(AxisAngle4d)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public mat4d_t(AxisAngle4d src)
Parameters
srcAxisAngle4dsrc
mat4d_t(AxisAngle4d, vec3d_t)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public mat4d_t(AxisAngle4d src, vec3d_t pivot)
Parameters
srcAxisAngle4dsrc
pivotvec3d_trotation pivot
mat4d_t(mat4d_t)
copy constructor
public mat4d_t(mat4d_t src)
Parameters
srcmat4d_tsrc
mat4d_t(vec3d_t)
Set this matrix to translation matrix. m(3,0)=trans.x; m(3,1)=trans.y; m(3,2)=trans.z.
public mat4d_t(vec3d_t trans)
Parameters
transvec3d_ttranslation
mat4d_t(vec3d_t, vec3d_t, vec3d_t, IndexFlag)
Initializes a new instance of the mat4d_t struct from three vectors.
public mat4d_t(vec3d_t v0, vec3d_t v1, vec3d_t v2, mat4d_t.IndexFlag indexFlag = IndexFlag.ByColumn)
Parameters
v0vec3d_tThe first vector.
v1vec3d_tThe second vector.
v2vec3d_tThe third vector.
indexFlagmat4d_t.IndexFlagDetermines whether vectors are used as columns or rows in the matrix.
mat4d_t(vec3d_t, double)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public mat4d_t(vec3d_t axis, double rad)
Parameters
mat4d_t(vec3d_t, double, vec3d_t)
A matrix rotate at pivot along axis by angle rad.
public mat4d_t(vec3d_t axis, double rad, vec3d_t pivot)
Parameters
mat4d_t(IEnumerable<double>)
Initializes a new instance of the mat4d_t struct from an enumerable of double values. Takes the first 16 values from the enumerable.
public mat4d_t(IEnumerable<double> src)
Parameters
srcIEnumerable<double>The enumerable collection of double values.
mat4d_t(double)
a scale matrix which is I*scale. Where I is an identity matrix.
public mat4d_t(double scale)
Parameters
scaledoublescale
mat4d_t(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
constructor
public mat4d_t(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
Parameters
m00doublevalue at (0,0)
m01doublevalue at (0,1)
m02doublevalue at (0,2)
m03doublevalue at (0,3)
m10doublevalue at (1,0)
m11doublevalue at (1,1)
m12doublevalue at (1,2)
m13doublevalue at (1,3)
m20doublevalue at (2,0)
m21doublevalue at (2,1)
m22doublevalue at (2,2)
m23doublevalue at (2,3)
m30doublevalue at (3,0)
m31doublevalue at (3,1)
m32doublevalue at (3,2)
m33doublevalue at (3,3)
mat4d_t(double[])
Ctor by a copy of the first 16 elements of src.
public mat4d_t(double[] src)
Parameters
srcdouble[]src
mat4d_t(BinaryReader)
Ctor by the 16 doubles read from reader.
public mat4d_t(BinaryReader reader)
Parameters
readerBinaryReaderreader
mat4d_t(ReadOnlySpan<double>)
Ctor by a copy of the 16 elements of src.
public mat4d_t(ReadOnlySpan<double> src)
Parameters
srcReadOnlySpan<double>src
mat4d_t(string)
Ctor by parsing str.
The format is {0,1,2,3,...,15}, the form ToString() writes.
public mat4d_t(string str)
Parameters
strstringsrc
Fields
m
Column-major matrix in form of a 16-element inline array. m[i] reads and writes the
element in place on a variable; on a property receiver the write is a compile error.
public mat4d_t.Elements m
Field Value
Properties
AxialNormal
vec3d_t on 2th row. It usually is tool normal.
public readonly vec3d_t AxialNormal { get; }
Property Value
AxisAngle
Gets the axis-angle representation of the rotation component of this matrix.
public readonly AxisAngle4d AxisAngle { get; }
Property Value
Determinant
Gets the determinant of this matrix.
public readonly double Determinant { get; }
Property Value
- double
The determinant value.
Idt
Generate identity matrix.
public static mat4d_t Idt { get; }
Property Value
IsAllNaN
Gets a value indicating whether all elements of this matrix are NaN.
public readonly bool IsAllNaN { get; }
Property Value
IsFinite
Gets a value indicating whether all elements of this matrix are finite numbers.
public readonly bool IsFinite { get; }
Property Value
IsRotate
Gets a value indicating whether this matrix represents a pure rotation.
public readonly bool IsRotate { get; }
Property Value
this[int, int]
The matrix element at the specified row and column, i.e. m[i * 4 + j].
The setter writes the element in place; on a property receiver it is a compile error.
public double this[int i, int j] { readonly get; set; }
Parameters
Property Value
MatScale
Gets the scale factor of the matrix, calculated as the cube root of the determinant without translation.
public readonly double MatScale { get; }
Property Value
NaN
Generate matrix that all elements are nan.
public static mat4d_t NaN { get; }
Property Value
NativeByteSize
Byte size of the struct as core.dll sees it: sizeof(mat4d_t), sixteen doubles.
public static int NativeByteSize { get; }
Property Value
NoTransMat
Generate new matrix that the translation part is zero. i.e. (m[12],m[13],m[14])=(0,0,0).
public readonly mat4d_t NoTransMat { get; }
Property Value
Pn
Pn: Point and Normal (position + tool axis direction). Point = Trans = (m[12], m[13], m[14]), Normal = AxialNormal = (m[8], m[9], m[10]).
public readonly dvec3d_t Pn { get; }
Property Value
Trans
Translation. The value is vec3d_t(m[12], m[13], m[14]). The setter writes the three elements in place; on a property receiver it is a compile error.
public vec3d_t Trans { readonly get; set; }
Property Value
TransposeMat
Gets a new matrix that is the transpose of this matrix.
public readonly mat4d_t TransposeMat { get; }
Property Value
Zero
Generate zero matrix.
public static mat4d_t Zero { get; }
Property Value
Methods
At(int, int)
Gets the matrix element at the specified row and column, i.e. m[i * 4 + j].
public readonly double At(int i, int j)
Parameters
Returns
- double
The element value.
Equals(mat4d_t)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(mat4d_t other)
Parameters
othermat4d_tAn object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
EqualsByTolerance(mat4d_t, double)
Determines whether this matrix is equal to another matrix within a specified tolerance.
public readonly bool EqualsByTolerance(mat4d_t other, double tolerance)
Parameters
othermat4d_tThe matrix to compare with this matrix.
tolerancedoubleThe maximum absolute difference between matrix elements for them to be considered equal.
Returns
- bool
true if the matrices are equal within the specified tolerance; otherwise, false.
FilledMat(double)
Creates a matrix with all elements set to the specified value.
public static mat4d_t FilledMat(double v)
Parameters
vdoubleThe value to fill all elements with.
Returns
- mat4d_t
A new matrix with all elements set to the specified value.
GetFloatingZeroFixed(double)
Creates a new matrix whose floating-point values close to zero are exactly zero.
public readonly mat4d_t GetFloatingZeroFixed(double floatingZeroTolerance = 1E-12)
Parameters
floatingZeroTolerancedoubleThe tolerance below which values are considered zero. Default is 1e-12.
Returns
- mat4d_t
A new matrix with the near-zero elements set to zero.
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetInverse()
Gets the inverse.
public readonly mat4d_t GetInverse()
Returns
- mat4d_t
Inverse matrix
GetScaleMat(double)
Creates a new matrix by scaling the first three columns of every row of this matrix
by the specified factor (the last column, m[3], m[7], m[11], m[15], is kept).
public readonly mat4d_t GetScaleMat(double scale)
Parameters
scaledoubleThe scale factor to apply.
Returns
- mat4d_t
A new scaled matrix.
GetSingularValueAdjusted(double)
Creates a new matrix whose elements close to 0, 1, or -1 (within the specified tolerance) are exactly those values.
public readonly mat4d_t GetSingularValueAdjusted(double tolerance)
Parameters
tolerancedoubleThe tolerance threshold for considering values close to 0, 1, or -1.
Returns
- mat4d_t
A new adjusted matrix.
GetTransform(Func<double, double>)
Creates a new matrix with all elements transformed by the specified function.
public readonly mat4d_t GetTransform(Func<double, double> transformingFunc)
Parameters
Returns
- mat4d_t
A new matrix with transformed elements.
ReadBin(BinaryReader)
Reads the 16 doubles written by WriteBin(BinaryWriter).
public static mat4d_t ReadBin(BinaryReader reader)
Parameters
readerBinaryReaderreader
Returns
- mat4d_t
the matrix read
ToArray()
A copy of the 16 elements as a new array.
public readonly double[] ToArray()
Returns
- double[]
the 16 elements, column-major
ToBriefString()
To brief string.
public readonly string ToBriefString()
Returns
- string
brief string.
ToLinesString()
Converts the matrix to a multi-line string representation with aligned columns.
public readonly string ToLinesString()
Returns
- string
A formatted multi-line string representation of the matrix.
ToString()
Returns the fully qualified type name of this instance.
public override readonly string ToString()
Returns
- string
The fully qualified type name.
WriteBin(BinaryWriter)
Writes the object's data to a binary stream.
public readonly void WriteBin(BinaryWriter writer)
Parameters
writerBinaryWriterThe binary writer to write to
Operators
operator +(mat4d_t, mat4d_t)
Adds two matrices element-wise.
public static mat4d_t operator +(mat4d_t a, mat4d_t b)
Parameters
Returns
- mat4d_t
A new matrix that is the sum of the two matrices.
operator /(mat4d_t, double)
Divides a matrix by a scalar value.
public static mat4d_t operator /(mat4d_t a, double b)
Parameters
Returns
- mat4d_t
A new matrix with all elements divided by the scalar.
operator ==(mat4d_t, mat4d_t)
Determines whether two matrices are equal.
public static bool operator ==(mat4d_t a, mat4d_t b)
Parameters
Returns
- bool
true if the matrices are equal; otherwise, false.
operator !=(mat4d_t, mat4d_t)
Determines whether two matrices are not equal.
public static bool operator !=(mat4d_t a, mat4d_t b)
Parameters
Returns
- bool
true if the matrices are not equal; otherwise, false.
operator *(mat4d_t, dvec3d_t)
Multiple matrxi to cutter location (Point and Normal).
public static dvec3d_t operator *(mat4d_t m, dvec3d_t v)
Parameters
Returns
- dvec3d_t
transformed point and normal
operator *(mat4d_t, mat4d_t)
Multiplies two matrices.
public static mat4d_t operator *(mat4d_t a, mat4d_t b)
Parameters
Returns
- mat4d_t
A new matrix that is the product of the two matrices.
operator *(mat4d_t, vec3d_t)
Multiplies a matrix by a vector, transforming the vector.
public static vec3d_t operator *(mat4d_t a, vec3d_t b)
Parameters
Returns
- vec3d_t
The transformed vector.
operator *(mat4d_t, double)
Multiplies a matrix by a scalar value.
public static mat4d_t operator *(mat4d_t a, double s)
Parameters
Returns
- mat4d_t
A new matrix with all elements multiplied by the scalar.
operator -(mat4d_t, mat4d_t)
Subtracts the second matrix from the first matrix element-wise.
public static mat4d_t operator -(mat4d_t a, mat4d_t b)
Parameters
Returns
- mat4d_t
A new matrix that is the difference of the two matrices.
operator -(mat4d_t)
Returns the negation of the specified matrix.
public static mat4d_t operator -(mat4d_t src)
Parameters
srcmat4d_tThe source matrix.
Returns
- mat4d_t
A new matrix with all elements negated.