module Geode::Matrix2x2Transforms2D(T)
Overview
Transformation that can be performed in two-dimensions with 2x2 matrices.
These methods produce a new matrix that has the operation performed on it. This:
matrix.rotate(45.degrees)
is effectively the same as:
matrix * Matrix2(Float64).rotate(45.degrees)
Direct including types
Defined in:
geode/matrices/transforms2d.crInstance Method Summary
-
#reflect_x : self
Returns a matrix that has a reflection transform applied.
-
#reflect_xy : self
Returns a matrix that has a scale transform applied.
-
#reflect_y : self
Returns a matrix that has a scale transform applied.
-
#rotate(angle : Number | Angle) : CommonMatrix
Returns a matrix that has a rotation transform applied.
-
#rotate180 : self
Returns a matrix that has a 180-degree rotation transform applied.
-
#rotate270 : self
Returns a matrix that has a 270-degree rotation transform applied.
-
#rotate90 : self
Returns a matrix that has a 90-degree rotation transform applied.
-
#scale(x, y) : CommonMatrix
Returns a matrix that has a scale transform applied.
-
#scale(amount : Number) : CommonMatrix
Returns a matrix that has a scale transform applied.
-
#shear_x(amount) : CommonMatrix
Returns a matrix that has a shear transform applied.
-
#shear_y(amount : T) : self
Returns a matrix that has a shear transform applied.
-
#translate(x, y) : CommonMatrix
Returns a matrix that has a translation applied.
Instance Method Detail
Returns a matrix that has a reflection transform applied.
Multiplying a 2D object by this matrix will reflect it along the x-axis.
vector = Vector2[5, 1]
matrix = Matrix2(Int32).identity.reflect_x
vector * matrix # => (-5, 1)
Returns a matrix that has a scale transform applied.
Multiplying a 2D object by this matrix will reflect it along the x and y-axis. This has the same effect as rotating 180 degrees.
vector = Vector2[5, 1]
matrix = Matrix2(Int32).identity.reflect_xy
vector * matrix # => (-5, -1)
See: #rotate270
Returns a matrix that has a scale transform applied.
Multiplying a 2D object by this matrix will reflect it along the y-axis.
vector = Vector2[5, 1]
matrix = Matrix2(Int32).identity.reflect_y
vector * matrix # => (5, -1)
Returns a matrix that has a rotation transform applied.
The angle must be a Number
in radians or an Angle
.
vector = Vector2[1, 1].normalize
matrix = Matrix2(Float64).identity.rotate(45.degrees)
vector * matrix # => (0.0, 1.0)
Returns a matrix that has a 180-degree rotation transform applied.
Multiplying a 2D object by this matrix will rotate it 180 degrees.
vector = Vector2[1, 1]
matrix = Matrix2(Int32).identity.rotate180
vector * matrix # => (-1, -1)
Returns a matrix that has a 270-degree rotation transform applied.
Multiplying a 2D object by this matrix will rotate it 270 degrees.
vector = Vector2[1, 1]
matrix = Matrix2(Int32).identity.rotate270
vector * matrix # => (-1, -1)
See: #reflect_xy
Returns a matrix that has a 90-degree rotation transform applied.
Multiplying a 2D object by this matrix will rotate it 90 degrees.
vector = Vector2[1, 1]
matrix = Matrix2(Int32).identity.rotate90
vector * matrix # => (-1, 1)
Returns a matrix that has a scale transform applied.
Non-uniformly scales an object (squash and stretch). Values for x and y smaller than 1 will shrink it. Values larger than 1 will enlarge it. Negative values will flip it.
vector = Vector2[2, 3]
matrix = Matrix2(Float64).identity.scale(1.5, 2)
vector * matrix # => (3.0, 6.0)
Returns a matrix that has a scale transform applied.
Uniformly scales an object. Multiplying a 2D 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 = Vector2[2, 3]
matrix = Matrix2(Int32).identity.scale(2)
vector * matrix # => (4, 6)
Returns a matrix that has a shear transform applied.
Multiplying a 2D object by this matrix will shear it along the x-axis.
vector = Vector2[2, 3]
matrix = Matrix2(Int32).identity.shear_x(2)
vector * matrix # => (8, 3)
Returns a matrix that has a shear transform applied.
Multiplying a 2D object by this matrix will shear it along the y-axis.
vector = Vector2[2, 3]
matrix = Matrix2(Int32).identity.shear_y(2)
vector * matrix # => (2, 7)
Returns a matrix that has a translation applied.
Returns a 3x3 matrix.
vector = Vector3[3, 5, 1]
matrix = Matrix2(Int32).identity.translate(1, 2)
vector * matrix # => (4, 7, 1)