## Libraries.Compute.Vector3 Documentation

Vector3 is a class representing a vector in 3D space.

Example Code

``````use Libraries.Compute.Vector3

Vector3 vector1
Vector3 vector2

vector1:Set(2, 6, 9)
vector2:Set(1, 7, 2)

vector1:CrossProduct(vector2)

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

output "The cross product of the two vectors is: [" + newX + ", " + newY + "]"
``````

Inherits from: Libraries.Language.Object

## Actions Documentation

### Add(number xValue, number yValue, number zValue)

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

#### Parameters

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

#### Return

Libraries.Compute.Vector3: The calling vector after addition

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(4.3, 8.1, 6.6)

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

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

This action adds the passed value to the x, y, and z components of the vector. This changes the vector to the result of the addition.

#### Parameters

• number value: The value to add to the x, y, and z components

#### Return

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(3.5, 5.0, 3.1)

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

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

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

#### Return

Libraries.Compute.Vector3: The calling vector after addition

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.2, 5.5, 9.0)
secondVector:Set(8.3, 4.2, -7.3)

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

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

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

#### Parameters

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

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(2.0, 1.0, 2.0)

vector:Clamp(0.5, 1.5)

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

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

### 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)
``````

### Copy()

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

#### Return

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

Example

``````
use Libraries.Compute.Vector3

Vector3 vector
vector:Set(4.8, 3.2, -4.2)

Vector3 copyVector
copyVector = vector:Copy()

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

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

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

This action computes the cross product between this vector and the passed vector. This changes the calling vector to the result of the cross product.

#### Return

Libraries.Compute.Vector3: The calling vector after taking the cross product

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

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

firstVector:CrossProduct(secondVector)

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

output "The cross product is: [" + newX + ", " + newY + ", " + newZ + "]"
``````

### CrossProduct(number xValue, number yValue, number zValue)

This action computes the cross product between the calling vector and the vector with the passed x, y, and z components. This changes the calling vector to the result of the cross product.

#### Parameters

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

#### Return

Libraries.Compute.Vector3: The calling vector after taking the cross product

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(1.0, 0.0, 0.0)

vector:CrossProduct(0.0, 1.0, 0.0)

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

output "The cross product is: [" + newX + ", " + newY + ", " + newZ + "]"
``````

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

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

#### Parameters

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

#### Return

number: The distance between the two vectors

Example

``````use Libraries.Compute.Vector3

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

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

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

#### Return

number: The distance between the two vectors

Example

``````
use Libraries.Compute.Vector3

Vector3 vector
Vector3 otherVector

vector:Set(2.0, 3.0, 4.0)
otherVector:Set(2.0, 5.0, 1.0)

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

### Distance(number xValue, number yValue, number zValue)

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

#### Parameters

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

#### Return

number: The distance between the two vectors

Example

``````
use Libraries.Compute.Vector3

Vector3 vector

vector:Set(2.0, 3.0, 4.0)

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

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

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

#### Return

number: The square of the distance between the two vectors

Example

``````
use Libraries.Compute.Vector3

Vector3 vector
Vector3 otherVector

vector:Set(2.0, 3.0, 4.0)
otherVector:Set(2.0, 5.0, 1.0)

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

### DistanceSquared(number xValue, number yValue, number zValue)

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

#### Parameters

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

#### Return

number: The square of the distance between the two vectors

Example

``````
use Libraries.Compute.Vector3

Vector3 vector

vector:Set(2.0, 3.0, 4.0)

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

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

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

#### Parameters

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

#### Return

number: The square of the distance between the two vectors

Example

``````use Libraries.Compute.Vector3

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

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

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

#### Parameters

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

#### Return

number: The dot product of the two vectors.

Example

``````use Libraries.Compute.Vector3

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

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

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

#### Return

number: The dot product of the two vectors

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

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

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

### DotProduct(number xValue, number yValue, number zValue)

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

#### Parameters

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

#### Return

number: The dot product of the two vectors

Example

``````
use Libraries.Compute.Vector3

Vector3 vector
vector:Set(3.0, 4.0, 5.0)

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

### 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)
``````

### Equals(Libraries.Compute.Vector3 vector)

This action determines whether the passed vector is equal to this vector. Two vectors are equal if they have the same x, y, and z components.

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

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

boolean areEqual = firstVector:Equals(secondVector)

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

### EqualsAtPrecision(Libraries.Compute.Vector3 other, number epsilon)

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

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(6.0, 8.0, 10.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."
end
``````

### EqualsAtPrecision(number xVal, number yVal, number zVal, number precision)

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

#### Parameters

• number xVal
• number yVal
• number zVal
• number precision: The desired precision

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 vector

vector:Set(3.0, 4.0, 7.5)

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

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

### 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()
``````

### GetX()

This action returns the x component of the vector.

#### Return

number: the x component of the vector

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(1, 2, 3)

number x = vector:GetX()
output "The x component is: " + x
``````

### GetY()

This action returns the y component of the vector.

#### Return

number: the y component of the vector

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(1, 2, 3)

number y = vector:GetY()
output "The y component is: " + y
``````

### GetZ()

This action returns the z component of the vector.

#### Return

number: the z component of the vector

Example

``````use Libraries.Compute.Vector3

Vector3 vector
vector:Set(1, 2, 3)

number z = vector:GetZ()
output "The z component is: " + z
``````

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

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

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(-3.0, -4.0, -5.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."
end
``````

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

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

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(6.0, 8.0, 10.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."
end
``````

### IsCollinear(Libraries.Compute.Vector3 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.

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(6.0, 8.0, 10.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"
end
``````

### IsCollinear(Libraries.Compute.Vector3 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.

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(6.0, 8.0, 10.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"
end
``````

### IsCollinearOpposite(Libraries.Compute.Vector3 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.

#### Return

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

Example

``````use Libraries.Compute.Vector3

Vector3 firstVector
Vector3 secondVector

firstVector:Set(3.0, 4.0, 5.0)
secondVector:Set(-6.0, -8.0, -10.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"
end
``````