Table of Contents

Struct Fixed3x3

Namespace
FixedMathSharp
Assembly
FixedMathSharp.dll

Represents a 3x3 matrix used for linear transformations in 2D and 3D space, such as rotation, scaling, and shearing.

[MemoryPackable(GenerateType.Object)]
public struct Fixed3x3 : IEquatable<Fixed3x3>, ISpanFormattable, IFormattable, IMemoryPackable<Fixed3x3>, IMemoryPackFormatterRegister
Implements
IMemoryPackable<Fixed3x3>
IMemoryPackFormatterRegister
Inherited Members
Extension Methods

Remarks

A 3x3 matrix handles only linear transformations and is typically used when translation is not needed. It operates on directions, orientations, and vectors within a given space without affecting position. This matrix is more lightweight compared to a 4x4 matrix, making it ideal when translation and perspective are unnecessary.

Use Cases:

  • Rotating or scaling objects around the origin in 2D and 3D space.
  • Transforming vectors and normals (e.g., in lighting calculations).
  • Used in physics engines for inertia tensors or to represent local orientations.
  • Useful when optimizing transformations, as it omits the overhead of translation and perspective.

Constructors

Fixed3x3(Fixed64, Fixed64, Fixed64, Fixed64, Fixed64, Fixed64, Fixed64, Fixed64, Fixed64)

Initializes a new FixedMatrix3x3 with the specified elements.

public Fixed3x3(Fixed64 m11, Fixed64 m12, Fixed64 m13, Fixed64 m21, Fixed64 m22, Fixed64 m23, Fixed64 m31, Fixed64 m32, Fixed64 m33)

Parameters

m11 Fixed64
m12 Fixed64
m13 Fixed64
m21 Fixed64
m22 Fixed64
m23 Fixed64
m31 Fixed64
m32 Fixed64
m33 Fixed64

Fixed3x3(Vector3d, Vector3d, Vector3d)

Initializes a new FixedMatrix3x3 using three Vector3d values representing the rows.

public Fixed3x3(Vector3d m11_m12_m13, Vector3d m21_m22_m23, Vector3d m31_m32_m33)

Parameters

m11_m12_m13 Vector3d
m21_m22_m23 Vector3d
m31_m32_m33 Vector3d

Fields

Identity

Returns the identity matrix (no scaling, rotation, or translation).

public static readonly Fixed3x3 Identity

Field Value

Fixed3x3

M11

Represents the element in the first row and first column of the matrix.

