## Libraries.Compute.Vector2 Documentation

Vector2 is a class representing a vector in 2D space.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(2.0, 3.0)

number dotProduct = firstVector:DotProduct(secondVector)
output "The dot product is: " + dotProdu``````

Inherits from: Libraries.Language.Object

## Summary

### Actions Summary Table

ActionsDescription
Add(number xValue, number yValue)This action adds the vector with the passed x and y components to the calling vector.
Angle()This action computes the angle in degrees of the vector relative to the positive x-axis.
Angle(Libraries.Compute.Vector2 vector)This action computes the angle in degrees between the calling vector and the passed vector.
AngleInRadians(Libraries.Compute.Vector2 vector)This action computes the angle in radians between the calling vector and the passed vector.
AngleInRadians()This action computes the angle in radians of the vector relative to the positive x-axis.
Clamp(number min, number max)This action clamps the length of the vector to be between the passed minimum and maximum values.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Copy()This action returns a copy of the current vector.
CrossProduct(number xValue, number yValue)This action computes the 2D cross product of the calling vector and the vector represented by the passed x and y components.
CrossProduct(Libraries.Compute.Vector2 vector)This action computes the 2D cross product of the calling vector and the passed vector.
Distance(number xValue, number yValue)This action computes the distance between the calling vector and the vector represented by the passed x and y components.
Distance(Libraries.Compute.Vector2 vector)This action computes the distance between the calling vector and the passed vector.
Distance(number x1, number y1, number x2, number y2)This action computes the distance between the vectors represented by the passed x and y components.
DistanceSquared(number x1, number y1, number x2, number y2)This action computes the square of the distance between the vectors represented by the passed x and y components.
DistanceSquared(Libraries.Compute.Vector2 vector)This action computes the square of the distance between the calling vector and the passed vector.
DistanceSquared(number xValue, number yValue)This action computes the square of the distance between the calling vector and the vector represented by the passed x and y components.
DotProduct(number x1, number y1, number x2, number y2)This action computes the dot product of the two vectors given by the passed x and y components.
DotProduct(Libraries.Compute.Vector2 vector)This action computes the dot product between the calling vector and the passed vector.
DotProduct(number xValue, number yValue)This action computes the dot product between the calling vector and the vector with the passed x and y components.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
EqualsAtPrecision(number xValue, number yValue, number precision)This action determines whether the vector represented by the passed x and y components equals the calling vector to within the passed precision.
EqualsAtPrecision(Libraries.Compute.Vector2 vector, number precision)This action determines whether the passed vector equals the calling vector to within the passed precision.
GetHashCode()This action gets the hash code for an object.
GetX()This action returns the current x component of the vector.
GetY()This action returns the current y component of the vector.
HasOppositeDirection(Libraries.Compute.Vector2 vector)This action determines whether the passed vector has the opposite direction as the calling vector.
HasSameDirection(Libraries.Compute.Vector2 vector)This action determines whether the passed vector has the same direction as the calling vector.
IsCollinear(Libraries.Compute.Vector2 other)This action determines whether the passed vector is collinear with the calling vector, meaning that it lies on the same line as the calling vector and has the same direction as the calling vector.
IsCollinear(Libraries.Compute.Vector2 other, number precision)This action determines whether the passed vector is collinear with the calling vector, meaning that it lies on the same line as the calling vector and has the same direction as the calling vector to within the passed precision.
IsCollinearOpposite(Libraries.Compute.Vector2 other)This action determines whether the passed vector is collinear in the opposite direction with the calling vector, meaning that it lies on the same line as the calling vector and has the opposite direction as the calling vector.
IsCollinearOpposite(Libraries.Compute.Vector2 other, number precision)This action determines whether the passed vector is collinear in the opposite direction with the calling vector, meaning that it lies on the same line as the calling vector and has the opposite direction as the calling vector to within the passed precision.
IsOnLine(Libraries.Compute.Vector2 other, number precision)This action determines whether the passed vector is on the same line as the calling vector to within the passed precision, either in the same or opposite direction
IsOnLine(Libraries.Compute.Vector2 other)This action determines whether the passed vector is on the same line as the calling vector, either in the same or opposite direction.
IsPerpendicular(Libraries.Compute.Vector2 vector)This action determines whether the passed vector is perpendicular to the calling vector.
IsPerpendicular(Libraries.Compute.Vector2 vector, number precision)This action determines whether the passed vector is perpendicular to the calling vector to within the passed precision.
IsUnit()This action determines whether the vector is a unit vector, meaning it has a length of 1.
IsUnit(number precision)This action determines whether the vector is a unit vector, meaning it has a length of 1 to within the passed precision.
IsZero()This action determines whether the vector is the zero vector, meaning that its x and y components are 0.
IsZero(number precision)This action determines whether the vector is the zero vector to within the passed precision, meaning that its x and y components are 0.
Length(number x, number y)This action returns the length of the vector with the passed x and y components measured from the origin (0, 0).
Length()This action returns the length of the vector measured from the origin (0, 0)
LengthSquared(number x, number y)This action returns the square of the length of the vector with the passed x and y components measured from the origin (0, 0).
LengthSquared()This action returns the square of the length of the vector measured from the origin (0, 0).
Limit(number limit)This action limits the length of the vector to the passed limit value.
LimitSquared(number limitSquared)This action limits the square of the length of the vector to the passed value, which represents the square of the value to limit the length of the vector to.
LinearInterpolation(Libraries.Compute.Vector2 target, number alpha)This action performs a linear interpolation between the calling vector and the passed target vector by alpha, which is between 0, and 1, inclusive.
Multiply(Libraries.Compute.Matrix3 matrix)This action multiplies the vector by the passed 3-by-3 matrix.
MultiplyAndAdd(Libraries.Compute.Vector2 addVector, Libraries.Compute.Vector2 scaleVector)This action multiplies the passed vector by the passed scalar vector and adds the result to the calling vector.
MultiplyAndAdd(Libraries.Compute.Vector2 vector, number scalar)This action multiplies the passed vector by the passed scalar and adds the result to the calling vector.
Normalize()This action produces a normalized vector with the same direction as the original vector but with a length of 1.
Rotate(number degrees)This action rotates the vector by the passed angle in degrees in the counter-clockwise direction.
Rotate90Degrees(boolean rotateCounterClockwise)This action rotates the vector 90 degrees.
Scale(Libraries.Compute.Vector2 vector)This action scales the vector by multiplying the x component by the x component of the passed vector and the y component by the y component of the passed vector.
Scale(number scalar)This action scales the vector by multiplying the x and y components by the passed scalar value.
Scale(number xValue, number yValue)This action scales the vector by multiplying the x component with the passed x value and the y component with the passed y value.
Set(number xValue, number yValue)This action sets the x and y components of the vector to the passed x and y values.
Set(Libraries.Compute.Vector2 vector)This action sets the vector's components to the components of the passed vector.
SetAngle(number degrees)This action sets the vector to have the passed angle in degrees relative to the x-axis.
SetAngleInRadians(number radians)This action sets the vector to have the passed angle in radians relative to the x-axis.
SetLength(number length)This action sets the length of the vector to the passed length.
SetLengthSquared(number lengthSquared)This action sets the length of the vector to the passed value that represents the square of the new length.
SetX(number x)This action sets the x component of the vector to the passed value
SetY(number y)This action sets the y component of the vector to the passed value
SetZero()This action sets the vector to the zero vector, meaning both the x and y components will be set to 0.
Subtract(number xValue, number yValue)This action subtracts a vector with the passed components from the calling vector.
Subtract(Libraries.Compute.Vector2 vector)This action subtracts the passed vector from the calling vector.

