@bedrock-oss/bedrock-boost
    Preparing search index...

    Class Vec3

    Implements

    • Vector3
    Index

    Constructors

    • Parameters

      • x: number
      • y: number
      • z: number

      Returns Vec3

    • Parameters

      Returns Vec3

    • Parameters

      • x: Vector3

      Returns Vec3

    • Parameters

      • x: Direction

      Returns Vec3

    • Parameters

      • x: number[]

      Returns Vec3

    Properties

    x: number

    X component of this vector.

    y: number

    Y component of this vector.

    z: number

    Z component of this vector.

    Down: Vec3
    East: Vec3
    North: Vec3
    South: Vec3
    Up: Vec3
    West: Vec3
    Zero: Vec3

    Methods

    • Adds three numbers to the current vector.

      Parameters

      • x: number

        The x component to be added.

      • y: number

        The y component to be added.

      • z: number

        The z component to be added.

      Returns Vec3

      The updated vector after addition.

    • Adds another Vec3 to the current vector.

      Parameters

      • x: Vec3

        The Vec3 to be added.

      Returns Vec3

      The updated vector after addition.

    • Adds another Vector3 to the current vector.

      Parameters

      • x: Vector3

        The Vector3 to be added.

      Returns Vec3

      The updated vector after addition.

    • Adds a Direction to the current vector.

      Parameters

      • x: Direction

        The Direction to be added.

      Returns Vec3

      The updated vector after addition.

    • Adds an array of numbers to the current vector.

      Parameters

      • x: number[]

        The array of numbers to be added.

      Returns Vec3

      The updated vector after addition.

    • Checks if the current vector is almost equal to another vector defined by three numbers, within a given tolerance (delta).

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      • delta: number

        The maximum allowed difference between corresponding components.

      Returns boolean

      True if the vectors are almost equal; otherwise, false.

    • Checks if the current vector is almost equal to another Vec3 within a given tolerance (delta).

      Parameters

      • x: Vec3

        The Vec3 to compare.

      • delta: number

        The maximum allowed difference between corresponding components.

      Returns boolean

      True if the vectors are almost equal; otherwise, false.

    • Checks if the current vector is almost equal to another Vector3 within a given tolerance (delta).

      Parameters

      • x: Vector3

        The Vector3 to compare.

      • delta: number

        The maximum allowed difference between corresponding components.

      Returns boolean

      True if the vectors are almost equal; otherwise, false.

    • Checks if the current vector is almost equal to a Direction within a given tolerance (delta).

      Parameters

      • x: Direction

        The Direction to compare.

      • delta: number

        The maximum allowed difference between corresponding components.

      Returns boolean

      True if the vectors are almost equal; otherwise, false.

    • Checks if the current vector is almost equal to a vector represented by an array of numbers, within a given tolerance (delta).

      Parameters

      • x: number[]

        The array of numbers representing the vector.

      • delta: number

        The maximum allowed difference between corresponding components.

      Returns boolean

      True if the vectors are almost equal; otherwise, false.

    • Computes the angle (in radians) between the current vector and a vector specified by three numbers.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns number

      The angle in radians between the two vectors.

    • Computes the angle (in radians) between the current vector and another Vec3.

      Parameters

      • x: Vec3

        The Vec3 to compute the angle with.

      Returns number

      The angle in radians between the two vectors.

    • Computes the angle (in radians) between the current vector and another Vector3.

      Parameters

      • x: Vector3

        The Vector3 to compute the angle with.

      Returns number

      The angle in radians between the two vectors.

    • Computes the angle (in radians) between the current vector and a Direction.

      Parameters

      • x: Direction

        The Direction to compute the angle with.

      Returns number

      The angle in radians between the two vectors.

    • Computes the angle (in radians) between the current vector and a vector represented by an array of numbers.

      Parameters

      • x: number[]

        The array of numbers representing the other vector.

      Returns number

      The angle in radians between the two vectors.

    • Ceils the X, Y, and Z components of the vector.

      Returns Vec3

      A new vector with the ceiled components.

    • Ceils the X component of the vector.

      Returns Vec3

      A new vector with the ceiled X component.

    • Ceils the Y component of the vector.

      Returns Vec3

      A new vector with the ceiled Y component.

    • Ceils the Z component of the vector.

      Returns Vec3

      A new vector with the ceiled Z component.

    • Creates a copy of the current vector.

      Returns Vec3

      A new vector with the same values as the current vector.

    • Computes the cross product of the current vector with three numbers.

      A cross product is a vector that is perpendicular to both vectors.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns Vec3

      A new vector representing the cross product.

    • Computes the cross product of the current vector with another Vec3.

      A cross product is a vector that is perpendicular to both vectors.

      Parameters

      • x: Vec3

        The Vec3 to be crossed.

      Returns Vec3

      A new vector representing the cross product.

    • Computes the cross product of the current vector with another Vector3.

      A cross product is a vector that is perpendicular to both vectors.

      Parameters

      • x: Vector3

        The Vector3 to be crossed.

      Returns Vec3

      A new vector representing the cross product.

    • Computes the cross product of the current vector with a Direction.

      A cross product is a vector that is perpendicular to both vectors.

      Parameters

      • x: Direction

        The Direction to be crossed.

      Returns Vec3

      A new vector representing the cross product.

    • Computes the cross product of the current vector with an array of numbers.

      A cross product is a vector that is perpendicular to both vectors.

      Parameters

      • x: number[]

        The array of numbers representing a vector.

      Returns Vec3

      A new vector representing the cross product.

    • Computes the distance between the current vector and a vector represented by three numbers.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns number

      The distance between the two vectors.

    • Computes the distance between the current vector and another Vec3.

      Parameters

      • x: Vec3

        The Vec3 to measure the distance to.

      Returns number

      The distance between the two vectors.

    • Computes the distance between the current vector and another Vector3.

      Parameters

      • x: Vector3

        The Vector3 to measure the distance to.

      Returns number

      The distance between the two vectors.

    • Computes the distance between the current vector and a Direction.

      Parameters

      • x: Direction

        The Direction to measure the distance to.

      Returns number

      The distance between the two vectors.

    • Computes the distance between the current vector and a vector represented by an array of numbers.

      Parameters

      • x: number[]

        The array of numbers representing the other vector.

      Returns number

      The distance between the two vectors.

    • Computes the squared distance between the current vector and a vector represented by three numbers. This is faster than computing the actual distance and can be useful for comparison purposes.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns number

      The squared distance between the two vectors.

    • Computes the squared distance between the current vector and another Vec3. This is faster than computing the actual distance and can be useful for comparison purposes.

      Parameters

      • x: Vec3

        The Vec3 to measure the squared distance to.

      Returns number

      The squared distance between the two vectors.

    • Computes the squared distance between the current vector and another Vector3. This is faster than computing the actual distance and can be useful for comparison purposes.

      Parameters

      • x: Vector3

        The Vector3 to measure the squared distance to.

      Returns number

      The squared distance between the two vectors.

    • Computes the squared distance between the current vector and a Direction. This is faster than computing the actual distance and can be useful for comparison purposes.

      Parameters

      • x: Direction

        The Direction to measure the squared distance to.

      Returns number

      The squared distance between the two vectors.

    • Computes the squared distance between the current vector and a vector represented by an array of numbers. This is faster than computing the actual distance and can be useful for comparison purposes.

      Parameters

      • x: number[]

        The array of numbers representing the other vector.

      Returns number

      The squared distance between the two vectors.

    • Calculates the shortest distance between a point (represented by this Vector3 instance) and a line segment.

      This method finds the perpendicular projection of the point onto the line defined by the segment. If this projection lies outside the line segment, then the method calculates the distance from the point to the nearest segment endpoint.

      Parameters

      • start: Vector3

        The starting point of the line segment.

      • end: Vector3

        The ending point of the line segment.

      Returns number

      The shortest distance between the point and the line segment.

    • Divides the current vector by three numbers.

      Parameters

      • x: number

        The divisor for the x component.

      • y: number

        The divisor for the y component.

      • z: number

        The divisor for the z component.

      Returns Vec3

      The updated vector after division.

    • Divides the current vector by another Vec3.

      Parameters

      • x: Vec3

        The Vec3 divisor.

      Returns Vec3

      The updated vector after division.

    • Divides the current vector by another Vector3.

      Parameters

      • x: Vector3

        The Vector3 divisor.

      Returns Vec3

      The updated vector after division.

    • Divides the current vector by a Direction.

      Parameters

      • x: Direction

        The Direction divisor.

      Returns Vec3

      The updated vector after division.

    • Divides the current vector by an array of numbers.

      Parameters

      • x: number[]

        The array divisor.

      Returns Vec3

      The updated vector after division.

    • Divides the current vector by a scalar.

      Parameters

      • x: number

        The scalar divisor.

      Returns Vec3

      The updated vector after division.

    • Computes the dot product of the current vector with a vector specified by three numbers.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns number

      The dot product of the two vectors.

    • Computes the dot product of the current vector with another Vec3.

      Parameters

      • x: Vec3

        The Vec3 to compute the dot product with.

      Returns number

      The dot product of the two vectors.

    • Computes the dot product of the current vector with another Vector3.

      Parameters

      • x: Vector3

        The Vector3 to compute the dot product with.

      Returns number

      The dot product of the two vectors.

    • Computes the dot product of the current vector with a Direction.

      Parameters

      • x: Direction

        The Direction to compute the dot product with.

      Returns number

      The dot product of the two vectors.

    • Computes the dot product of the current vector with a vector represented by an array of numbers.

      Parameters

      • x: number[]

        The array of numbers representing the other vector.

      Returns number

      The dot product of the two vectors.

    • Returns a new vector offset from the current vector down by 1 block.

      Returns Vec3

      A new vector offset from the current vector down by 1 block.

    • Returns a new vector offset from the current vector east by 1 block.

      Returns Vec3

      A new vector offset from the current vector east by 1 block.

    • Checks if the current vector is exactly equal to another vector defined by three numbers.

      Parameters

      • x: number

        The x component of the other vector.

      • y: number

        The y component of the other vector.

      • z: number

        The z component of the other vector.

      Returns boolean

      True if the vectors are exactly equal; otherwise, false.

    • Checks if the current vector is exactly equal to another Vec3.

      Parameters

      • x: Vec3

        The Vec3 to compare.

      Returns boolean

      True if the vectors are exactly equal; otherwise, false.

    • Checks if the current vector is exactly equal to another Vector3.

      Parameters

      • x: Vector3

        The Vector3 to compare.

      Returns boolean

      True if the vectors are exactly equal; otherwise, false.

    • Checks if the current vector is exactly equal to a Direction.

      Parameters

      • x: Direction

        The Direction to compare.

      Returns boolean

      True if the vectors are exactly equal; otherwise, false.

    • Checks if the current vector is exactly equal to a vector represented by an array of numbers.

      Parameters

      • x: number[]

        The array of numbers representing the vector.

      Returns boolean

      True if the vectors are exactly equal; otherwise, false.

    • Floors the X, Y, and Z components of the vector.

      Returns Vec3

      A new vector with the floored components.

    • Floors the X component of the vector.

      Returns Vec3

      A new vector with the floored X component.

    • Floors the Y component of the vector.

      Returns Vec3

      A new vector with the floored Y component.

    • Floors the Z component of the vector.

      Returns Vec3

      A new vector with the floored Z component.

    • Checks if the current vector is equal to the zero vector.

      Returns boolean

      true if the vector is equal to the zero vector, else returns false.

    • Computes the length (magnitude) of the vector.

      Returns number

      The length of the vector.

    • Computes the squared length of the vector. This is faster than computing the actual length and can be useful for comparison purposes.

      Returns number

      The squared length of the vector.

    • Computes the linear interpolation between the current vector and another vector, when t is in the range [0, 1]. Computes the extrapolation when t is outside this range.

      Parameters

      • v: Vector3

        The other vector.

      • t: number

        The interpolation factor.

      Returns Vec3

      A new vector after performing the lerp operation.

    • Multiplies the current vector by three numbers.

      Parameters

      • x: number

        The multiplier for the x component.

      • y: number

        The multiplier for the y component.

      • z: number

        The multiplier for the z component.

      Returns Vec3

      The updated vector after multiplication.

    • Multiplies the current vector by another Vec3.

      Parameters

      • x: Vec3

        The Vec3 multiplier.

      Returns Vec3

      The updated vector after multiplication.

    • Multiplies the current vector by another Vector3.

      Parameters

      • x: Vector3

        The Vector3 multiplier.

      Returns Vec3

      The updated vector after multiplication.

    • Multiplies the current vector by a Direction.

      Parameters

      • x: Direction

        The Direction multiplier.

      Returns Vec3

      The updated vector after multiplication.

    • Multiplies the current vector by an array of numbers.

      Parameters

      • x: number[]

        The array multiplier.

      Returns Vec3

      The updated vector after multiplication.

    • Multiplies the current vector by a scalar.

      Parameters

      • x: number

        The scalar multiplier.

      Returns Vec3

      The updated vector after multiplication.

    • Normalizes the vector to have a length (magnitude) of 1. Normalized vectors are often used as a direction vectors.

      Returns Vec3

      The normalized vector.

    • Returns a new vector offset from the current vector north by 1 block.

      Returns Vec3

      A new vector offset from the current vector north by 1 block.

    • Computes the projection of the current vector onto a vector specified by three numbers. This method finds how much of the current vector lies in the direction of the given vector.

      Parameters

      • x: number

        The x component of the vector to project onto.

      • y: number

        The y component of the vector to project onto.

      • z: number

        The z component of the vector to project onto.

      Returns Vec3

      A new vector representing the projection of the current vector.

    • Computes the projection of the current vector onto another Vec3. This method finds how much of the current vector lies in the direction of the given vector.

      Parameters

      • x: Vec3

        The Vec3 to project onto.

      Returns Vec3

      A new vector representing the projection of the current vector.

    • Computes the projection of the current vector onto another Vector3. This method finds how much of the current vector lies in the direction of the given vector.

      Parameters

      • x: Vector3

        The Vector3 to project onto.

      Returns Vec3

      A new vector representing the projection of the current vector.

    • Computes the projection of the current vector onto a Direction. This method finds how much of the current vector lies in the direction of the given vector.

      Parameters

      • x: Direction

        The Direction to project onto.

      Returns Vec3

      A new vector representing the projection of the current vector.

    • Computes the projection of the current vector onto a vector represented by an array of numbers. This method finds how much of the current vector lies in the direction of the given vector.

      Parameters

      • x: number[]

        The array of numbers representing the vector to project onto.

      Returns Vec3

      A new vector representing the projection of the current vector.

    • Computes the reflection of the current vector against a normal vector specified by three numbers. Useful for simulating light reflections or bouncing objects.

      Parameters

      • x: number

        The x component of the normal vector.

      • y: number

        The y component of the normal vector.

      • z: number

        The z component of the normal vector.

      Returns Vec3

      A new vector representing the reflection of the current vector.

    • Computes the reflection of the current vector against another Vec3 normal vector. Useful for simulating light reflections or bouncing objects.

      Parameters

      • x: Vec3

        The Vec3 representing the normal vector.

      Returns Vec3

      A new vector representing the reflection of the current vector.

    • Computes the reflection of the current vector against another Vector3 normal vector. Useful for simulating light reflections or bouncing objects.

      Parameters

      • x: Vector3

        The Vector3 representing the normal vector.

      Returns Vec3

      A new vector representing the reflection of the current vector.

    • Computes the reflection of the current vector against a Direction normal vector. Useful for simulating light reflections or bouncing objects.

      Parameters

      • x: Direction

        The Direction representing the normal vector.

      Returns Vec3

      A new vector representing the reflection of the current vector.

    • Computes the reflection of the current vector against a normal vector represented by an array of numbers. Useful for simulating light reflections or bouncing objects.

      Parameters

      • x: number[]

        The array of numbers representing the normal vector.

      Returns Vec3

      A new vector representing the reflection of the current vector.

    • Rotates the current normalized vector by a given angle around a given axis.

      Parameters

      • axis: Vector3

        The axis of rotation.

      • angle: number

        The angle of rotation in degrees.

      Returns Vec3

      The rotated vector.

    • Rounds the X, Y, and Z components of the vector.

      Returns Vec3

      A new vector with the rounded components.

    • Rounds the X component of the vector.

      Returns Vec3

      A new vector with the rounded X component.

    • Rounds the Y component of the vector.

      Returns Vec3

      A new vector with the rounded Y component.

    • Rounds the Z component of the vector.

      Returns Vec3

      A new vector with the rounded Z component.

    • Scales the current vector by a scalar.

      Parameters

      • scalar: number

        The scalar to scale the vector by.

      Returns Vec3

      The updated vector after scaling.

    • Sets the X component of the vector.

      Parameters

      • value: number

        The new X value.

      Returns Vec3

      The updated vector with the new X value.

    • Sets the X component of the vector.

      Parameters

      • value: (x: number) => number

        The new X value.

      Returns Vec3

      The updated vector with the new X value.

    • Sets the Y component of the vector.

      Parameters

      • value: number

        The new Y value.

      Returns Vec3

      The updated vector with the new Y value.

    • Sets the Y component of the vector.

      Parameters

      • value: (y: number) => number

        The new Y value.

      Returns Vec3

      The updated vector with the new Y value.

    • Sets the Z component of the vector.

      Parameters

      • value: number

        The new Z value.

      Returns Vec3

      The updated vector with the new Z value.

    • Sets the Z component of the vector.

      Parameters

      • value: (z: number) => number

        The new Z value.

      Returns Vec3

      The updated vector with the new Z value.

    • Computes the spherical linear interpolation between the current vector and another vector, when t is in the range [0, 1]. Computes the extrapolation when t is outside this range.

      Parameters

      • v: Vector3

        The other vector.

      • t: number

        The interpolation factor.

      Returns Vec3

      A new vector after performing the slerp operation.

    • Returns a new vector offset from the current vector south by 1 block.

      Returns Vec3

      A new vector offset from the current vector south by 1 block.

    • Subtracts three numbers from the current vector.

      Parameters

      • x: number

        The x component to be subtracted.

      • y: number

        The y component to be subtracted.

      • z: number

        The z component to be subtracted.

      Returns Vec3

      The updated vector after subtraction.

    • Subtracts another Vec3 from the current vector.

      Parameters

      • x: Vec3

        The Vec3 to be subtracted.

      Returns Vec3

      The updated vector after subtraction.

    • Subtracts another Vector3 from the current vector.

      Parameters

      • x: Vector3

        The Vector3 to be subtracted.

      Returns Vec3

      The updated vector after subtraction.

    • Subtracts a Direction from the current vector.

      Parameters

      • x: Direction

        The Direction to be subtracted.

      Returns Vec3

      The updated vector after subtraction.

    • Subtracts an array of numbers from the current vector.

      Parameters

      • x: number[]

        The array of numbers to be subtracted.

      Returns Vec3

      The updated vector after subtraction.

    • Converts the vector to an array containing the X, Y, and Z components of the vector.

      Returns number[]

      An array containing the X, Y, and Z components of the vector.

    • Returns a new vector with the X, Y, and Z components rounded to the nearest block location.

      Returns Vec3

    • Converts the vector to a direction. If the vector is not a unit vector, then it will be normalized and rounded to the nearest direction.

      Returns Direction

    • Converts the vector to a string representation.

      Parameters

      • Optionalformat: "long" | "short"

        The format of the string representation. Defaults to "long".

      • Optionalseparator: string

        The separator to use between components. Defaults to ", ".

      Returns string

      The string representation of the vector.

      The "long" format is "Vec3(x, y, z)". The "short" format is "x, y, z".

    • Converts the normal vector to yaw and pitch values.

      Returns Vector2

      A Vector2 containing the yaw and pitch values.

    • Returns a new vector offset from the current vector up by 1 block.

      Returns Vec3

      A new vector offset from the current vector up by 1 block.

    • Updates the X, Y, and Z components of the vector.

      Parameters

      • x: undefined | ((x: number) => number)

        The function to use to update the X value.

      • y: undefined | ((y: number) => number)

        The function to use to update the Y value.

      • z: undefined | ((z: number) => number)

        The function to use to update the Z value.

      Returns Vec3

      The updated vector with the new values.

    • Returns a new vector offset from the current vector west by 1 block.

      Returns Vec3

      A new vector offset from the current vector west by 1 block.

    • Creates a new vector from the given values.

      Parameters

      • x: number
      • y: number
      • z: number

      Returns Vec3

    • Creates a new vector from the given values.

      Parameters

      Returns Vec3

    • Creates a new vector from the given values.

      Parameters

      • x: Vector3

      Returns Vec3

    • Creates a new vector from the given values.

      Parameters

      • x: Direction

      Returns Vec3

    • Creates a new vector from the given values.

      Parameters

      • x: number[]

      Returns Vec3

    • Creates a new direction vector from yaw and pitch values.

      Parameters

      • rotation: Vector2

        The yaw and pitch values in degrees.

      Returns Vec3

      A new vector representing the direction.

    • Creates a new direction vector from yaw and pitch values.

      Parameters

      • yaw: number

        The yaw value in degrees.

      • pitch: number

        The pitch value in degrees.

      Returns Vec3

      A new vector representing the direction.