Table of Contents

Class Mat4d

Namespace
Hi.Geom
Assembly
HiGeom.dll

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 AxisAngle4d

src

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 AxisAngle4d

src

pivot Vec3d

rotation pivot

Mat4d(Mat4d)

copy constructor

public Mat4d(Mat4d src)

Parameters

src Mat4d

src

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 Vec3d

translation

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 Vec3d

The first vector.

v1 Vec3d

The second vector.

v2 Vec3d

The third vector.

indexFlag Mat4d.IndexFlag

Determines 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

axis Vec3d

rotation axis

rad double

radian

Mat4d(Vec3d, double, Vec3d)

A matrix rotate at pivot along axis by angle rad.

public Mat4d(Vec3d axis, double rad, Vec3d pivot)

Parameters

axis Vec3d

rotate axis

rad double

angle

pivot Vec3d

rotate pivot

Mat4d(mat4d)

Ctor by Set(mat4d).

public Mat4d(mat4d src)

Parameters

src mat4d

src

Mat4d(double)

a scale matrix which is I*scale. Where I is an identity matrix.

public Mat4d(double scale)

Parameters

scale double

scale

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 double

value at (0,0)

m01 double

value at (0,1)

m02 double

value at (0,2)

m03 double

value at (0,3)

m10 double

value at (1,0)

m11 double

value at (1,1)

m12 double

value at (1,2)

m13 double

value at (1,3)

m20 double

value at (2,0)

m21 double

value at (2,1)

m22 double

value at (2,2)

m23 double

value at (2,3)

m30 double

value at (3,0)

m31 double

value at (3,1)

m32 double

value at (3,2)

m33 double

value at (3,3)

Mat4d(double[])

constructor

public Mat4d(double[] src)

Parameters

src double[]

src

Mat4d(BinaryReader)

Ctor.

public Mat4d(BinaryReader reader)

Parameters

reader BinaryReader

reader

Mat4d(string)

Ctor by Set(string).

public Mat4d(string str)

Parameters

str string

src

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

Vec3d

AxisAngle

Gets the axis-angle representation of the rotation component of this matrix.

public AxisAngle4d AxisAngle { get; }

Property Value

AxisAngle4d

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

Mat4d

IsAllNaN

Gets a value indicating whether all elements of this matrix are NaN.

public bool IsAllNaN { get; }

Property Value

bool

IsFinite

Gets a value indicating whether all elements of this matrix are finite numbers.

public bool IsFinite { get; }

Property Value

bool

IsRotate

Gets a value indicating whether this matrix represents a pure rotation.

public bool IsRotate { get; }

Property Value

bool

MatScale

Gets the scale factor of the matrix, calculated as the cube root of the determinant without translation.

public double MatScale { get; }

Property Value

double

NaN

Generate matrix that all elements are nan.

public static Mat4d NaN { get; }

Property Value

Mat4d

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

Mat4d

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

DVec3d

Trans

Translation. The value is Vec3d(m[12], m[13], m[14]).

public Vec3d Trans { get; set; }

Property Value

Vec3d

TransposeMat

Gets a new matrix that is the transpose of this matrix.

public Mat4d TransposeMat { get; }

Property Value

Mat4d

Zero

Generate zero matrix.

public static Mat4d Zero { get; }

Property Value

Mat4d

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 double

The 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

i int

The row index (0-based).

j int

The column index (0-based).

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 Mat4d

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

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 Mat4d

The matrix to compare with this matrix.

tolerance double

The 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 double

The 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 double

The 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 BinaryReader

The binary reader to read from

Scale(double)

Scales the specified s.

public Mat4d Scale(double s)

Parameters

s double

The 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 AxisAngle4d

src

Returns

Mat4d

this

Set(Mat4d)

copy the data from src to this.

public Mat4d Set(Mat4d src)

Parameters

src Mat4d

src

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 Vec3d

translation

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

axis Vec3d

rotation axis

rad double

radian

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

axis Vec3d

rotation axis

rad double

angle

pivot Vec3d

rotation pivot

Returns

Mat4d

this

Set(mat4d)

Set the data by src.

public Mat4d Set(mat4d src)

Parameters

src mat4d

src

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 double

scale

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 double

value at (0,0)

m01 double

value at (0,1)

m02 double

value at (0,2)

m03 double

value at (0,3)

m10 double

value at (1,0)

m11 double

value at (1,1)

m12 double

value at (1,2)

m13 double

value at (1,3)

m20 double

value at (2,0)

m21 double

value at (2,1)

m22 double

value at (2,2)

m23 double

value at (2,3)

m30 double

value at (3,0)

m31 double

value at (3,1)

m32 double

value at (3,2)

m33 double

value 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

i int

The row index (0-based).

j int

The column index (0-based).

v double

The value to set.

Set(string)

Set data by str. The format is {0,1,2,3,...,15}

public Mat4d Set(string str)

Parameters

str string

src

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 BinaryWriter

The binary writer to write to

Operators

operator +(Mat4d, Mat4d)

Adds two matrices element-wise.

public static Mat4d operator +(Mat4d a, Mat4d b)

Parameters

a Mat4d

The first matrix.

b Mat4d

The second matrix.

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

a Mat4d

The matrix to divide.

b double

The scalar divisor.

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

a Mat4d

The first matrix.

b Mat4d

The second matrix.

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

a Mat4d

The first matrix.

b Mat4d

The second matrix.

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

m Mat4d

matrix

v DVec3d

point and normal

Returns

DVec3d

transformed point and normal

operator *(Mat4d, Mat4d)

Multiplies two matrices.

public static Mat4d operator *(Mat4d a, Mat4d b)

Parameters

a Mat4d

The first matrix.

b Mat4d

The second matrix.

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

a Mat4d

The transformation matrix.

b Vec3d

The vector to transform.

Returns

Vec3d

The transformed vector.

operator *(Mat4d, double)

Multiplies a matrix by a scalar value.

public static Mat4d operator *(Mat4d a, double s)

Parameters

a Mat4d

The matrix to multiply.

s double

The scalar value.

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

a Mat4d

The matrix to subtract from.

b Mat4d

The matrix to subtract.

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 Mat4d

The source matrix.

Returns

Mat4d

A new matrix with all elements negated.