## Actions Documentation

This action adds the vector with the passed x and y components to the calling vector. This changes the calling vector to the result of the addition.

Example Code

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

Vector2 vector
vector:Set(4.3, 8.1)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number xValue: The x component of the vector to add
• number yValue: The y component of the vector to add

#### Return

Libraries.Compute.Vector2: The calling vector after addition

This action adds the passed vector to the calling vector. This action changes the calling vector to the result of the addition.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.2, 5.5)
secondVector:Set(8.3, 4.2)

number newX = firstVector:GetX()
number newY = firstVector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after addition

### Angle()

This action computes the angle in degrees of the vector relative to the positive x-axis.

Example Code

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

Vector2 vector

vector:Set(1.0, 1.0)

number angle = vector:Angle()

output "The angle in degrees of the vector is: " + ang``````

#### Return

number: The angle of the vector relative to the x-axis (in degrees)

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

This action computes the angle in degrees between the calling vector and the passed vector.

Example Code

``````use Libraries.Compute.Vector2
use Libraries.Compute.Math

Math math

Vector2 firstVector
Vector2 secondVector

firstVector:Set(0.5, math:SquareRoot(3) / 2)
secondVector:Set(math:SquareRoot(2) / 2, math:SquareRoot(2) / 2)

number angle = firstVector:Angle(secondVector)

