struct

Chem::Spatial::Mat3

Inherits Struct / Value / Object

A 3x3 matrix in row-major order. This is useful for encoding linear maps such as scaling and rotation (see Transform).

Constructors

additive_identity

Returns the additive identity of the matrix (zero matrix).

Source
build

Creates a new Mat3, allocating an internal buffer, and yielding that buffer to the passed block.

This method is unsafe, but is usually used to initialize the buffer by other convenience methods without doing bounds check.

Source
diagonal(d1 : Number, d2 : Number, d3 : Number) : self

Returns a new matrix with the elements at the diagonal set to the given values.

Source
diagonal(value : Number) : self

Returns a new matrix with the diagonal set to value.

Source
from_io(io : IO, format : IO::ByteFormat) : self

Reads a matrix from io in the given format. See also: IO#read_bytes.

Source
identity

Returns the identity matrix.

Source
multiplicative_identity

Returns the multiplicative identity of the matrix (identity matrix).

Source
zero

Returns the zero matrix.

Source

Class methods

basis(i : Vec3, j : Vec3, k : Vec3) : Spatial::Mat3

Returns a matrix in column-major order representing the basis defined by the basis vectors.

Source

Instance methods

*(rhs : Number) : self

Returns the element-wise multiplication of the matrix by rhs.

Source
*(rhs : Vec3) : Vec3

Returns the multiplication of the matrix by rhs.

Source
*(rhs : NumberTriple) : self

Returns the row-wise multiplication of the matrix by rhs.

Source
*(rhs : self) : self

Returns the multiplication of the matrix by rhs.

Source
+(rhs : self) : self

Returns the element-wise addition of the matrix by rhs.

Source
-(rhs : self) : self

Returns the element-wise subtraction of the matrix by rhs.

Source
-

Returns the negation of the matrix.

Source
/(rhs : Number) : self

Returns the element-wise division of the matrix by rhs.

Source
[](row : Int, cols : Range(Nil, Nil)) : FloatTriple

Returns the row at row. Raises IndexError if row is out of bounds.

Source
[](rows : Range(Nil, Nil), col : Int) : FloatTriple

Returns the column at col. Raises IndexError if col is out of bounds.

Source
[](row : Int, col : Int) : Float64

Returns the element at the given row and column. Raises IndexError if indices are out of bounds.

Source
close_to?(rhs : self, delta : Float64 = Float64::EPSILON) : Bool

Returns true if the elements of the matrices are within delta from each other, else false.

Source
det

Returns the determinant of the matrix.

Source
inv

Returns the inverse matrix. Raises ArgumentError if the matrix is not invertible.

The inverse matrix is computed using the Cramer's rule, which states that inv(A) = 1 / det(A) * adj(A) provided that det(A) != 0.

Source
map

Returns a new matrix with the results of the passed block for each element in the matrix.

Source
to_a

Returns an array with all the elements of the matrix.

Source
to_io(io : IO, format : IO::ByteFormat = :system_endian) : Nil

Writes the binary representation of the matrix to io in the given format. See also IO#write_bytes.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
to_unsafe

Returns a pointer to the internal buffer where the matrix elements are stored.

Source
unsafe_fetch(row : Int, col : Int) : Float64

Returns the element at row and col, without doing any bounds check.

This should be called with row and col within 0...3. Use #[](i, j) and #[]?(i, j) instead for bounds checking and support for negative indexes.

NOTE: This method should only be directly invoked if you are absolutely sure row and col are within bounds, to avoid a bounds check for a small boost of performance.

Source
unsafe_fetch(index : Int) : Float64

Returns the element at the given index , without doing any bounds check.

NOTE: This method should only be directly invoked if you are absolutely sure the index is within bounds, to avoid a bounds check for a small boost of performance.

Source

Macros

[](*rows)

Returns a new 3x3 matrix using a matrix literal, i.e., three indexable (array or tuple) literals.

Mat3[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Source