Table of Contents

Struct mat4d_t

Namespace
Hi.Geom
Assembly
HiGeom.dll

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

src AxisAngle4d

src

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

src AxisAngle4d

src

pivot vec3d_t

rotation pivot

mat4d_t(mat4d_t)

copy constructor

public mat4d_t(mat4d_t src)

Parameters

src mat4d_t

src

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

trans vec3d_t

translation

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

v0 vec3d_t

The first vector.

v1 vec3d_t

The second vector.

v2 vec3d_t

The third vector.

indexFlag mat4d_t.IndexFlag

Determines 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

axis vec3d_t

rotation axis

rad double

radian

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

axis vec3d_t

rotate axis

rad double

angle

pivot vec3d_t

rotate pivot

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

src IEnumerable<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

scale double

scale

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

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_t(double[])

Ctor by a copy of the first 16 elements of src.

public mat4d_t(double[] src)

Parameters

src double[]

src

mat4d_t(BinaryReader)

Ctor by the 16 doubles read from reader.

public mat4d_t(BinaryReader reader)

Parameters

reader BinaryReader

reader

mat4d_t(ReadOnlySpan<double>)

Ctor by a copy of the 16 elements of src.

public mat4d_t(ReadOnlySpan<double> src)

Parameters

src ReadOnlySpan<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

str string

src

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

mat4d_t.Elements

Properties

AxialNormal

vec3d_t on 2th row. It usually is tool normal.

public readonly vec3d_t AxialNormal { get; }

Property Value

vec3d_t

AxisAngle

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

public readonly AxisAngle4d AxisAngle { get; }

Property Value

AxisAngle4d

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

mat4d_t

IsAllNaN

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

public readonly bool IsAllNaN { get; }

Property Value

bool

IsFinite

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

public readonly bool IsFinite { get; }

Property Value

bool

IsRotate

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

public readonly bool IsRotate { get; }

Property Value

bool

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

i int

The row index (0-based).

j int

The column index (0-based).

Property Value

double

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

double

NaN

Generate matrix that all elements are nan.

public static mat4d_t NaN { get; }

Property Value

mat4d_t

NativeByteSize

Byte size of the struct as core.dll sees it: sizeof(mat4d_t), sixteen doubles.

public static int NativeByteSize { get; }

Property Value

int

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

mat4d_t

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

dvec3d_t

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

vec3d_t

TransposeMat

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

public readonly mat4d_t TransposeMat { get; }

Property Value

mat4d_t

Zero

Generate zero matrix.

public static mat4d_t Zero { get; }

Property Value

mat4d_t

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

i int

The row index (0-based).

j int

The column index (0-based).

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

other mat4d_t

An object to compare with this object.

Returns

bool

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

Equals(object)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

other mat4d_t

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_t FilledMat(double v)

Parameters

v double

The 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

floatingZeroTolerance double

The 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

scale double

The 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

tolerance double

The 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

transformingFunc Func<double, double>

The function to apply to each matrix element.

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

reader BinaryReader

reader

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

writer BinaryWriter

The 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

a mat4d_t

The first matrix.

b mat4d_t

The second matrix.

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

a mat4d_t

The matrix to divide.

b double

The scalar divisor.

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

a mat4d_t

The first matrix.

b mat4d_t

The second matrix.

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

a mat4d_t

The first matrix.

b mat4d_t

The second matrix.

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

m mat4d_t

matrix

v dvec3d_t

point and normal

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

a mat4d_t

The first matrix.

b mat4d_t

The second matrix.

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

a mat4d_t

The transformation matrix.

b vec3d_t

The vector to transform.

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

a mat4d_t

The matrix to multiply.

s double

The scalar value.

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

a mat4d_t

The matrix to subtract from.

b mat4d_t

The matrix to subtract.

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

src mat4d_t

The source matrix.

Returns

mat4d_t

A new matrix with all elements negated.