Vector4

Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w).

Core Class

Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w).

Constructors

  • Parameters

    • _x: number
    • _y: number
    • _z: number
    • _w: number

    Returns Vector4

Properties

x: number

the x value of this vector.

y: number

the y value of this vector.

z: number

the z value of this vector.

w: number

the w value of this vector.

isVector4: boolean

Check the type whether it belongs to Vector4. This value should not be changed by user.

Methods

  • Sets the x, y, z and w components of this vector.

    Parameters

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

    Returns Vector4

  • Sets the x, y, z and w values of this vector both equal to scalar.

    Parameters

    • scalar: number

    Returns Vector4

  • Replaces this vector's x value with x.

    Parameters

    • x: number

    Returns Vector4

  • Replaces this vector's y value with y.

    Parameters

    • y: number

    Returns Vector4

  • Replaces this vector's z value with z.

    Parameters

    • z: number

    Returns Vector4

  • Replaces this vector's w value with w.

    Parameters

    • w: number

    Returns Vector4

  • If index equals 0 set x to value. If index equals 1 set y to value. If index equals 2 set z to value. If index equals 3 set w to value.

    Parameters

    • index: number

      0, 1 or 2.

    • value: number

    Returns Vector4

  • If index equals 0 returns the x value. If index equals 1 returns the y value. If index equals 2 returns the z value. If index equals 3 returns the w value.

    Parameters

    • index: number

      0, 1, 2 or 3.

    Returns number

  • Returns a new Vector4 with the same x, y, z and w values as this one.

    Returns Vector4

  • Returns Readonly<
    Pick<
    ReadonlyMarked,
    | "_readonly_mark"
    | "cloneReadonly"
    | "clone"
    | "equals"
    | "getSerializeData"
    | "x"
    | "y"
    | "z"
    | "getNumberCount"
    | "toArray"
    | "dot"
    | "lengthSq"
    | "length"
    | "manhattanLength"
    | "w",
    >,
    >

  • Adds the scalar value s to this vector's x, y, z and w values.

    Parameters

    • s: number

    Returns Vector4

  • Subtracts s from this vector's x, y, z and w components.

    Parameters

    • s: number

    Returns Vector4

  • Multiplies this vector by scalar s.

    Parameters

    • scalar: number

    Returns Vector4

  • Divides this vector by scalar s. Sets vector to ( 0, 0, 0, 0 ) if s = 0.

    Parameters

    • scalar: number

    Returns Vector4

  • If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value.

    If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.

    Parameters

    Returns Vector4

  • If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value.

    If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.

    Parameters

    Returns Vector4

  • If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value.

    If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.

    Parameters

    • min: Vector4

      the minimum x, y, z and w values.

    • max: Vector4

      the maximum x, y, z and w values in the desired range.

    Returns Vector4

  • If this vector's x, y, z or w values are greater than the max value, they are replaced by the max value.

    If this vector's x, y, z or w values are less than the min value, they are replaced by the min value.

    Parameters

    • minVal: number
    • maxVal: number

    Returns Vector4

  • If this vector's length is greater than the max value, it is replaced by the max value.

    If this vector's length is less than the min value, it is replaced by the min value.

    Parameters

    • min: number

      the minimum x, y, z and w values.

    • max: number

      the maximum x, y, z and w values in the desired range.

    Returns Vector4

  • The components of this vector are rounded down to the nearest integer value.

    Returns Vector4

  • The x, y, z and w components of this vector are rounded up to the nearest integer value.

    Returns Vector4

  • The components of this vector are rounded to the nearest integer value.

    Returns Vector4

  • The components of this vector are rounded towards zero (up if negative, down if positive) to an integer value.

    Returns Vector4

  • Inverts this vector - i.e. sets x = -x, y = -y, z = -z and w = -w.

    Returns Vector4

  • Computes the square of the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.

    Returns number

  • Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to (x, y, z, w).

    Returns number

  • Computes the Manhattan length of this vector.

    Returns number

  • Converts this vector to a unit vector

    • that is, sets it equal to a vector with the same direction as this one, but length| length 1.

    Returns Vector4

  • Sets this vector to a vector with given length the same direction as this one.

    Parameters

    • length: number

    Returns Vector4

  • Linearly interpolates between this vector and v, where alpha is the percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.

    Parameters

    • v: Vector4

      Vector4 to interpolate towards.

    • alpha: number

      interpolation factor, typically in the closed interval [0, 1].

    Returns Vector4

  • Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the percent distance along the line connecting the two vectors

    • alpha = 0 will be v1, and alpha = 1 will be v2.

    Parameters

    • v1: Vector4

      the starting Vector4.

    • v2: Vector4

      Vector4 to interpolate towards.

    • alpha: number

      interpolation factor, typically in the closed interval [0, 1].

    Returns Vector4

  • Checks for strict equality of this vector and v.

    Parameters

    Returns boolean

  • Sets the x, y and z components of this vector to the quaternion's axis and w to the angle.

    Parameters

    Returns Vector4

  • m a Matrix4 of which the upper left 3x3 matrix is a pure rotation matrix. Sets the x, y and z to the axis of rotation and w to the angle.

    Parameters

    Returns Vector4

  • Sets this vector's x value to be array[ offset + 0 ], y value to be array[ offset + 1 ] z value to be array[ offset + 2 ] and w value to be array[ offset + 3 ].

    Parameters

    • array: ArrayLike<number>

      the source array.

    • offset: number

      (optional) offset into the array.

    Returns Vector4

  • There are 4 elements in this vector.

    Returns number

  • Returns an array [x, y, z, w], or copies x, y, z and w into the provided array.

    Parameters

    • array: number[]

      (optional) array to store this vector to. If this is not provided, a new array will be created.

    • offset: number

      (optional) optional offset into the array.

    Returns number[]