struct Chem::Spatial::Mat3

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.cr

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.additive_identity : self #

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


[View source]
def self.build(& : Pointer(Float64) -> ) : self #

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.


[View source]
def self.diagonal(d1 : Number, d2 : Number, d3 : Number) : self #

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


[View source]
def self.diagonal(value : Number) : self #

Returns a new matrix with the diagonal set to value.


[View source]
def self.from_io(io : IO, format : IO::ByteFormat) : self #

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


[View source]
def self.identity : self #

Returns the identity matrix.


[View source]
def self.multiplicative_identity : self #

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


[View source]
def self.zero : self #

Returns the zero matrix.


[View source]

Class Method Detail

def self.basis(i : Vec3, j : Vec3, k : Vec3) : Spatial::Mat3 #

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


[View source]

Instance Method Detail

def *(rhs : Number) : self #

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


[View source]
def *(rhs : Vec3) : Vec3 #

Returns the multiplication of the matrix by rhs.


[View source]
def *(rhs : NumberTriple) : self #

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


[View source]
def *(rhs : self) : self #

Returns the multiplication of the matrix by rhs.


[View source]
def +(rhs : self) : self #

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


[View source]
def -(rhs : self) : self #

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


[View source]
def - : self #

Returns the negation of the matrix.


[View source]
def /(rhs : Number) : self #

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


[View source]
def [](row : Int, cols : Range(Nil, Nil)) : FloatTriple #

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


[View source]
def [](rows : Range(Nil, Nil), col : Int) : FloatTriple #

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


[View source]
def [](row : Int, col : Int) : Float64 #

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


[View source]
def 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.


[View source]
def det : Float64 #

Returns the determinant of the matrix.


[View source]
def inv : self #

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.


[View source]
def map(& : Float64 -> Float64) : self #

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


[View source]
def to_a : Array(Float64) #

Returns an array with all the elements of the matrix.


[View source]
def 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.


[View source]
def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]
def to_unsafe : Pointer(Float64) #

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


[View source]
def 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.


[View source]
def 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.


[View source]

Macro Detail

macro [](*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]]

[View source]