output "The angle in degrees between the vectors is: " + ang``````

#### Return

number: The angle between the two vectors (in degrees)

This action computes the angle in radians between the calling vector and the passed vector.

Example Code

``````use Libraries.Compute.Vector2
use Libraries.Compute.Math

Math math

Vector2 firstVector
Vector2 secondVector

firstVector:Set(0.5, math:SquareRoot(3) / 2)
secondVector:Set(math:SquareRoot(2) / 2, math:SquareRoot(2) / 2)

output "The angle in radians between the vectors is: " + ang``````

#### Return

number: The angle between the two vectors (in radians)

This action computes the angle in radians of the vector relative to the positive x-axis.

Example Code

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

Vector2 vector

vector:Set(1.0, 1.0)

output "The angle in radians of the vector is: " + ang``````

#### Return

number: The angle of the vector relative to the x-axis (in radians)

### Clamp(number min, number max)

This action clamps the length of the vector to be between the passed minimum and maximum values. This changes the vector if the length of the vector is greater than the maximum or less than the minimum.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

vector:Clamp(0.5, 1.5)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number min: The minimum length
• number max: The maximum length

#### Return

Libraries.Compute.Vector2: The vector with a new length if the old length was below the minimum or above the maximum

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

Example Code

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

#### Return

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

### Copy()

This action returns a copy of the current vector. The new vector's x and y components are the same as the calling vector's x and y components.

Example Code

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

Vector2 vector
vector:Set(4.8, 3.2)

Vector2 copyVector
copyVector = vector:Copy()

number newX = copyVector:GetX()
number newY = copyVector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: a new vector that is a copy of the calling vector

### CrossProduct(number xValue, number yValue)

This action computes the 2D cross product of the calling vector and the vector represented by the passed x and y components. This action is mainly necessary for game graphics.

Example Code

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

Vector2 vector

vector:Set(4.0, 2.0)

number crossProduct = vector:CrossProduct(10.0, 3.0)

output "The 2D cross product is: " + crossProdu``````

#### Parameters

• number xValue: The x component of the other vector
• number yValue: The y component of the other vector

#### Return

number: The 2D cross product of the vectors

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

This action computes the 2D cross product of the calling vector and the passed vector. This action is mainly necessary for game graphics.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(4.0, 2.0)
secondVector:Set(8.0, 8.0)

number crossProduct = firstVector:CrossProduct(secondVector)

output "The 2D cross product is: " + crossProdu``````

#### Return

number: The 2D cross product of the vectors

### Distance(number xValue, number yValue)

This action computes the distance between the calling vector and the vector represented by the passed x and y components.

Example Code

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

Vector2 vector

vector:Set(3.0, 7.0)

number distance = vector:Distance(7.0, 8.0)
output "The distance is " + distan``````

#### Parameters

• number xValue: The x component of the other vector
• number yValue: The y component of the other vector

#### Return

number: The distance between the two vectors

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

This action computes the distance between the calling vector and the passed vector.

Example Code

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

Vector2 vector
Vector2 otherVector

vector:Set(4.0, 9.0)
otherVector:Set(3.0, 7.0)

number distance = vector:Distance(otherVector)
output "The distance is " + distan``````

#### Return

number: The distance between the two vectors

