Class Vector4

Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to represent a number of things, such as:

  • A point in 4D space.
  • A direction and length in 4D space. The length will always be the Euclidean distance (straight-line distance) from (0, 0, 0, 0) to (x, y, z, w) and the direction is also measured from (0, 0, 0, 0) towards (x, y, z, w).
  • Any arbitrary ordered quadruplet of numbers.

Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.

Example

const a = new THREE.Vector4( 0, 1, 0, 0 );

//no arguments; will be initialised to (0, 0, 0, 1)
const b = new THREE.Vector4( );

const d = a.dot( b );

Hierarchy

  • Base
    • Vector4

Implements

Constructors

  • Creates a new Vector4.

    Parameters

    • Optional x: number

      the x value of this vector. Default is 0.

    • Optional y: number

      the y value of this vector. Default is 0.

    • Optional z: number

      the z value of this vector. Default is 0.

    • Optional w: number

      the w value of this vector. Default is 0.

    Returns Vector4

Properties

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

Accessors

  • get height(): number
  • Alias for w.

    Returns number

  • set height(value: number): void
  • Parameters

    • value: number

    Returns void

  • get isBox2(): boolean
  • Returns boolean

  • get isBox3(): boolean
  • Returns boolean

  • get isColor(): boolean
  • Returns boolean

  • get isCylindrical(): boolean
  • Returns boolean

  • get isEuler(): boolean
  • Returns boolean

  • get isLine3(): boolean
  • Returns boolean

  • get isMatrix3(): boolean
  • Returns boolean

  • get isMatrix4(): boolean
  • Returns boolean

  • get isPlane(): boolean
  • Returns boolean

  • get isQuaternion(): boolean
  • Returns boolean

  • get isRay(): boolean
  • Returns boolean

  • get isSphere(): boolean
  • Returns boolean

  • get isSpherical(): boolean
  • Returns boolean

  • get isTriangle(): boolean
  • Returns boolean

  • get isVector(): boolean
  • Read-only flag to check if a given object is of type Vector.

    Returns boolean

  • get isVector2(): boolean
  • Returns boolean

  • get isVector3(): boolean
  • Returns boolean

  • get isVector4(): boolean
  • Read-only flag to check if a given object is of type Vector4.

    Returns boolean

  • get width(): number
  • Alias for z.

    Returns number

  • set width(value: number): void
  • Parameters

    • value: number

    Returns void

Methods

  • Returns IterableIterator<number>

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

    Returns

    This instance.

    Parameters

    • s: number

      The scalar.

    Returns Vector4

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

    Returns

    This instance.

    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.

    Returns

    This instance.

    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

  • Restrict the min and max length of this vector. 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.

    Returns

    This instance.

    Parameters

    • min: number

      the minimum value the length will be clamped to

    • max: number

      the maximum value the length will be clamped to

    Returns Vector4

  • Restrict the min and max component values. 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.

    Returns

    This instance.

    Parameters

    • minVal: number

      The minimum value the components will be clamped to

    • maxVal: number

      The maximum value the components will be clamped to

    Returns Vector4

  • Calculates the dot product of this vector and v.

    Returns

    The dot product.

    Parameters

    Returns number

  • Compare the components of this vector are strictly equal to those of v.

    Returns

    True if the components of this vector and v are strictly equal; false otherwise.

    Parameters

    Returns boolean

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

    Returns

    This instance.

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

    Returns

    This instance.

    Parameters

    • array: number[]

      The source array.

    • Optional offset: number

      (Optional) offset into the array. Default is 0.

    Returns Vector4

  • Get the componet referenced by index. 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.

    Returns

    This instance.

    Parameters

    • index: number

      0, 1 or 2.

    Returns number

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

    Returns

    The Euclidean length

    Returns number

  • 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

    The length squared.

    Returns number

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

    Returns

    This instance.

    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.

    Returns

    This instance.

    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

  • If this vector's x, y, z or w value is less than v's x, y, z or w value, replace that value with the corresponding max value.

    Returns

    This instance.

    Parameters

    Returns Vector4

  • If this vector's x, y, z or w value is greater than v's x, y, z or w value, replace that value with the corresponding min value.

    Returns

    This instance.

    Parameters

    Returns Vector4

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

    Returns

    This instance.

    Returns Vector4

  • Sets each component of this vector to a pseudo-random value between 0 and 1, excluding 1.

    Returns

    This instance.

    Returns Vector4

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

    Returns

    This instance.

    Returns Vector4

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

    Returns

    This instance.

    Returns Vector4

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

    Returns

    This instance.

    Parameters

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

    Returns Vector4

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

    Returns

    This instance.

    Parameters

    Returns Vector4

  • Sets the x, y and z to the axis of rotation and w to the angle.

    Returns

    This instance.

    Parameters

    • m: Matrix4

      A Matrix4 of which the upper left 3x3 matrix is a pure rotation matrix.

    Returns Vector4

  • Set the componet referenced by index. 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.

    Returns

    This instance.

    Parameters

    • index: number

      0, 1 or 2.

    • value: number

      THe new component value

    Returns Vector4

  • Sets this vector to a vector with the same direction as this one, but length l.

    Returns

    This instance.

    Parameters

    • length: number

      The new length.

    Returns Vector4

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

    Returns

    This instance.

    Parameters

    • scalar: number

    Returns Vector4

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

    Returns

    This instance.

    Parameters

    • s: number

      The scalar

    Returns Vector4

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

    Returns

    The array.

    Parameters

    • Optional array: number[]

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

    • Optional offset: number

      (optional) optional offset into the array.

    Returns number[]