## Libraries.Compute.Affine2 Documentation

Affine2 is a specialized three-by-three matrix that represents a series of 2D transformations, such as translations, scales, flips, rotations, and shears. The last row of an affine is always 0, 0, 1.

Example Code

``````use Libraries.Compute.Affine2

Affine2 affine
affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

Inherits from: Libraries.Language.Object

### Variables Table

VariablesDescription
number row1column0
number row0column0
number row0column1
number row0column2
number row1column1
number row1column2

## Actions Documentation

### ApplyTo(Libraries.Compute.Vector2 point)

This action applies the affine transformation(s) to the passed point. The passed vector representing the point is altered as a result of this action.

#### Parameters

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Vector2

Affine2 affine
Vector2 point

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

point:Set(3, 4)

affine:ApplyAffineTransformation(point)

number x = point:GetX()
number y = point:GetY()

output "The new point is [" + x + ", " + y + "]"
``````

### Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

#### Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

``````Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
``````

### Determinant()

This action calculates the determinant of the affine matrix.

#### Return

number: The determinant of the affine matrix

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

number determinant = affine:Determinant()

output "The determinant is " + determinant
``````

### Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

#### Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

``````use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
``````

### GetHashCode()

This action gets the hash code for an object.

#### Return

integer: The integer hash code of the object.

Example

``````Object o
integer hash = o:GetHashCode()
``````

### GetTranslation()

This action gets the x and y translation component of the affine matrix.

#### Return

Libraries.Compute.Vector2: the position vector of the translation

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Vector2

Affine2 affine
Vector2 translation

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

translation = affine:GetTranslation()

number x = translation:GetX()
number y = translation:GetY()

output "The translation vector is [" + x + ", " + y + "]"
``````

### Identity()

This action constructs an identity matrix. The resulting affine transformation is: 1.0 | 0.0 | 0.0 0.0 | 1.0 | 0.0 0.0 | 0.0 | 1.0

#### Return

Libraries.Compute.Affine2: The affine as the identy matrix

Example

``````use Libraries.Compute.Affine2

Affine2 affine
affine:Identity()

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Invert()

This action inverts the affine matrix.

#### Return

Libraries.Compute.Affine2: The inverted affine

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

affine:Invert()

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### IsIdentity()

This action determines whether this affine matrix is the identity matrix.

#### Return

boolean: true if matrix is the identity matrix and false if it is not

Example

``````use Libraries.Compute.Affine2

Affine2 affine

if affine:IsIdentityMatris()
output "The affine is the identity matrix."
else
output "The affine is not the identity matrix."
end
``````

### IsTranslation()

This action determines whether this affine matrix is a translation matrix.

#### Return

boolean: true if matrix is a translation matrix and false if it is not

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToTranslation(3, 2)

if affine:IsTranslation()
output "The affine is a translation affine"
else
output "The affine is not a translation affine"
end
``````

### Multiply(Libraries.Compute.Affine2 affine)

This action multiplies this affine matrix with the passed affine matrix.

#### Return

Libraries.Compute.Affine2: The affine as the product

Example

``````use Libraries.Compute.Affine2

Affine2 affine
Affine2 other

affine:SetToTranslationRotationScale(2, 2, 45, 3, 3)
other:SetToTranslationScale(1, 1, 3, 3)

affine:Multiply(other)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Rotate(number degrees)

This action multiplies the affine matrix with the (counter-clockwise) rotation matrix.

#### Parameters

• number degrees: The angle in degrees

#### Return

Libraries.Compute.Affine2: The affine rotated

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

affine:Rotate(90)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

This action multiplies the affine matrix with the (counter-clockwise) rotation matrix.

#### Return

Libraries.Compute.Affine2: The affine rotated

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Math

Affine2 affine
Math math

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Scale(Libraries.Compute.Vector2 scale)

This action multiplies the affine matrix with the scale matrix.

#### Return

Libraries.Compute.Affine2: The affine scaled

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Vector2