### Distance(number x1, number y1, number x2, number y2)

This action computes the distance between the vectors represented by the passed x and y components.

Example Code

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

Vector2 vector
number distance = vector:Distance(2.0, 3.0, 5.0, 1.0)
output "The distance is " + distan``````

#### Parameters

• number x1: The x component of the first vector
• number y1: The y component of the first vector
• number x2: The x component of the second vector
• number y2: The y component of the second vector

#### Return

number: The distance between the two vectors

### DistanceSquared(number x1, number y1, number x2, number y2)

This action computes the square of the distance between the vectors represented by the passed x and y components.

Example Code

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

Vector2 vector
number distanceSquared = vector:DistanceSquared(2.0, 3.0, 5.0, 1.0)
output "The square of the distance is " + distanceSquar``````

#### Parameters

• number x1: The x component of the first vector
• number y1: The y component of the first vector
• number x2: The x component of the second vector
• number y2: The y component of the second vector

#### Return

number: The square of the distance between the two vectors

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

This action computes the square of the distance between the calling vector and the passed vector.

Example Code

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

Vector2 vector
Vector2 otherVector

vector:Set(4.0, 9.0)
otherVector:Set(3.0, 7.0)

number distanceSquared = vector:DistanceSquared(otherVector)
output "The square of the distance is " + distanceSquar``````

#### Return

number: The square of the distance between the two vectors

### DistanceSquared(number xValue, number yValue)

This action computes the square of the distance between the calling vector and the vector represented by the passed x and y components.

Example Code

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

Vector2 vector

vector:Set(3.0, 7.0)

number distanceSquared = vector:DistanceSquared(7.0, 8.0)
output "The square of the distance is " + distanceSquar``````

#### Parameters

• number xValue: The x component of the other vector
• number yValue: The y component of the other vector

#### Return

number: The square of the distance between the two vectors

### DotProduct(number x1, number y1, number x2, number y2)

This action computes the dot product of the two vectors given by the passed x and y components.

Example Code

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

Vector2 vector
number dotProduct = vector:DotProduct(3.0, 4.0, 5.0, 6.0)
output "The dot product is " + dotProdu``````

#### Parameters

• number x1: The x component of the first vector
• number y1: The y component of the first vector
• number x2: The x component of the second vector
• number y2: The y component of the second vector

#### Return

number: The dot product of the two vectors.

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

This action computes the dot product between the calling vector and the passed vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(5.0, 6.0)

number dotProduct = firstVector:DotProduct(secondVector)
output "The dot product is " + dotProdu``````

#### Return

number: The dot product of the two vectors

### DotProduct(number xValue, number yValue)

This action computes the dot product between the calling vector and the vector with the passed x and y components.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

number dotProduct = vector:DotProduct(4.0, 5.0)
output "The dot product is " + dotProdu``````

#### Parameters

• number xValue: The x component of the other vector
• number yValue: The y component of the other vector

#### Return

number: The dot product of the two vectors

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

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

Example Code

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

#### Return

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

### EqualsAtPrecision(number xValue, number yValue, number precision)

This action determines whether the vector represented by the passed x and y components equals the calling vector to within the passed precision.

Example Code

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

Vector2 vector

vector:Set(3.0, 4.0)

boolean areEqual = vector:EqualsAtPrecision(3.0, 4.0000001, 0.00001)

if areEqual
output "The two vectors are equal."
else
output "The two vectors are not equal."
e``````

#### Parameters

• number xValue: The x component of the other vector
• number yValue: The y component of the other vector
• number precision: The desired precision

#### Return

boolean: true if the vectors are equal within the passed precision, false otherwise

### EqualsAtPrecision(Libraries.Compute.Vector2 vector, number precision)

This action determines whether the passed vector equals the calling vector to within the passed precision.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(6.0, 8.0)
secondVector:Scale(0.5)

boolean areEqual = firstVector:EqualsAtPrecision(secondVector, 0.00001)

if areEqual
output "The two vectors are equal."
else
output "The two vectors are not equal."
e``````

#### Return

boolean: true if the vectors are equal within the passed precision, false otherwise

### GetHashCode()

