struct Chem::Spatial::Mat3
- Chem::Spatial::Mat3
- Struct
- Value
- Object
Overview
A 3x3 matrix in row-major order. This is useful for encoding linear
maps such as scaling and rotation (see Transform
).
Defined in:
chem/spatial/mat3.crConstructors
-
.additive_identity : self
Returns the additive identity of the matrix (zero matrix).
-
.build(& : Pointer(Float64) -> ) : self
Creates a new
Mat3
, allocating an internal buffer, and yielding that buffer to the passed block. -
.diagonal(d1 : Number, d2 : Number, d3 : Number) : self
Returns a new matrix with the elements at the diagonal set to the given values.
-
.diagonal(value : Number) : self
Returns a new matrix with the diagonal set to value.
-
.from_io(io : IO, format : IO::ByteFormat) : self
Reads a matrix from io in the given format.
-
.identity : self
Returns the identity matrix.
-
.multiplicative_identity : self
Returns the multiplicative identity of the matrix (identity matrix).
-
.zero : self
Returns the zero matrix.
Class Method Summary
-
.basis(i : Vec3, j : Vec3, k : Vec3) : Spatial::Mat3
Returns a matrix in column-major order representing the basis defined by the basis vectors.
Instance Method Summary
-
#*(rhs : Number) : self
Returns the element-wise multiplication of the matrix by rhs.
-
#*(rhs : Vec3) : Vec3
Returns the multiplication of the matrix by rhs.
-
#*(rhs : NumberTriple) : self
Returns the row-wise multiplication of the matrix by rhs.
-
#*(rhs : self) : self
Returns the multiplication of the matrix by rhs.
-
#+(rhs : self) : self
Returns the element-wise addition of the matrix by rhs.
-
#-(rhs : self) : self
Returns the element-wise subtraction of the matrix by rhs.
-
#- : self
Returns the negation of the matrix.
-
#/(rhs : Number) : self
Returns the element-wise division of the matrix by rhs.
-
#[](row : Int, cols : Range(Nil, Nil)) : FloatTriple
Returns the row at row.
-
#[](rows : Range(Nil, Nil), col : Int) : FloatTriple
Returns the column at col.
-
#[](row : Int, col : Int) : Float64
Returns the element at the given row and column.
-
#close_to?(rhs : self, delta : Float64 = Float64::EPSILON) : Bool
Returns
true
if the elements of the matrices are within delta from each other, elsefalse
. -
#det : Float64
Returns the determinant of the matrix.
-
#inv : self
Returns the inverse matrix.
-
#map(& : Float64 -> Float64) : self
Returns a new matrix with the results of the passed block for each element in the matrix.
-
#to_a : Array(Float64)
Returns an array with all the elements of the matrix.
-
#to_io(io : IO, format : IO::ByteFormat = :system_endian) : Nil
Writes the binary representation of the matrix to io in the given format.
-
#to_s(io : IO) : Nil
Same as
#inspect(io)
. -
#to_unsafe : Pointer(Float64)
Returns a pointer to the internal buffer where the matrix elements are stored.
-
#unsafe_fetch(row : Int, col : Int) : Float64
Returns the element at row and col, without doing any bounds check.
-
#unsafe_fetch(index : Int) : Float64
Returns the element at the given index , without doing any bounds check.
Macro Summary
-
[](*rows)
Returns a new 3x3 matrix using a matrix literal, i.e., three indexable (array or tuple) literals.
Constructor Detail
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.
Returns a new matrix with the elements at the diagonal set to the given values.
Returns a new matrix with the diagonal set to value.
Reads a matrix from io in the given format. See also:
IO#read_bytes
.
Returns the multiplicative identity of the matrix (identity matrix).
Class Method Detail
Returns a matrix in column-major order representing the basis defined by the basis vectors.
Instance Method Detail
Returns the element-wise multiplication of the matrix by rhs.
Returns the row-wise multiplication of the matrix by rhs.
Returns the row at row. Raises IndexError
if row is out of
bounds.
Returns the column at col. Raises IndexError
if col is out
of bounds.
Returns the element at the given row and column. Raises
IndexError
if indices are out of bounds.
Returns true
if the elements of the matrices are within delta
from each other, else false
.
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
.
Returns a new matrix with the results of the passed block for each element in the matrix.
Writes the binary representation of the matrix to io in the
given format. See also IO#write_bytes
.
Returns a pointer to the internal buffer where the matrix elements are stored.
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.
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.
Macro Detail
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]]