Vector3

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

Core Class

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

Implements

  • Vector

Constructors

  • Parameters

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

    Returns Vector3

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.

isVector3: boolean

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

Methods

  • If NaN exists in three elements, return true.

    Returns boolean

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

    Parameters

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

    Returns Vector3

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

    Parameters

    • scalar: number

    Returns Vector3

  • Replace this vector's x value with x.

    Parameters

    • x: number

    Returns Vector3

  • Replace this vector's y value with y.

    Parameters

    • y: number

    Returns Vector3

  • Replace this vector's z value with z.

    Parameters

    • z: number

    Returns Vector3

  • If index equals 0 set x to Float| value. If index equals 1 set y to Float| value. If index equals 2 set z to Float| value.

    Parameters

    • index: number
    • value: number

    Returns Vector3

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

    Parameters

    • index: number

      0, 1 or 2.

    Returns number

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

    Returns Vector3

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

  • Copies the values of the passed vector3's x, y and z properties to this vector3.

    Parameters

    Returns Vector3

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

    Parameters

    • s: number

    Returns Vector3

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

    Parameters

    • s: number

    Returns Vector3

  • Multiplies this vector by scalar s.

    Parameters

    • scalar: number

    Returns Vector3

  • Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.

    Parameters

    Returns Vector3

  • Projects this vector from world space into the camera's normalized device coordinate (NDC) space.

    Parameters

    • camera: Camera3D

      camera to use in the projection.

    Returns Vector3

  • Projects this vector from the camera's normalized device coordinate (NDC) space into world space.

    Parameters

    • camera: Camera3D

      camera to use in the projection.

    Returns Vector3

  • Transforms the direction of this vector by a matrix (the upper left 3 x 3 subset of a m) and then normalizes the result.

    Parameters

    Returns Vector3

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

    Parameters

    • scalar: number

    Returns Vector3

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

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

    Parameters

    Returns Vector3

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

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

    Parameters

    Returns Vector3

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

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

    Parameters

    • min: Vector3

      the minimum x, y and z values.

    • max: Vector3

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

    Returns Vector3

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

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

    Parameters

    • minVal: number
    • maxVal: number

    Returns Vector3

  • If this vector's length is greater than the max value, the vector will be scaled down so its length is the max value.

    If this vector's length is less than the min value, the vector will be scaled up so its length is the min value.

    Parameters

    • min: number

      the minimum value the length will be clamped to.

    • max: number

      the maximum value the length will be clamped to.

    Returns Vector3

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

    Returns Vector3

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

    Returns Vector3

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

    Returns Vector3

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

    Returns Vector3

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

    Returns Vector3

  • Calculate the dot product of this vector and v.

    Parameters

    Returns number

  • Computes the square of the Euclidean length (straight-line length) from (0, 0, 0) to (x, y, z). 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) to (x, y, z).

    Returns number

  • Computes the Manhattan length of this vector.

    Returns number

  • Convert 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 Vector3

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

    Parameters

    • length: number

    Returns Vector3

  • Linearly interpolate 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: Vector3

      Vector3 to interpolate towards.

    • alpha: number

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

    Returns Vector3

  • 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: Vector3

      the starting Vector3.

    • v2: Vector3

      Vector3 to interpolate towards.

    • alpha: number

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

    Returns Vector3

  • Projects this vector onto a plane by subtracting this vector projected onto the plane's normal from this vector.

    Parameters

    • planeNormal: Vector3

      A vector representing a plane normal.

    Returns Vector3

  • Reflect this vector off of plane orthogonal to normal. Normal is assumed to have unit length.

    Parameters

    • normal: Vector3

      the normal to the reflecting plane.

    Returns Vector3

  • Returns the angle between this vector and vector v in radians.

    Parameters

    Returns number

  • Computes the distance from this vector to v.

    Parameters

    Returns number

  • Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, you should compare the distance squared instead as it is slightly more efficient to calculate.

    Parameters

    Returns number

  • Sets this vector from the spherical coordinates Spherical| s.

    Parameters

    • s: Spherical

    Returns Vector3

  • Sets this vector from the spherical coordinates Spherical| radius, Spherical| phi and Spherical| theta.

    Parameters

    • radius: number
    • phi: number
    • theta: number

    Returns Vector3

  • Sets this vector from the cylindrical coordinates Cylindrical| c.

    Parameters

    • c: Cylindrical

    Returns Vector3

  • Sets this vector from the cylindrical coordinates Cylindrical| radius, Cylindrical| theta and Cylindrical| y.

    Parameters

    • radius: number
    • theta: number
    • y: number

    Returns Vector3

  • Sets this vector's x, y and z components from Integer| index column of matrix.

    Parameters

    Returns Vector3

  • Checks for strict equality of this vector and v.

    Parameters

    Returns boolean

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

    Parameters

    • array: ArrayLike<number>

      the source array.

    • offset: number

      ( optional) offset into the array.

    Returns Vector3

  • There are 3 elements in this vector.

    Returns number

  • Returns an array [x, y, z], or copies x, y and z 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[]