This action gets the hash code for an object.

Example Code

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

#### Return

integer: The integer hash code of the object.

### GetX()

This action returns the current x component of the vector.

Example Code

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

Vector2 vector
vector:Set(4.0, 3.0)
number x = vector:GetX()
output "The x component is " +``````

#### Return

number: the x component of the vector

### GetY()

This action returns the current y component of the vector.

Example Code

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

Vector2 vector
vector:Set(4.0, 3.0)
number y = vector:GetY()
output "The y component is " +``````

#### Return

number: the y component of the vector

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

This action determines whether the passed vector has the opposite direction as the calling vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(-3.0, -4.0)

boolean isOpposite = firstVector:HasOppositeDirection(secondVector)

if isOpposite
output "The two vectors have opposite directions."
else
output "The two vectors do not have opposite directions."
e``````

#### Return

boolean: true if the two vectors have the opposite direction, false otherwise

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

This action determines whether the passed vector has the same direction as the calling vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(6.0, 8.0)

boolean isSame = firstVector:HasSameDirection(secondVector)

if isSame
output "The two vectors have the same direction."
else
output "The two vectors do not have the same direction."
e``````

#### Return

boolean: true if the two vectors have the same direction, false otherwise

### IsCollinear(Libraries.Compute.Vector2 other)

This action determines whether the passed vector is collinear with the calling vector, meaning that it lies on the same line as the calling vector and has the same direction as the calling vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(6.0, 8.0)

boolean collinear = firstVector:IsCollinear(secondVector)

if collinear
output "The two vectors are collinear in the same direction"
else
output "The two vectors are not collinear in the same direction"
e``````

#### Return

boolean: true if the vectors are collinear, false otherwise.

### IsCollinear(Libraries.Compute.Vector2 other, number precision)

This action determines whether the passed vector is collinear with the calling vector, meaning that it lies on the same line as the calling vector and has the same direction as the calling vector to within the passed precision.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(6.0, 8.0)

boolean collinear = firstVector:IsCollinear(secondVector, 0.00001)

if collinear
output "The two vectors are collinear in the same direction"
else
output "The two vectors are not collinear in the same direction"
e``````

#### Return

boolean: true if the vectors are collinear, false otherwise.

### IsCollinearOpposite(Libraries.Compute.Vector2 other)

This action determines whether the passed vector is collinear in the opposite direction with the calling vector, meaning that it lies on the same line as the calling vector and has the opposite direction as the calling vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(-6.0, -8.0)

boolean collinearOpposite = firstVector:IsCollinearOpposite(secondVector)

if collinearOpposite
output "The two vectors are collinear in the opposite direction"
else
output "The two vectors are not collinear in the opposite direction"
e``````

#### Return

boolean: true if the vectors are collinear in the opposite directions, false otherwise

### IsCollinearOpposite(Libraries.Compute.Vector2 other, number precision)

This action determines whether the passed vector is collinear in the opposite direction with the calling vector, meaning that it lies on the same line as the calling vector and has the opposite direction as the calling vector to within the passed precision.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(3.0, 4.0)
secondVector:Set(-6.0, -8.0)

boolean collinearOpposite = firstVector:IsCollinearOpposite(secondVector, 0.00001)

if collinearOpposite
output "The two vectors are collinear in the opposite direction"
else
output "The two vectors are not collinear in the opposite direction"
e``````

#### Return

boolean: true if the vectors are collinear in the opposite directions, false otherwise

### IsOnLine(Libraries.Compute.Vector2 other, number precision)

This action determines whether the passed vector is on the same line as the calling vector to within the passed precision, either in the same or opposite direction

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(1.0, 2.0)
secondVector:Set(-2.0, -4.0)

boolean onLine = firstVector:IsOnLine(secondVector, 0.00001)

if onLine
output "The two vectors are on the same line."
else
output "The two vectors are not on the same line."
e``````

#### Return

boolean: true if the vectors are on the same line, false otherwise

### IsOnLine(Libraries.Compute.Vector2 other)

This action determines whether the passed vector is on the same line as the calling vector, either in the same or opposite direction.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(1.0, 2.0)
secondVector:Set(-2.0, -4.0)

