dot big bang

Developer API
Menu

Class Vector3

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Vector3

Index

Constructors

constructor

  • new Vector3(x?: number, y?: number, z?: number): Vector3
  • Creates a new Vector3

    Parameters

    • Optional x: number

      The x component of the vector. Default is 0.

    • Optional y: number

      The y component of the vector. Default is 0.

    • Optional z: number

      The z component of the vector. Default is 0.

    Returns Vector3

Properties

x

x: number

The x component of the vector.

y

y: number

The y component of the vector.

z

z: number

The z component of the vector.

Methods

add

  • Adds the vector v to this vector.

    Parameters

    • v: Vector3

      The vector to add to this one.

    Returns Vector3

addScalar

  • Adds the scalar value s to the x, y and z components of this vector.

    Parameters

    • s: number

      The scalar value to add.

    Returns Vector3

addScaledVector

  • Adds the vector v multiplied by the scalar s to this vector.

    Parameters

    • v: Vector3

      The vector to scale by s and add to this vector.

    • s: number

      The scale factor to apply to v before adding it to this vector.

    Returns Vector3

addVectors

  • Sets this vector to a + b.

    Parameters

    • a: Vector3

      The vector to add to b before setting the result to this vector.

    • b: Vector3

      The vector to add to a before setting the result to this vector.

    Returns Vector3

angleTo

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

    Parameters

    • v: Vector3

      The second vector to calculate the angle to (the first one being this vector).

    Returns number

applyAxisAngle

  • Applies a rotation specified by an axis and an angle to this vector.

    Parameters

    • axis: Vector3

      The normalized axis vector of rotation.

    • angle: number

      The angle of rotation in radians.

    Returns Vector3

applyEuler

  • Applies the euler transform to this vector by converting the Euler object to a quaternion and applying it.

    Parameters

    • euler: Euler

      The euler transform to apply to this vector.

    Returns Vector3

applyMatrix3

  • Multiplies this vector by m.

    Parameters

    • m: Matrix3

      The matrix to apply to this vector.

    Returns Vector3

applyMatrix4

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

    Parameters

    • m: Matrix4

      The matrix to apply to this vector.

    Returns Vector3

applyProjection

  • Multiplies this vector and m, and divides by perspective.

    Parameters

    • m: Matrix4

      The matrix to multiply this vector with.

    Returns Vector3

applyQuaternion

  • Applies the quaternion transform q to this vector.

    Parameters

    Returns Vector3

ceil

  • Rounds this vector's components up to the nearest integer value.

    Returns Vector3

clamp

  • 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 vector with the minimum x, y and z values used for clamping this vector.

    • max: Vector3

      The vector with the maximum x, y and z values used for clamping this vector.

    Returns Vector3

clampLength

  • clampLength(min: number, max: number): 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

clampScalar

  • clampScalar(minVal: number, maxVal: number): Vector3
  • If this vector's x, y or z values are greater than the max value, they are replaced by the maxVal value. If this vector's x, y or z values are less than the min value, they are replaced by the minVal value.

    Parameters

    • minVal: number

      The minimum value used for clamping this vector.

    • maxVal: number

      The maximum value used for clamping this vector.

    Returns Vector3

clone

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

    Returns Vector3

copy

  • Copies the provided vector v into this one.

    Parameters

    Returns Vector3

cross

  • Sets this vector to the cross product of itself and v.

    Parameters

    • v: Vector3

      The second vector to calculate the cross product from (the first one being this vector).

    Returns Vector3

crossVectors

  • Sets this vector to the cross product of a and b.

    Parameters

    • a: Vector3

      The first vector to calculate the cross product from.

    • b: Vector3

      The second vector to calculate the cross product from.

    Returns Vector3

distanceTo

  • Calculates the distance from this vector to v.

    Parameters

    • v: Vector3

      The second vector to calculate the distance to (the first one being this vector).

    Returns number

distanceToSquared

  • distanceToSquared(v: Vector3): number
  • Calculates 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

    • v: Vector3

      The second to calculate the squared distance to (the first one being this vector).

    Returns number

divide

  • Divides this vector by the other vector v. Each component of this vector is divided by the corresponding one of v.

    Parameters

    • v: Vector3

      The vector to divide this one with.

    Returns Vector3

divideScalar

  • Divides this vector by the scalar s. Each component of this vector is divided by the same value s. Set this vector to (0, 0, 0) if s == 0.

    Parameters

    • s: number

      The value to divide each component of this vector with.

    Returns Vector3

dot

  • Calculates the dot product of this vector and v.

    Parameters

    • v: Vector3

      The other vector to calculate the dot product with.

    Returns number

equals

  • Checks for strict equality of this vector and v.

    Parameters

    • v: Vector3

      The other vector to compare this one to.

    Returns boolean

floor

  • Rounds this vector's components down to the nearest integer value.

    Returns Vector3

fromArray

  • fromArray(array: number[], offset?: number): Vector3
  • 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: number[]

      The array of format [x, y, z] used to construct this vector.

    • Optional offset: number

      An offset into the array from where to start reading the components.

    Returns Vector3

getComponent

  • getComponent(index: number): number
  • Gets the value of the index-th component of the vector. Index 0 corresponds to the x component, 1 is y and 2 is z.

    Parameters

    • index: number

      The index (0, 1 or 2) of the component to get.

    Returns number

length

  • length(): number
  • Computes the Euclidean length (straight-line length) from (0, 0, 0) to this vector's (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

