Class Mat4d
4x4 Matrix.
public class Mat4d : IEquatable<Mat4d>, IBinaryIo, IWriteBin
- Inheritance
-
Mat4d
- Implements
- Inherited Members
- Extension Methods
Constructors
Mat4d()
Initializes a new instance of the Mat4d class.
public Mat4d()
Mat4d(AxisAngle4d)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public Mat4d(AxisAngle4d src)
Parameters
src
AxisAngle4dsrc
Mat4d(AxisAngle4d, Vec3d)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public Mat4d(AxisAngle4d src, Vec3d pivot)
Parameters
src
AxisAngle4dsrc
pivot
Vec3drotation pivot
Mat4d(Mat4d)
copy constructor
public Mat4d(Mat4d src)
Parameters
src
Mat4dsrc
Mat4d(Vec3d)
Set this matrix to translation matrix. m(3,0)=trans.x; m(3,1)=trans.y; m(3,2)=trans.z.
public Mat4d(Vec3d trans)
Parameters
trans
Vec3dtranslation
Mat4d(Vec3d, Vec3d, Vec3d, IndexFlag)
Initializes a new instance of the Mat4d class from three vectors.
public Mat4d(Vec3d v0, Vec3d v1, Vec3d v2, Mat4d.IndexFlag indexFlag = IndexFlag.ByColumn)
Parameters
v0
Vec3dThe first vector.
v1
Vec3dThe second vector.
v2
Vec3dThe third vector.
indexFlag
Mat4d.IndexFlagDetermines whether vectors are used as columns or rows in the matrix.
Mat4d(Vec3d, double)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public Mat4d(Vec3d axis, double rad)
Parameters
Mat4d(Vec3d, double, Vec3d)
A matrix rotate at pivot
along axis
by angle rad
.
public Mat4d(Vec3d axis, double rad, Vec3d pivot)
Parameters
Mat4d(mat4d)
Ctor by Set(mat4d).
public Mat4d(mat4d src)
Parameters
src
mat4dsrc
Mat4d(double)
a scale matrix which is I*scale. Where I is an identity matrix.
public Mat4d(double scale)
Parameters
scale
doublescale
Mat4d(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
constructor
public Mat4d(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
m00
doublevalue at (0,0)
m01
doublevalue at (0,1)
m02
doublevalue at (0,2)
m03
doublevalue at (0,3)
m10
doublevalue at (1,0)
m11
doublevalue at (1,1)
m12
doublevalue at (1,2)
m13
doublevalue at (1,3)
m20
doublevalue at (2,0)
m21
doublevalue at (2,1)
m22
doublevalue at (2,2)
m23
doublevalue at (2,3)
m30
doublevalue at (3,0)
m31
doublevalue at (3,1)
m32
doublevalue at (3,2)
m33
doublevalue at (3,3)
Mat4d(double[])
constructor
public Mat4d(double[] src)
Parameters
src
double[]src
Mat4d(BinaryReader)
Ctor.
public Mat4d(BinaryReader reader)
Parameters
reader
BinaryReaderreader
Mat4d(string)
Ctor by Set(string).
public Mat4d(string str)
Parameters
str
stringsrc
Fields
m
Column-major matrix in form of array.
public double[] m
Field Value
- double[]
Properties
AxialNormal
Vec3d on 2th row. It usually is tool normal.
public Vec3d AxialNormal { get; }
Property Value
AxisAngle
Gets the axis-angle representation of the rotation component of this matrix.
public AxisAngle4d AxisAngle { get; }
Property Value
Determinant
Gets the determinant of this matrix.
public double Determinant { get; }
Property Value
- double
The determinant value.
Idt
Generate identity matrix.
public static Mat4d Idt { get; }
Property Value
IsAllNaN
Gets a value indicating whether all elements of this matrix are NaN.
public bool IsAllNaN { get; }
Property Value
IsFinite
Gets a value indicating whether all elements of this matrix are finite numbers.
public bool IsFinite { get; }
Property Value
IsRotate
Gets a value indicating whether this matrix represents a pure rotation.
public bool IsRotate { get; }
Property Value
MatScale
Gets the scale factor of the matrix, calculated as the cube root of the determinant without translation.
public double MatScale { get; }
Property Value
NaN
Generate matrix that all elements are nan.
public static Mat4d NaN { get; }
Property Value
NativeByteSize
public static int NativeByteSize { get; }
Property Value
- int
Byte size: sizeof(double) * 3.
NoTransMat
Generate new matrix that the translation part is zero. i.e. (m[12],m[13],m[14])=(0,0,0).
public Mat4d NoTransMat { get; }
Property Value
Pn
Pn: the abbr. of Point and Normal.
The value is
new DVec3d(m[12], m[13], m[14], m[8], m[9], m[10])
public DVec3d Pn { get; }
Property Value
Trans
Translation. The value is Vec3d(m[12], m[13], m[14]).
public Vec3d Trans { get; set; }
Property Value
TransposeMat
Gets a new matrix that is the transpose of this matrix.
public Mat4d TransposeMat { get; }
Property Value
Zero
Generate zero matrix.
public static Mat4d Zero { get; }
Property Value
Methods
AdjustSingularValueByTolerance(double)
Adjusts matrix values that are close to 0, 1, or -1 (within the specified tolerance) to exactly those values.
public Mat4d AdjustSingularValueByTolerance(double tolerance)
Parameters
tolerance
doubleThe tolerance threshold for considering values close to 0, 1, or -1.
Returns
- Mat4d
This matrix after adjustment.
At(int, int)
Gets a reference to the matrix element at the specified row and column.
public ref double At(int i, int j)
Parameters
Returns
- double
A reference to the matrix element.
Equals(Mat4d)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Mat4d other)
Parameters
other
Mat4dAn object to compare with this object.
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
EqualsByTolerance(Mat4d, double)
Determines whether this matrix is equal to another matrix within a specified tolerance.
public bool EqualsByTolerance(Mat4d other, double tolerance)
Parameters
other
Mat4dThe matrix to compare with this matrix.
tolerance
doubleThe 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 FilledMat(double v)
Parameters
v
doubleThe value to fill all elements with.
Returns
- Mat4d
A new matrix with all elements set to the specified value.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetInverse()
Gets the inverse.
public Mat4d GetInverse()
Returns
- Mat4d
Inverse matrix
GetScaleMat(double)
Creates a new matrix by scaling this matrix by the specified factor.
public Mat4d GetScaleMat(double scale)
Parameters
scale
doubleThe scale factor to apply.
Returns
- Mat4d
A new scaled matrix.
Inverse()
Inverses this instance.
public Mat4d Inverse()
Returns
- Mat4d
this
ReadBin(BinaryReader)
Reads binary data to initialize the object.
public void ReadBin(BinaryReader reader)
Parameters
reader
BinaryReaderThe binary reader to read from
Scale(double)
Scales the specified s.
public Mat4d Scale(double s)
Parameters
s
doubleThe s.
Returns
- Mat4d
this
Set(AxisAngle4d)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public Mat4d Set(AxisAngle4d src)
Parameters
src
AxisAngle4dsrc
Returns
- Mat4d
this
Set(Mat4d)
copy the data from src to this.
public Mat4d Set(Mat4d src)
Parameters
src
Mat4dsrc
Returns
- Mat4d
this
Set(Vec3d)
Set this matrix to translation matrix. m(3,0)=trans.x; m(3,1)=trans.y; m(3,2)=trans.z.
public Mat4d Set(Vec3d trans)
Parameters
trans
Vec3dtranslation
Returns
- Mat4d
this
Set(Vec3d, double)
Set this matrix to rotation matrix. The matrix is rotate along axis with given radian.
public Mat4d Set(Vec3d axis, double rad)
Parameters
Returns
- Mat4d
this
Set(Vec3d, double, Vec3d)
Set the matrix rotation at pivot
along axis
by angle rad
.
public Mat4d Set(Vec3d axis, double rad, Vec3d pivot)
Parameters
Returns
- Mat4d
this
Set(mat4d)
Set the data by src
.
public Mat4d Set(mat4d src)
Parameters
src
mat4dsrc
Returns
- Mat4d
this
Set(double)
The matrix will be reset to a scale matrix which is I*scale. Where I is an identity matrix.
public Mat4d Set(double scale)
Parameters
scale
doublescale
Returns
- Mat4d
this
Set(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
constructor
public Mat4d Set(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
m00
doublevalue at (0,0)
m01
doublevalue at (0,1)
m02
doublevalue at (0,2)
m03
doublevalue at (0,3)
m10
doublevalue at (1,0)
m11
doublevalue at (1,1)
m12
doublevalue at (1,2)
m13
doublevalue at (1,3)
m20
doublevalue at (2,0)
m21
doublevalue at (2,1)
m22
doublevalue at (2,2)
m23
doublevalue at (2,3)
m30
doublevalue at (3,0)
m31
doublevalue at (3,1)
m32
doublevalue at (3,2)
m33
doublevalue at (3,3)
Returns
- Mat4d
this
Set(int, int, double)
Sets the value of the matrix element at the specified row and column.
public void Set(int i, int j, double v)
Parameters
Set(string)
Set data by str
.
The format is {0,1,2,3,...,15}
public Mat4d Set(string str)
Parameters
str
stringsrc
Returns
- Mat4d
this
SetIdt()
Set this instance to identity matrix.
public void SetIdt()
SetNoTrans()
Sets the translation components of this matrix to zero.
public Mat4d SetNoTrans()
Returns
- Mat4d
This matrix with translation components set to zero.
ToBriefString()
To brief string.
public string ToBriefString()
Returns
- string
brief string.
ToLinesString()
Converts the matrix to a multi-line string representation with aligned columns.
public string ToLinesString()
Returns
- string
A formatted multi-line string representation of the matrix.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
Transpose()
Transposes this matrix in place.
public Mat4d Transpose()
Returns
- Mat4d
This matrix after transposition.
WriteBin(BinaryWriter)
Writes the object's data to a binary stream.
public void WriteBin(BinaryWriter writer)
Parameters
writer
BinaryWriterThe binary writer to write to
Operators
operator +(Mat4d, Mat4d)
Adds two matrices element-wise.
public static Mat4d operator +(Mat4d a, Mat4d b)
Parameters
Returns
- Mat4d
A new matrix that is the sum of the two matrices.
operator /(Mat4d, double)
Divides a matrix by a scalar value.
public static Mat4d operator /(Mat4d a, double b)
Parameters
Returns
- Mat4d
A new matrix with all elements divided by the scalar.
operator ==(Mat4d, Mat4d)
Determines whether two matrices are equal.
public static bool operator ==(Mat4d a, Mat4d b)
Parameters
Returns
- bool
true if the matrices are equal; otherwise, false.
operator !=(Mat4d, Mat4d)
Determines whether two matrices are not equal.
public static bool operator !=(Mat4d a, Mat4d b)
Parameters
Returns
- bool
true if the matrices are not equal; otherwise, false.
operator *(Mat4d, DVec3d)
Multiple matrxi to cutter location (Point and Normal).
public static DVec3d operator *(Mat4d m, DVec3d v)
Parameters
Returns
- DVec3d
transformed point and normal
operator *(Mat4d, Mat4d)
Multiplies two matrices.
public static Mat4d operator *(Mat4d a, Mat4d b)
Parameters
Returns
- Mat4d
A new matrix that is the product of the two matrices.
operator *(Mat4d, Vec3d)
Multiplies a matrix by a vector, transforming the vector.
public static Vec3d operator *(Mat4d a, Vec3d b)
Parameters
Returns
- Vec3d
The transformed vector.
operator *(Mat4d, double)
Multiplies a matrix by a scalar value.
public static Mat4d operator *(Mat4d a, double s)
Parameters
Returns
- Mat4d
A new matrix with all elements multiplied by the scalar.
operator -(Mat4d, Mat4d)
Subtracts the second matrix from the first matrix element-wise.
public static Mat4d operator -(Mat4d a, Mat4d b)
Parameters
Returns
- Mat4d
A new matrix that is the difference of the two matrices.
operator -(Mat4d)
Returns the negation of the specified matrix.
public static Mat4d operator -(Mat4d src)
Parameters
src
Mat4dThe source matrix.
Returns
- Mat4d
A new matrix with all elements negated.