boolean onLine = firstVector:IsOnLine(secondVector)

if onLine
output "The two vectors are on the same line."
else
output "The two vectors are not on the same line."
e``````

#### Return

boolean: true if the vectors are on the same line, false otherwise

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

This action determines whether the passed vector is perpendicular to the calling vector.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(1.0, 0.0)
secondVector:Set(0.0, 1.0)

boolean isPerpendicular = firstVector:IsPerpendicular(secondVector)

if isPerpendicular
output "The two vectors are perpendicular."
else
output "The two vectors are not perpendicular."
e``````

#### Return

boolean: true if the two vectors are perpendicular, false otherwise

### IsPerpendicular(Libraries.Compute.Vector2 vector, number precision)

This action determines whether the passed vector is perpendicular to the calling vector to within the passed precision.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(1.0, 0.0)
secondVector:Set(0.0, 1.0)

boolean isPerpendicular = firstVector:IsPerpendicular(secondVector, 0.00001)

if isPerpendicular
output "The two vectors are perpendicular."
else
output "The two vectors are not perpendicular."
e``````

#### Return

boolean: true if the two vectors are perpendicular, false otherwise

### IsUnit()

This action determines whether the vector is a unit vector, meaning it has a length of 1.

Example Code

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

Vector2 vector
vector:Set(0.0, 1.0)

boolean isUnit = vector:IsUnit()

if isUnit
output "The vector is a unit vector."
else
output "The vector is not a unit vector."
e``````

#### Return

boolean: true if the vector is a unit vector, false otherwise

### IsUnit(number precision)

This action determines whether the vector is a unit vector, meaning it has a length of 1 to within the passed precision.

Example Code

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

Vector2 vector
vector:Set(0.0, 1.0)

boolean isUnit = vector:IsUnit(0.00001)

if isUnit
output "The vector is a unit vector."
else
output "The vector is not a unit vector."
e``````

#### Parameters

• number precision: The desired precision

#### Return

boolean: true if the vector is a unit vector to within the passed precision, false otherwise

### IsZero()

This action determines whether the vector is the zero vector, meaning that its x and y components are 0.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(5.0, 6.0)
secondVector:Set(5.0, 6.0)

firstVector:Subtract(secondVector)

boolean isZero = firstVector:IsZero()

if isZero
output "The vector is the zero vector."
else
output "The vector is not the zero vector."
e``````

#### Return

boolean: true if the vector is the zero vector, false otherwise

### IsZero(number precision)

This action determines whether the vector is the zero vector to within the passed precision, meaning that its x and y components are 0.

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(5.0, 6.0)
secondVector:Set(5.0, 6.0)

firstVector:Subtract(secondVector)

boolean isZero = firstVector:IsZero(0.00001)

if isZero
output "The vector is the zero vector."
else
output "The vector is not the zero vector."
e``````

#### Parameters

• number precision: The desired precision

#### Return

boolean: true if the vector is the zero vector to within the passed precision, false otherwise

### Length(number x, number y)

This action returns the length of the vector with the passed x and y components measured from the origin (0, 0).

Example Code

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

Vector2 vector

number length = vector:Length(3.0, 4.0)
output "The length of the vector is " + leng``````

#### Parameters

• number x: The x component of the vector
• number y: The y component of the vector

#### Return

number: The length of the vector

### Length()

This action returns the length of the vector measured from the origin (0, 0)

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

number length = vector:Length()
output "The length of the vector is " + leng``````

#### Return

number: the length of the calling vector

### LengthSquared(number x, number y)

This action returns the square of the length of the vector with the passed x and y components measured from the origin (0, 0).

Example Code

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

Vector2 vector

number lengthSquared = vector:LengthSquared(3.0, 4.0)
output "The square of the length of the vector is " + lengthSquar``````

#### Parameters

• number x: The x component of the vector
• number y: The y component of the vector

#### Return

number: The square of the length of the vector

### LengthSquared()

This action returns the square of the length of the vector measured from the origin (0, 0).

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