lengthManhattan

  • lengthManhattan(): number

lengthSq

  • lengthSq(): number
  • Computes the square of the Euclidean length (straight-line length) from (0, 0, 0) to this vector's (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

lerp

  • Linearly interpolates between this vector and v by alpha amount (alpha=0 returns this vector, while alpha=1 returns v) and stores the result into this vector.

    Parameters

    • v: Vector3

      The vector to interpolate this one towards.

    • alpha: number

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

    Returns Vector3

lerpVectors

  • Linearly interpolates between v1 and v2 by alpha amount (alpha=0 returns v1, while alpha=1 returns v2) and stores the result into this vector.

    Parameters

    • v1: Vector3

      The starting vector (returned when alpha equals 0).

    • v2: Vector3

      The vector to interpolate towards (returned when alpha equals 1).

    • alpha: number

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

    Returns Vector3

max

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

    Parameters

    Returns Vector3

min

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

    Parameters

    • v: Vector3

      The vector with the values to compare to.

    Returns Vector3

multiply

  • Multiplies this vector by the vector w. Each component of this vector is multiplied by the corresponding one of w.

    Parameters

    • w: Vector3

      The vector to multiply to this one.

    Returns Vector3

multiplyScalar

  • multiplyScalar(s: number): Vector3
  • Multiplies this vector by the scalar s. Each component of this vector is multiplied by the same value s.

    Parameters

    • s: number

      The value to multiply each component of this vector by.

    Returns Vector3

multiplyVectors

  • Sets this vector to a * b, component-wise.

    Parameters

    • a: Vector3

      The vector t multiply b with before setting the result into this vector.

    • b: Vector3

      The vector to multiply a with before setting the result into this vector.

    Returns Vector3

negate

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

    Returns Vector3

normalize

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

    Returns Vector3

projectOnPlane

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

    Parameters

    • planeNormal: Vector3

      The normal of the plane on which to project this vector.

    Returns Vector3

projectOnVector

  • Projects this vector onto v.

    Parameters

    • vector: Vector3

      The vector on which to calculate the projection of this one.

    Returns Vector3

reflect

  • Reflects this vector off of the plane orthogonal to normal (and passing through the origin). Normal is assumed to have unit length.

    Parameters

    • normal: Vector3

      The normal to the reflecting plane.

    Returns Vector3

round

  • Rounds this vector's components to the nearest integer value.

    Returns Vector3

roundToZero

  • Rounds this vector's components towards zero (up if negative, down if positive) to an integer value.

    Returns Vector3

set

  • set(x: number, y: number, z: number): Vector3
  • Sets the x, y, z components of this vector to the provided ones.

    Parameters

    • x: number

      The x component of the vector.

    • y: number

      The y component of the vector.

    • z: number

      The z component of the vector.

    Returns Vector3

setComponent

  • setComponent(index: number, value: number): void
  • Sets the index-th component of this vector to the provided value. Index 0 corresponds to the x component, 1 is y and 2 is z.

    Parameters

    • index: number

      The index (0, 1 or 2) of the component to set.

    • value: number

      The value to set the component of this vector to.

    Returns void

setFromMatrixColumn

  • Sets this vector's x, y and z components from the index-th column of matrix.

    Parameters

    • m: Matrix4

      The matrix which column is used to set this vector.

    • index: number

      The index (0, 1 or 2) of the column in matrix m to use to set this vector.

    Returns Vector3

setFromMatrixPosition

  • Sets this vector to the position elements of the transformation matrix m.

    Parameters

    • m: Matrix4

      The transformation matrix which position elements are used to set this vector.

    Returns Vector3

setFromMatrixScale

setFromSpherical

  • Sets this vector from the spherical coordinates s.

    Parameters

    • s: Spherical

      The spherical coordinates to set this vector from.

    Returns Vector3

setLength

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

    Parameters

    • l: number

      The length to set this vector to.

    Returns Vector3

setScalar

  • setScalar(scalar: number): Vector3
  • Sets the x, y, z components of this vector to the same scalar value.

    Parameters

    • scalar: number

      The value to set all the components of this vector to.

    Returns Vector3

setX

  • Sets this vector's x component to the provided value.

    Parameters

    • x: number

      The value to set the x component to.

    Returns Vector3

setY

  • Sets this vector's y component to the provided value.

    Parameters

    • y: number

      The value to set the y component to.

    Returns Vector3

setZ

  • Sets this vector's z component to the provided value.

    Parameters

    • z: number

      The value to set the z component to.

    Returns Vector3

sub

  • Subtracts the vector v from this vector.

    Parameters

    • v: Vector3

      The vector to subtract from this vector.

    Returns Vector3

subScalar

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

    Parameters

    • s: number

      The value to subtract to the x, y and z components of this vector.

    Returns Vector3

subVectors

  • Sets this vector to a - b.

    Parameters

    • a: Vector3

      The vector from which b is subtracted before setting the result to this vector.

    • b: Vector3

      The vector to subtract from a before setting the result to this vector.

    Returns Vector3

toArray

  • toArray(array?: number[], offset?: number): number[]
  • Returns the components of this vector in an array of format [x, y, z].

    Parameters

    • Optional array: number[]

      The array to store the compoments of the vector in. If not specified, a new array will be created.

    • Optional offset: number

      An offset into the array where to write the elements of this vector.

    Returns number[]

transformDirection

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

    Parameters

    • m: Matrix4

      The matrix to transform the direction of this vector with.

    Returns Vector3