Skip to main content

Vector3

Vector3:normalize

If the vector has zero length, an error is thrown.

  • Methods:
    • Vector3:normalize()

Vector3:dot

Calculates the dot product of this vector with another vector.

  • Parameters:

    NameTypeDescription
    otherVector3The other vector to calculate the dot product with.
  • Return:

    TypeDescription
    numberThe dot product of the two vectors.
  • Methods:

    • Vector3:dot(other)

Vector3:cross

Calculates the cross product of this vector with another vector.

  • Parameters:

    NameTypeDescription
    otherVector3The other vector to calculate the cross product with.
  • Return:

    TypeDescription
    Vector3A new vector that is the cross product of the two vectors.
  • Methods:

    • Vector3:cross(other)

Vector3:get_negated

Returns a new vector that is the negation of this vector.

  • Return:

    TypeDescription
    Vector3A new vector where each component is the negation of the corresponding component of this vector.
  • Methods:

    • Vector3:get_negated()

Vector3:get_normalized

Returns a normalized copy of this vector.

  • Return:

    TypeDescription
    Vector3A new vector that is the normalized version of this vector.
  • Methods:

    • Vector3:get_normalized()

Vector3:is_equal_tol

Checks if this vector is approximately equal to another vector, within a specified tolerance.

  • Parameters:

    NameTypeDescription
    otherVector3The vector to compare with.
    tolerancenumberThe tolerance within which the vectors are considered equal.
  • Return:

    TypeDescription
    booleanReturns true if the vectors are approximately equal within the given tolerance, otherwise false.
  • Methods:

    • Vector3:is_equal_tol(other, tolerance)

Vector3:is_zero

Determines if the vector is a zero vector.

  • Return:

    TypeDescription
    booleanReturns true if all components of the vector are zero, otherwise false.
  • Methods:

    • Vector3:is_zero()

Vector3:length

Calculates the length (magnitude) of the vector.

  • Return:

    TypeDescription
    numberThe length of the vector.
  • Methods:

    • Vector3:length()

Vector3:length_2d

Calculates the 2D length (magnitude) of the vector ignoring the z component.

  • Return:

    TypeDescription
    numberThe 2D length of the vector.
  • Methods:

    • Vector3:length_2d()

Vector3:length_2d_sqr

Calculates the squared 2D length of the vector, ignoring the z component. Useful for comparisons where the exact length is not necessary.

  • Return:

    TypeDescription
    numberThe squared 2D length of the vector.
  • Methods:

    • Vector3:length_2d_sqr()

Vector3:length_sqr

Calculates the squared length of the vector. Useful for comparisons where the exact length is not necessary.

  • Return:

    TypeDescription
    numberThe squared length of the vector.
  • Methods:

    • Vector3:length_sqr()

Vector3:mul

Multiplies each component of the vector by a scalar.

  • Parameters:

    NameTypeDescription
    scalarnumberThe scalar to multiply with.
  • Methods:

    • Vector3:mul(scalar)

Vector3:negate

Negates each component of the vector.

  • Methods:
    • Vector3:negate()

Vector3:random

Assigns random values to each component of the vector within the specified range.

  • Parameters:

    NameTypeDescription
    minnumberThe minimum value (inclusive) - defaults to -1.0.
    maxnumberThe maximum value (inclusive) - defaults to 1.0.
  • Methods:

    • Vector3:random(min, max)

Vector3:set

--- Sets the vector's components to those of another vector.

  • Parameters:

    NameTypeDescription
    vectorVector3The vector from which to copy the components.
  • Methods:

    • Vector3:set(vector)

Vector3:set_unpacked

Sets the components of the vector to the provided values.

  • Parameters:

    NameTypeDescription
    x_valnumberThe new x value.
    y_valnumberThe new y value.
    z_valnumberThe new z value.
  • Methods:

    • Vector3:set_unpacked(x_val, y_val, z_val)

Vector3:sub

Subtracts another vector from this vector.

  • Parameters:

    NameTypeDescription
    vectorVector3The vector to subtract.
  • Methods:

    • Vector3:sub(vector)

Vector3:unpack

Unpacks the vector's components and returns them as individual values.

  • Return:

    TypeDescription
    number, number, numberThe x, y, and z components of the vector.
  • Methods:

    • Vector3:unpack()

Vector3:within_aabox

Checks if the vector is within an axis-aligned bounding box defined by two points.

  • Parameters:

    NameTypeDescription
    boxStartVector3The starting point of the bounding box.
    boxEndVector3The ending point of the bounding box.
  • Return:

    TypeDescription
    booleanReturns true if the vector is within the bounding box, otherwise false.
  • Methods:

    • Vector3:within_aabox(boxStart, boxEnd)

Vector3:zero

Sets all components of the vector to zero.

  • Methods:
    • Vector3:zero()

Vector3:distance

Calculates the distance to another vector.

  • Parameters:

    NameTypeDescription
    otherVector3The other vector.
  • Return:

    TypeDescription
    numberThe squared distance to the other vector.
  • Methods:

    • Vector3:distance(other)

Vector3:dist_to_sqr

Calculates the squared distance to another vector.

  • Parameters:

    NameTypeDescription
    otherVector3The other vector.
  • Return:

    TypeDescription
    numberThe squared distance to the other vector.
  • Methods:

    • Vector3:dist_to_sqr(other)