number lengthSquared = vector:LengthSquared()
output "The square of the length of the vector is " + lengthSquar``````

#### Return

number: The square of the length of the calling vector

### Limit(number limit)

This action limits the length of the vector to the passed limit value. This changes the calling vector to have a new length if its old length was greater than the passed limit.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

vector:Limit(2.5)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number limit: The value to limit the length to

#### Return

Libraries.Compute.Vector2: The vector with a new length if its old length was larger than the passed limit

### LimitSquared(number limitSquared)

This action limits the square of the length of the vector to the passed value, which represents the square of the value to limit the length of the vector to. This changes the calling vector to have a new length if the old length squared was greater than the limit squared.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

vector:LimitSquared(6.25)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number limitSquared: the square of the limit

#### Return

Libraries.Compute.Vector2: the calling vector with a new length if the old length squared was greater than the limit squared

### LinearInterpolation(Libraries.Compute.Vector2 target, number alpha)

This action performs a linear interpolation between the calling vector and the passed target vector by alpha, which is between 0, and 1, inclusive. This changes the calling vector to the result of the linear interpolation.

Example Code

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

Vector2 vector
Vector2 target

vector:Set(2.0, 7.0)
target:Set(3.0, 6.0)
number alpha = 0.5

vector:LinearInterpolation(target, alpha)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after linear interpolation

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

This action multiplies the vector by the passed 3-by-3 matrix. This action is mainly necessary for game graphics. This changes the vector to the result of the multiplication.

Example Code

``````use Libraries.Compute.Vector2
use Libraries.Compute.Matrix3
use Libraries.Containers.Array

Vector2 vector
Matrix3 matrix
Array<number> array

vector:Set(4.0, 8.0)

number n = 0.0
integer i = 0
repeat while i < 9
n = n + 1.0
i = i + 1
end
matrix:Set(array)

vector:Multiply(matrix)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The vector after multiplication

This action multiplies the passed vector by the passed scalar vector and adds the result to the calling vector. This changes the calling vector to the result of the multiplication and addition.

Example Code

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

Vector2 vector
Vector2 scaleVector