Affine2 affine
Vector2 vector

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)
vector:Set(4, 4)

affine:Scale(vector)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Scale(number scaleX, number scaleY)

This action multiplies the affine matrix with the scale matrix.

#### Parameters

• number scaleX: The scale in the x-direction
• number scaleY: The scale in the y-direction

#### Return

Libraries.Compute.Affine2: The affine scaled

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToTranslationRotationScale(3, 3, 45, 2, 2)

affine:Scale(4, 4)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Set(Libraries.Compute.Matrix4 matrix)

This action sets the affine matrix to the 2D transformation components of the passed 4x4 matrix.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Matrix4

Affine2 affine
Matrix4 matrix

matrix:Set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

affine:Set(matrix)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Set(Libraries.Compute.Matrix3 matrix)

This action sets the affine matrix to the passed 3x3 matrix.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Matrix3

Affine2 affine
Matrix3 matrix

matrix:Set(0, 1, 2, 3, 4, 5, 6, 7, 8)

affine:Set(matrix)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### Set(Libraries.Compute.Affine2 other)

This action sets the affine transformation to the passed affine transformation.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2

Affine2 affine
Affine2 setAffine

setAffine:SetToTranslation(3, 4)

affine:Set(setAffine)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToProduct(Libraries.Compute.Affine2 left, Libraries.Compute.Affine2 right)

This action sets the affine matrix to the product of the passed affine matrices.

#### Return

Libraries.Compute.Affine2: The affine after setting as the product

Example

``````use Libraries.Compute.Affine2

Affine2 affine
Affine2 left
Affine2 right

left:SetToTranslationScale(3, 3, 2, 2)
right:SetToTranslationRotationScale(2, 3, 45, 2, 2)

affine:SetToProduct(left, right)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToRotation(number cosine, number sine)

This action sets the affine matrix to the rotation matrix that will rotate any vector in the counter-clockwise direction around the z-axis (the axis coming out of the screen).

#### Parameters

• number cosine
• number sine

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Math

Math math

Affine2 affine

affine:SetToRotation(math:SquareRoot(2) / 2, math:SquareRoot(2) / 2)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToRotation(number degrees)

This action sets the affine matrix as the rotation matrix with the given rotation angle in degrees.

#### Parameters

• number degrees: The rotation angle in degrees

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToRotation(45)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

This action sets the affine matrix to the rotation matrix with the given rotation angle in radians.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Math

Math math

Affine2 affine

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToScaling(number scaleX, number scaleY)

This action sets the affine matrix to the scaling matrix with the given x and y scales.

#### Parameters

• number scaleX: The amount to scale in the x-direction
• number scaleY: The amount to scale in the y-direction

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToScaling(2, 2)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToScaling(Libraries.Compute.Vector2 scale)

This action sets the affine matrix to the scaling matrix with the given scaling vector.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Vector2

Affine2 affine
Vector2 vector

vector:Set(2, 2)

affine:SetToScaling(vector)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToShearing(number shearX, number shearY)

This action sets the affine matrix to the shearing matrix with the passed shear in x and y.

#### Parameters

• number shearX: The shear in x
• number shearY: The shear in y

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2

Affine2 affine

affine:SetToShearing(3, 2)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````

### SetToShearing(Libraries.Compute.Vector2 vector)

This action sets the affine matrix to the shearing matrix with the passed shear vector.

#### Return

Libraries.Compute.Affine2: The affine after setting

Example

``````use Libraries.Compute.Affine2
use Libraries.Compute.Vector2

Affine2 affine
Vector2 vector

vector:Set(3, 2)

affine:SetToShearing(vector)

number row0column0 = affine:row0column0
number row0column1 = affine:row0column1
number row0column2 = affine:row0column2
number row1column0 = affine:row1column0
number row1column1 = affine:row1column1
number row1column2 = affine:row1column2

output "The affine is: "
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + "|"
output "|0, 0, 1|"
``````