module Geode::Matrix3x3Transforms2DConstructors(T)

Overview

Transformation that can be performed in two-dimensions with 3x3 matrices.

Multiplying a 2D object by the matrices produced by these methods will apply the operation to the object. The matrix must be on the right-hand-side of the multiplication operation.

object * matrix

Matrix multiplication is not commutative, therefore the ordering matters. If it's desired to have the matrix on the left-hand-side, transpose it before multiplying.

matrix.transpose * object

To combine multiple operations, multiply the matrices from these methods together.

This module should be extended.

Defined in:

geode/matrices/transforms2d.cr

Instance Method Summary

Instance Method Detail

def reflect_x : self #

Creates a 2D reflecting matrix with space for translation.

Multiplying an object by this matrix will reflect it along the x-axis.

vector = Vector3[5, 1, 1]
matrix = Matrix3(Int32).reflect_x
vector * matrix # => (-5, 1, 1)

[View source]
def reflect_xy : self #

Creates a 2D reflective matrix with space for translation.

Multiplying an object by this matrix will reflect it along the x and y-axis. This has the same effect as rotating 180 degrees.

vector = Vector3[5, 1, 1]
matrix = Matrix3(Int32).reflect_xy
vector * matrix # => (-5, -1, 1)

See: #rotate270


[View source]
def reflect_y : self #

Creates a 2D reflective matrix with space for translation.

Multiplying an object by this matrix will reflect it along the y-axis.

vector = Vector3[5, 1, 1]
matrix = Matrix3(Int32).reflect_y
vector * matrix # => (5, -1, 1)

[View source]
def rotate(angle : Number | Angle) : self #

Creates a 2D rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it the specified amount. The angle must be a Number in radians or an Angle.

vector = Vector3[3 / 5, 4 / 5, 1.0]
matrix = Matrix3(Float64).rotate(90.degrees)
vector * matrix # => (-0.8, 0.6, 1.0)

[View source]
def rotate180 : self #

Creates a 2D 180-degree rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it 180 degrees.

vector = Vector3[1, 1, 1]
matrix = Matrix3(Int32).rotate180
vector * matrix # => (-1, -1, 1)

[View source]
def rotate270 : self #

Creates a 2D 270-degree rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it 270 degrees.

vector = Vector3[1, 1, 1]
matrix = Matrix3(Int32).rotate270
vector * matrix # => (1, 1, 1)

See: #reflect_xy


[View source]
def rotate90 : self #

Creates a 2D 90-degree rotation matrix with space for translation.

Multiplying an object by this matrix will rotate it 90 degrees.

vector = Vector3[1, 1, 1]
matrix = Matrix3(Int32).rotate90
vector * matrix # => (-1, 1, 1)

[View source]
def scale(x : T, y : T) : self #

Creates a 2D scaling matrix with space for translation.

Non-uniformly scales an object (squash and stretch). Multiplying an object by this matrix will scale it by x amount along the x-axis and y amount along the y-axis. Values for x and y smaller than 1 will shrink it. Values larger than 1 will enlarge it. Negative values will flip it.

vector = Vector3[2, 3, 1]
matrix = Matrix3(Float64).scale(1.5, 2)
vector * matrix # => (3.0, 6.0, 1.0)

[View source]
def scale2(amount : T) : self #

Creates a 2D scaling matrix with space for translation.

Uniformly scales an object. Multiplying an object by this matrix will scale it by amount. Values for amount smaller than 1 will shrink it. Values larger than 1 will enlarge it. Negative values will flip it.

vector = Vector3[2, 3, 1]
matrix = Matrix3(Int32).scale2(2)
vector * matrix # => (4, 6, 1)

[View source]
def shear_x(amount : T) : self #

Creates a 2D shearing matrix with space for translation.

Multiplying an object by this matrix will shear it along the x-axis.

vector = Vector3[2, 3, 1]
matrix = Matrix3(Int32).shear_x(2)
vector * matrix # => (8, 3, 1)

[View source]
def shear_y(amount : T) : self #

Creates a 2D shearing matrix with space for translation.

Multiplying an object by this matrix will shear it along the y-axis.

vector = Vector3[2, 3, 1]
matrix = Matrix3(Int32).shear_y(2)
vector * matrix # => (2, 7, 1)

[View source]
def translate(x : T, y : T) : self #

Creates a 2D transform matrix with space for translation.

vector = Vector3[3, 5, 1]
matrix = Matrix3(Int32).translate(1, 2)
vector * matrix # => (4, 7, 1)

[View source]