vector:Set(4.0, 7.0)
scaleVector:Set(3.0, 1.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after multiplication and addition

This action multiplies the passed vector by the passed scalar and adds the result to the calling vector. This changes the calling vector to the result of the multiplication and addition.

Example Code

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

Vector2 vector

vector:Set(4.0, 7.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after multiplication and addition

### Normalize()

This action produces a normalized vector with the same direction as the original vector but with a length of 1. This action changes the calling vector to the normalized vector.

Example Code

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

Vector2 vector
vector:Set(23.4, 43.2)
vector:Normalize()

number newX = vector:GetX()
number newY = vector:GetY()

output "The normalized vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: the normalized vector with a length of 1

### Rotate(number degrees)

This action rotates the vector by the passed angle in degrees in the counter-clockwise direction.

Example Code

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

Vector2 vector
vector:Set(1.0, 1.0)

vector:Rotate(45.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number degrees: The rotation angle in degrees

#### Return

Libraries.Compute.Vector2: The calling vector after rotation

### Rotate90Degrees(boolean rotateCounterClockwise)

This action rotates the vector 90 degrees. If the passed boolean is true, then the rotation direction is in the counter-clockwise direction. If it is false, then the rotation direction is in the clockwise direction.

Example Code

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

Vector2 vector
vector:Set(4.0, 1.0)

vector:Rotate90Degrees(true)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• boolean rotateCounterClockwise: Whether to rotate counter-clockwise

#### Return

Libraries.Compute.Vector2: The vector after rotation

This action rotates the vector by the passed angle in radians in the counter-clockwise direction.

Example Code

``````use Libraries.Compute.Vector2
use Libraries.Compute.Math

Math math

Vector2 vector
vector:Set(1.0, 1.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after rotation

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

This action scales the vector by multiplying the x component by the x component of the passed vector and the y component by the y component of the passed vector.

Example Code

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

Vector2 vector
Vector2 scaleVector

vector:Set(2.0, 3.0)
scaleVector:Set(3.0, 4.0)

vector:Scale(scaleVector)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector

### Scale(number scalar)

This action scales the vector by multiplying the x and y components by the passed scalar value.

Example Code

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

Vector2 vector
vector:Set(2.0, 3.0)

vector:Scale(2.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number scalar: The scalar value to multiply by

#### Return

Libraries.Compute.Vector2: The calling vector

### Scale(number xValue, number yValue)

This action scales the vector by multiplying the x component with the passed x value and the y component with the passed y value.

Example Code

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

Vector2 vector
vector:Set(2.0, 3.0)

vector:Scale(3.0, 4.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number xValue: The value to multiply the x component by
• number yValue: The value to multiply the y component by

#### Return

Libraries.Compute.Vector2: The calling vector

### Set(number xValue, number yValue)

This action sets the x and y components of the vector to the passed x and y values.

Example Code

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

Vector2 vector
vector:Set(8.8, 4.2)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number xValue: the value to set as the x component
• number yValue: the value to set as the y component

#### Return

Libraries.Compute.Vector2: the calling vector

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

This action sets the vector's components to the components of the passed vector.

Example Code

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

Vector2 firstVector
firstVector:Set(2.4, 4.3)

Vector2 secondVector
secondVector:Set(firstVector)

number newX = secondVector:GetX()
number newY = secondVector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: the calling vector

### SetAngle(number degrees)

This action sets the vector to have the passed angle in degrees relative to the x-axis.

Example Code

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

Vector2 vector
vector:Set(1.0, 5.0)

vector:SetAngle(45.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number degrees: The new angle of the vector

#### Return

Libraries.Compute.Vector2: The calling vector with the new angle

This action sets the vector to have the passed angle in radians relative to the x-axis.

Example Code

``````use Libraries.Compute.Vector2
use Libraries.Compute.Math

Math math

Vector2 vector
vector:Set(1.0, 5.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number radians: The new angle of the vector

#### Return

Libraries.Compute.Vector2: The calling vector with the new angle

### SetLength(number length)

This action sets the length of the vector to the passed length.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

vector:SetLength(10.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number length: The new length of the vector

#### Return

Libraries.Compute.Vector2: The vector with the new length

### SetLengthSquared(number lengthSquared)

This action sets the length of the vector to the passed value that represents the square of the new length.

Example Code

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

Vector2 vector
vector:Set(3.0, 4.0)

vector:SetLengthSquared(100.0)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number lengthSquared: the length squared

#### Return

Libraries.Compute.Vector2: The vector with a new length

### SetX(number x)

This action sets the x component of the vector to the passed value

Example Code

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

Vector2 vector
vector:SetX(``````

#### Parameters

• number x: The value to set as the x component

### SetY(number y)

This action sets the y component of the vector to the passed value

Example Code

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

Vector2 vector
vector:SetY(``````

#### Parameters

• number y: The value to set as the y component

### SetZero()

This action sets the vector to the zero vector, meaning both the x and y components will be set to 0.

Example Code

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

Vector2 vector
vector:SetZero()

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector set to the zero vector

### Subtract(number xValue, number yValue)

This action subtracts a vector with the passed components from the calling vector. This action changes the calling vector to the result of the subtraction.

Example Code

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

Vector2 vector

vector:Set(9.0, 8.0)

vector:Subtract(7.3, 2.7)

number newX = vector:GetX()
number newY = vector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Parameters

• number xValue: The x component of the vector to subtract
• number yValue: The y component of the vector to subtract

#### Return

Libraries.Compute.Vector2: The calling vector after subtraction

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

This action subtracts the passed vector from the calling vector. For example, if A and B are vectors, then this action will compute A - B. This changes the calling vector to the result of the subtraction. Using the above example, this results in A = A - B

Example Code

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

Vector2 firstVector
Vector2 secondVector

firstVector:Set(9.0, 8.0)
secondVector:Set(6.0, 5.0)

firstVector:Subtract(secondVector)

number newX = firstVector:GetX()
number newY = firstVector:GetY()

output "The new vector is: [" + newX + ", " + newY + "``````

#### Return

Libraries.Compute.Vector2: The calling vector after subtraction