[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 M11

Field Value

Fixed64

M12

Represents the element in the first row and second column of the matrix.

[JsonInclude]
[MemoryPackOrder(1)]
public Fixed64 M12

Field Value

Fixed64

M13

Represents the element in the first row and third column of the matrix.

[JsonInclude]
[MemoryPackOrder(2)]
public Fixed64 M13

Field Value

Fixed64

M21

Represents the element in the second row and first column of the matrix.

[JsonInclude]
[MemoryPackOrder(3)]
public Fixed64 M21

Field Value

Fixed64

M22

Represents the element in the second row and second column of the matrix.

[JsonInclude]
[MemoryPackOrder(4)]
public Fixed64 M22

Field Value

Fixed64

M23

Represents the element in the second row and third column of the matrix.

[JsonInclude]
[MemoryPackOrder(5)]
public Fixed64 M23

Field Value

Fixed64

M31

Represents the element in the third row and first column of the matrix.

[JsonInclude]
[MemoryPackOrder(6)]
public Fixed64 M31

Field Value

Fixed64

M32

Represents the element in the third row and second column of the matrix.

[JsonInclude]
[MemoryPackOrder(7)]
public Fixed64 M32

Field Value

Fixed64

M33

Represents the element in the third row and third column of the matrix.

[JsonInclude]
[MemoryPackOrder(8)]
public Fixed64 M33

Field Value

Fixed64

Zero

Returns a matrix with all elements set to zero.

public static readonly Fixed3x3 Zero

Field Value

Fixed3x3

Properties

this[int]

Gets or sets the matrix element at the specified index.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 this[int index] { get; set; }

Parameters

index int

The zero-based index of the matrix element to get or set. Valid values are 0, 1, 2, 4, 5, 6, 8, 9, and 10.

Property Value

Fixed64

The matrix element at the specified index.

Remarks

The mapping between indices and matrix elements is non-sequential. Ensure that the index corresponds to a valid matrix element.

Exceptions

IndexOutOfRangeException

Thrown when the specified index is not one of the valid matrix element indices.

Methods

CreateBarycentricProductSums(Vector3d, Vector3d, Vector3d)

Creates a symmetric matrix containing second-order barycentric product sums for three vectors.

public static Fixed3x3 CreateBarycentricProductSums(Vector3d a, Vector3d b, Vector3d c)

Parameters

a Vector3d
b Vector3d
c Vector3d

Returns

Fixed3x3

Remarks

The diagonal contains squared component sums, and the off-diagonal elements contain cross-component sums.

CreateRotationX(Fixed64)

Creates a 3x3 matrix representing a rotation around the X-axis.

public static Fixed3x3 CreateRotationX(Fixed64 angle)

Parameters

angle Fixed64

The angle of rotation in radians.

Returns

Fixed3x3

A 3x3 rotation matrix.

CreateRotationY(Fixed64)

Creates a 3x3 matrix representing a rotation around the Y-axis.

public static Fixed3x3 CreateRotationY(Fixed64 angle)

Parameters

angle Fixed64

The angle of rotation in radians.

Returns

Fixed3x3

A 3x3 rotation matrix.

CreateRotationZ(Fixed64)

Creates a 3x3 matrix representing a rotation around the Z-axis.

public static Fixed3x3 CreateRotationZ(Fixed64 angle)

Parameters

angle Fixed64

The angle of rotation in radians.

Returns

Fixed3x3

A 3x3 rotation matrix.

CreateScale(Fixed64)

Creates a uniform scaling matrix with the same scale factor on all axes.

public static Fixed3x3 CreateScale(Fixed64 scaleFactor)

Parameters

scaleFactor Fixed64

The uniform scale factor.

Returns

Fixed3x3

A 3x3 scaling matrix with uniform scaling.

CreateScale(Vector3d)

Creates a scaling matrix that applies a uniform or non-uniform scale transformation.

public static Fixed3x3 CreateScale(Vector3d scale)

Parameters

scale Vector3d

The scale factors along the X, Y, and Z axes.

Returns

Fixed3x3

A 3x3 scaling matrix.

CreateShear(Fixed64, Fixed64, Fixed64)

Creates a 3x3 shear matrix.

public static Fixed3x3 CreateShear(Fixed64 shX, Fixed64 shY, Fixed64 shZ)

Parameters

shX Fixed64

Shear factor along the X-axis.

shY Fixed64

Shear factor along the Y-axis.

shZ Fixed64

Shear factor along the Z-axis.

Returns

Fixed3x3

A 3x3 shear matrix.

Equals(Fixed3x3)

public bool Equals(Fixed3x3 other)

Parameters

other Fixed3x3

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

ExtractLossyScale(Fixed3x3)

Extracts canonical signed lossy scale from the matrix basis rows.

public static Vector3d ExtractLossyScale(Fixed3x3 matrix)

Parameters

matrix Fixed3x3

Returns

Vector3d

Remarks

A reflected basis assigns its one recoverable negative sign to X.

ExtractScaleMagnitudes(Fixed3x3)

Extracts the unsigned magnitudes of the matrix basis rows.

public static Vector3d ExtractScaleMagnitudes(Fixed3x3 matrix)

Parameters

matrix Fixed3x3

Returns

Vector3d

The nonnegative basis magnitudes along X, Y, and Z.

GetDeterminant()

Calculates the determinant of a 3x3 matrix.

public Fixed64 GetDeterminant()

Returns

Fixed64

GetHashCode()

public override int GetHashCode()

Returns

int

GetNormalized(Fixed3x3)

Normalizes the basis vectors of a 3x3 matrix to ensure they are orthogonal and unit length.

public static Fixed3x3 GetNormalized(Fixed3x3 matrix)

Parameters

matrix Fixed3x3

Returns

Fixed3x3

Remarks

This method recalculates and normalizes the X, Y, and Z basis vectors of the matrix to avoid numerical drift that can occur after multiple transformations. It also ensures that the Z-axis is recomputed to maintain orthogonality by taking the cross-product of the normalized X and Y axes.

Use Cases:

  • Ensuring stability and correctness after repeated transformations involving rotation and scaling.
  • Useful in physics calculations where orthogonal matrices are required (e.g., inertia tensors or rotations).

InverseTransformDirection(Fixed3x3, Vector3d)

Transforms a direction from world space into the local space of the matrix. Ignores translation.

public static Vector3d InverseTransformDirection(Fixed3x3 matrix, Vector3d direction)

Parameters

matrix Fixed3x3

The transformation matrix.

direction Vector3d

The world-space direction.

Returns

Vector3d

The transformed local-space direction.

Invert(Fixed3x3, out Fixed3x3?)

Attempts to invert the matrix. If the determinant is zero, returns false and sets result to null.

public static bool Invert(Fixed3x3 matrix, out Fixed3x3? result)

Parameters

matrix Fixed3x3
result Fixed3x3?

Returns

bool

InvertDiagonal()

Inverts the diagonal elements of the matrix.

public Fixed3x3 InvertDiagonal()

Returns

Fixed3x3

Remarks

protects against the case where you would have an infinite value on the diagonal, which would cause problems in subsequent computations. If m00 or m22 are zero, handle that as a special case and manually set the inverse to zero, since for a theoretical object with no inertia along those axes, it would be impossible to impart a rotation in those directions

bear in mind that having a zero on the inertia tensor's diagonal isn't generally valid for real, 3-dimensional objects (unless they are "infinitely thin" along one axis), so if you end up with such a tensor, it's a sign that something else might be wrong in your setup.

Lerp(Fixed3x3, Fixed3x3, Fixed64)

Linearly interpolates between two matrices.

public static Fixed3x3 Lerp(Fixed3x3 a, Fixed3x3 b, Fixed64 t)

Parameters

a Fixed3x3
b Fixed3x3
t Fixed64

Returns

Fixed3x3

NormalizeInPlace()

Normalizes the basis vectors of a 3x3 matrix to ensure they are orthogonal and unit length.

public Fixed3x3 NormalizeInPlace()

Returns

Fixed3x3

Remarks

This method recalculates and normalizes the X, Y, and Z basis vectors of the matrix to avoid numerical drift that can occur after multiple transformations. It also ensures that the Z-axis is recomputed to maintain orthogonality by taking the cross-product of the normalized X and Y axes.

Use Cases:

  • Ensuring stability and correctness after repeated transformations involving rotation and scaling.
  • Useful in physics calculations where orthogonal matrices are required (e.g., inertia tensors or rotations).

ToString()

Returns a string that represents the current matrix in a readable format.

public override string ToString()

Returns

string

A string containing the matrix elements formatted as "[m00, m01, m02; m10, m11, m12; m20, m21, m22]".

Remarks

This method is useful for debugging or logging the contents of the matrix. The returned string lists the matrix elements in row-major order.

ToString(string?, IFormatProvider?)

Returns a string that represents the current matrix in a readable format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

TransformDirection(Fixed3x3, Vector3d)

Transforms a direction vector from local space to world space using this transformation matrix. Ignores translation.

public static Vector3d TransformDirection(Fixed3x3 matrix, Vector3d direction)

Parameters

matrix Fixed3x3

The transformation matrix.

direction Vector3d

The local-space direction vector.

Returns

Vector3d

The transformed direction in world space.

Remarks

FixedMathSharp applies matrices using a row-vector convention: direction * matrix.

Transpose(Fixed3x3)

Transposes the matrix (swaps rows and columns).

public static Fixed3x3 Transpose(Fixed3x3 matrix)

Parameters

matrix Fixed3x3

Returns

Fixed3x3

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Formats this matrix into the provided destination buffer.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

TryTransformDirection(Fixed3x3, Vector3d, out Vector3d)

Attempts to transform a direction with one final round-half-to-even conversion per component and no intermediate saturation.

public static bool TryTransformDirection(Fixed3x3 matrix, Vector3d direction, out Vector3d result)

Parameters

matrix Fixed3x3
direction Vector3d
result Vector3d

Returns

bool

Operators

operator +(Fixed3x3, Fixed3x3)

Adds two Fixed3x3 matrices element-wise.

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

Parameters

a Fixed3x3

The first matrix to add.

b Fixed3x3

The second matrix to add.

Returns

Fixed3x3

A Fixed3x3 matrix whose elements are the sums of the corresponding elements of the input matrices.

operator /(Fixed3x3, int)

Divides each element of the specified matrix by the given scalar value.

public static Fixed3x3 operator /(Fixed3x3 a, int divisor)

Parameters

a Fixed3x3

The matrix whose elements are to be divided.

divisor int

The scalar value by which to divide each element of the matrix.

Returns

Fixed3x3

A new Fixed3x3 matrix whose elements are the result of dividing the corresponding elements of the input matrix by the specified scalar.

Remarks

Division is performed element-wise. The result may lose precision if the divisor does not evenly divide the matrix elements.

operator ==(Fixed3x3, Fixed3x3)

Determines whether two Fixed3x3 instances are equal.

public static bool operator ==(Fixed3x3 left, Fixed3x3 right)

Parameters

left Fixed3x3

The first Fixed3x3 instance to compare.

right Fixed3x3

The second Fixed3x3 instance to compare.

Returns

bool

true if the specified Fixed3x3 instances are equal; otherwise, false.

operator !=(Fixed3x3, Fixed3x3)

Determines whether two Fixed3x3 instances are not equal.

public static bool operator !=(Fixed3x3 left, Fixed3x3 right)

Parameters

left Fixed3x3

The first Fixed3x3 instance to compare.

right Fixed3x3

The second Fixed3x3 instance to compare.

Returns

bool

true if the specified Fixed3x3 instances are not equal; otherwise, false.

operator *(Fixed3x3, Fixed3x3)

Performs matrix multiplication on two 3x3 matrices.

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

Parameters

a Fixed3x3

The first matrix to multiply.

b Fixed3x3

The second matrix to multiply.

Returns

Fixed3x3

A new Fixed3x3 instance that is the product of the two input matrices.

Remarks

Matrix multiplication is not commutative; the order of operands affects the result.

operator *(Fixed3x3, Fixed64)

Multiplies each element of the specified matrix by the given scalar value.

public static Fixed3x3 operator *(Fixed3x3 a, Fixed64 scalar)

Parameters

a Fixed3x3

The matrix whose elements are to be multiplied.

scalar Fixed64

The scalar value by which to multiply each element of the matrix.

Returns

Fixed3x3

A new Fixed3x3 matrix whose elements are the result of multiplying each element of the input matrix by the scalar value.

operator *(Fixed64, Fixed3x3)

Multiplies each element of the specified matrix by the given scalar value.

public static Fixed3x3 operator *(Fixed64 scalar, Fixed3x3 a)

Parameters

scalar Fixed64

The scalar value by which to multiply each element of the matrix.

a Fixed3x3

The matrix whose elements are to be multiplied.

Returns

Fixed3x3

A new Fixed3x3 matrix whose elements are the result of multiplying each element of the input matrix by the scalar value.

operator -(Fixed3x3, Fixed3x3)

Subtracts each corresponding element of one Fixed3x3 matrix from another.

public static Fixed3x3 operator -(Fixed3x3 a, Fixed3x3 b)

Parameters

a Fixed3x3

The first Fixed3x3 matrix (the minuend).

b Fixed3x3

The second Fixed3x3 matrix (the subtrahend).

Returns

Fixed3x3

A Fixed3x3 matrix whose elements are the result of subtracting each element of parameter b from the corresponding element of parameter a.

operator -(Fixed3x3)

Negates all elements of the matrix.

public static Fixed3x3 operator -(Fixed3x3 a)

Parameters

a Fixed3x3

Returns

Fixed3x3