Matrix3x2
public struct Matrix3x2<Scalar> : Hashable, CustomStringConvertible where Scalar : ElementaryFunctions, Scalar : FloatingPoint
extension Matrix3x2: Encodable where Scalar: Encodable
extension Matrix3x2: Decodable where Scalar: Decodable
Plain 3-row 2-column Matrix for 2D affine transformations with floating-point components.
-
Declaration
Swift
public typealias Vector = Vector2<Scalar> -
Gets the identity matrix.
Declaration
Swift
public static var identity: `Self` { get } -
Element (1,1)
Declaration
Swift
public let m11: Scalar -
Element (1,2)
Declaration
Swift
public let m12: Scalar -
Element (2,1)
Declaration
Swift
public let m21: Scalar -
Element (2,2)
Declaration
Swift
public let m22: Scalar -
Element (3,1)
Declaration
Swift
public let m31: Scalar -
Element (3,2)
Declaration
Swift
public let m32: Scalar -
Gets the first row in the matrix; that is M11 and M12.
Declaration
Swift
public var row1: [Scalar] { get } -
Gets the second row in the matrix; that is M21 and M22.
Declaration
Swift
public var row2: [Scalar] { get } -
Gets the third row in the matrix; that is M31 and M32.
Declaration
Swift
public var row3: [Scalar] { get } -
Gets the first column in the matrix; that is M11, M21, and M31.
Declaration
Swift
public var column1: [Scalar] { get } -
Gets the second column in the matrix; that is M12, M22, and M32.
Declaration
Swift
public var column2: [Scalar] { get } -
Gets the translation of the matrix; that is M31 and M32.
Declaration
Swift
public var translationVector: Vector { get } -
Gets the scale of the matrix; that is M11 and M22.
Declaration
Swift
public var scaleVector: Vector { get } -
Gets a value indicating whether this instance is an identity matrix.
trueif this instance is an identity matrix; otherwise,false.Declaration
Swift
public var isIdentity: Bool { get } -
Gets or sets the component at the specified index.
Declaration
Swift
public subscript(index index: Int) -> Scalar { get }Parameters
indexThe zero-based index of the component to access.
Return Value
The value of the component at the specified index.
-
Gets or sets the component at the specified index.
Precondition
row >= 0 && row <= 2 && column >= 0 && column <= 1Declaration
Swift
public subscript(column column: Int, row row: Int) -> Scalar { get }Parameters
rowThe row of the matrix to access.
columnThe column of the matrix to access.
Return Value
The value of the component at the specified index.
-
Returns a
Stringthat represents this instance.Declaration
Swift
public var description: String { get } -
Initializes a new instance of the
Matrix3x2struct.Declaration
Swift
public init(value: Scalar)Parameters
valueThe value that will be assigned to all components.
-
Initializes a new instance of the
Matrix3x2struct.Declaration
Swift
public init( m11: Scalar, m12: Scalar, m21: Scalar, m22: Scalar, m31: Scalar, m32: Scalar )Parameters
m11The value to assign at row 1 column 1 of the matrix.
m12The value to assign at row 1 column 2 of the matrix.
m21The value to assign at row 2 column 1 of the matrix.
m22The value to assign at row 2 column 2 of the matrix.
m31The value to assign at row 3 column 1 of the matrix.
m32The value to assign at row 3 column 2 of the matrix.
-
Initializes a new instance of the
Matrix3x2struct.Precondition
values.count == 6Declaration
Swift
public init(values: [Scalar])Parameters
valuesThe values to assign to the components of the matrix. This must be an array with six elements, otherwise a runtime error is thrown
-
Creates an array containing the elements of the matrix.
Declaration
Swift
public func toArray() -> [Scalar]Return Value
A six-element array containing the components of the matrix.
-
Calculates the determinant of this matrix.
Declaration
Swift
public func determinant() -> ScalarReturn Value
Result of the determinant.
-
Calculates the inverse of this matrix instance.
Declaration
Swift
public func inverted() -> Matrix3x2 -
Determines the sum of two matrices.
Declaration
Swift
public static func add( _ left: Matrix3x2, _ right: Matrix3x2 ) -> Matrix3x2Parameters
leftThe first matrix to add.
rightThe second matrix to add.
-
Determines the difference between two matrices.
Declaration
Swift
public static func subtract( _ left: Matrix3x2, _ right: Matrix3x2 ) -> Matrix3x2Parameters
leftThe first matrix to subtract.
rightThe second matrix to subtract.
-
Scales a matrix by the given value.
Declaration
Swift
public static func multiply( _ left: Matrix3x2, _ right: Scalar ) -> Matrix3x2Parameters
leftThe matrix to scale.
rightThe amount by which to scale.
-
Determines the product of two matrices.
Declaration
Swift
public static func multiply( _ left: Matrix3x2, _ right: Matrix3x2 ) -> Matrix3x2Parameters
leftThe first matrix to multiply.
rightThe second matrix to multiply.
-
Scales a matrix by the given value.
Declaration
Swift
public static func divide(_ left: Matrix3x2, _ right: Scalar) -> Matrix3x2Parameters
leftThe matrix to scale.
rightThe amount by which to scale. Must be greater than zero
-
Determines the quotient of two matrices.
Declaration
Swift
public static func divide( _ left: Matrix3x2, _ right: Matrix3x2 ) -> Matrix3x2Parameters
leftThe first matrix to divide.
rightThe second matrix to divide.
-
Negates a matrix.
Declaration
Swift
public static func negate(_ value: Matrix3x2) -> Matrix3x2Parameters
valueThe matrix to be negated.
-
Performs a linear interpolation between two matrices.
Passing
amounta value of 0 will causestartto be returned; a value of 1 will causeendto be returned.Declaration
Swift
public static func lerp( start: Matrix3x2, end: Matrix3x2, amount: Scalar ) -> Matrix3x2Parameters
startStart matrix.
endEnd matrix.
amountValue between 0 and 1 indicating the weight of
end. -
Creates a matrix that scales along the x-axis and y-axis.
Declaration
Swift
public static func scaling(scale: Vector) -> Matrix3x2Parameters
scaleScaling factor for both axes.
-
Creates a matrix that scales along the x-axis and y-axis.
Declaration
Swift
public static func scaling(x: Scalar, y: Scalar) -> Matrix3x2Parameters
xScaling factor that is applied along the x-axis.
yScaling factor that is applied along the y-axis.
-
Creates a matrix that uniformly scales along both axes.
Declaration
Swift
public static func scaling(scale: Scalar) -> Matrix3x2Parameters
scaleThe uniform scale that is applied along both axes.
-
Creates a matrix that is scaling from a specified center.
Declaration
Swift
public static func scaling(x: Scalar, y: Scalar, center: Vector) -> Matrix3x2Parameters
xScaling factor that is applied along the x-axis.
yScaling factor that is applied along the y-axis.
centerThe center of the scaling.
-
Creates a matrix that rotates.
Declaration
Swift
@available(*, deprecated, message: "Use rotation(angle: Angle<Scalar>﹚ instead") public static func rotation(angle: Scalar) -> Matrix3x2Parameters
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
resultWhen the method completes, contains the created rotation matrix.
-
Creates a matrix that rotates.
Declaration
Swift
public static func rotation(angle: Angle<Scalar>) -> Matrix3x2Parameters
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
resultWhen the method completes, contains the created rotation matrix.
-
Creates a matrix that rotates about a specified center.
Declaration
Swift
@available(*, deprecated, message: "Use rotation(angle: Angle<Scalar>, center: Vector﹚ instead") public static func rotation(angle: Scalar, center: Vector) -> Matrix3x2Parameters
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
centerThe center of the rotation.
-
Creates a matrix that rotates about a specified center.
Parameters
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
centerThe center of the rotation.
-
Creates a translation matrix using the specified offsets.
Declaration
Swift
public static func translation(_ value: Vector) -> Matrix3x2Parameters
valueThe offset for both coordinate planes.
resultWhen the method completes, contains the created translation matrix.
-
Creates a translation matrix using the specified offsets.
Declaration
Swift
public static func translation(x: Scalar, y: Scalar) -> Matrix3x2Parameters
xX-coordinate offset.
yY-coordinate offset.
-
Creates a transformation matrix.
Declaration
Swift
@available(*, deprecated, message: "Use transformation(xScale: Scalar, yScale: Scalar, angle: Angle<Scalar>, xOffset: Scalar, yOffset: Scalar﹚ instead.") public static func transformation( xScale: Scalar, yScale: Scalar, angle: Scalar, xOffset: Scalar, yOffset: Scalar ) -> Matrix3x2Parameters
xScaleScaling factor that is applied along the x-axis.
yScaleScaling factor that is applied along the y-axis.
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
xOffsetX-coordinate offset.
yOffsetY-coordinate offset.
-
Creates a transformation matrix.
Declaration
Swift
public static func transformation( xScale: Scalar, yScale: Scalar, angle: Angle<Scalar>, xOffset: Scalar, yOffset: Scalar ) -> Matrix3x2Parameters
xScaleScaling factor that is applied along the x-axis.
yScaleScaling factor that is applied along the y-axis.
angleAngle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.
xOffsetX-coordinate offset.
yOffsetY-coordinate offset.
-
Transforms a vector by this matrix.
Declaration
Parameters
matrixThe matrix to use as a transformation matrix.
pointThe original vector to apply the transformation.
Return Value
The result of the transformation for the input vector.
-
Transforms a vector by this matrix.
Declaration
Swift
@inlinable public static func transformPoint<V: Vector2Type>( matrix: Matrix3x2, point: V ) -> V where V.Scalar == ScalarParameters
matrixThe matrix to use as a transformation matrix.
pointThe original vector to apply the transformation.
Return Value
The result of the transformation for the input vector.
-
Creates a skew matrix.
Declaration
Swift
public static func skew(angleX: Scalar, angleY: Scalar) -> Matrix3x2Parameters
angleXAngle of skew along the X-axis in radians.
angleYAngle of skew along the Y-axis in radians.
-
Calculates the inverse of the specified matrix.
Declaration
Swift
public static func invert(_ value: Matrix3x2) -> Matrix3x2Parameters
valueThe matrix whose inverse is to be calculated.
resultWhen the method completes, contains the inverse of the specified matrix.
-
Adds two matrices.
Declaration
Swift
public static func + (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2Parameters
leftThe first matrix to add.
rightThe second matrix to add.
Return Value
The sum of the two matrices.
-
Assert a matrix (return it unchanged).
Declaration
Swift
public prefix static func + (value: Matrix3x2) -> Matrix3x2Parameters
valueThe matrix to assert (unchanged).
Return Value
The asserted (unchanged) matrix.
-
Subtracts two matrices.
Declaration
Swift
public static func - (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2Parameters
leftThe first matrix to subtract.
rightThe second matrix to subtract.
Return Value
The difference between the two matrices.
-
Negates a matrix.
Declaration
Swift
public prefix static func - (value: Matrix3x2) -> Matrix3x2Parameters
valueThe matrix to negate.
Return Value
The negated matrix.
-
Scales a matrix by a given value.
Declaration
Swift
public static func * (left: Scalar, right: Matrix3x2) -> Matrix3x2Parameters
rightThe matrix to scale.
leftThe amount by which to scale.
Return Value
The scaled matrix.
-
Scales a matrix by a given value.
Declaration
Swift
public static func * (left: Matrix3x2, right: Scalar) -> Matrix3x2Parameters
leftThe matrix to scale.
rightThe amount by which to scale.
Return Value
The scaled matrix.
-
Multiplies two matrices.
Declaration
Swift
public static func * (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2Parameters
leftThe first matrix to multiply.
rightThe second matrix to multiply.
Return Value
The product of the two matrices.
-
Scales a matrix by a given value.
Declaration
Swift
public static func / (left: Matrix3x2, right: Scalar) -> Matrix3x2Parameters
leftThe matrix to scale.
rightThe amount by which to scale.
Return Value
The scaled matrix.
-
Divides two matrices.
Declaration
Swift
public static func / (left: Matrix3x2, right: Matrix3x2) -> Matrix3x2Parameters
leftThe first matrix to divide.
rightThe second matrix to divide.
Return Value
The quotient of the two matrices.
-
Transforms a given rectangle’s bounds using this transformation matrix.
The scale and rotation transformations use the origin (0, 0) for the base of the transformation, so scaling and rotating do not happen around the origin or center of the rectangle itself.
Declaration
Swift
@inlinable func transform<V: Vector2Type & VectorAdditive & VectorComparable>( _ rect: NRectangle<V> ) -> NRectangle<V> where V.Scalar == Scalar -
Declaration
Swift
@inlinable func transform<V>(_ point: V) -> V where Scalar == V.Scalar, V : Vector2Type -
Declaration
Swift
@inlinable func transform<V>(points: [V]) -> [V] where Scalar == V.Scalar, V : Vector2Type