Class Vec3

3-dimensional vector

Example

const v = new Vec3(1, 2, 3)
console.log('x=' + v.x) // x=1

Constructors

  • Parameters

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

    Returns Vec3

Properties

x: number
y: number
z: number
UNIT_X: Vec3
UNIT_Y: Vec3
UNIT_Z: Vec3
ZERO: Vec3

Methods

  • Scale a vector and add it to this vector. Save the result in "target". (target = this + vector * scalar)

    Parameters

    • scalar: number
    • vector: Vec3
    • Optional target: Vec3

      The vector to save the result in.

    Returns Vec3

  • Check if a vector equals is almost equal to another one.

    Parameters

    • vector: Vec3
    • Optional precision: number

    Returns boolean

  • Check if a vector is almost zero

    Parameters

    • Optional precision: number

    Returns boolean

  • Clone the vector

    Returns Vec3

  • Copies value of source to this vector.

    Parameters

    Returns Vec3

  • Vector cross product

    Parameters

    • vector: Vec3
    • Optional target: Vec3

      Optional target to save in.

    Returns Vec3

  • Get squared distance from this point to another point

    Parameters

    Returns number

  • Get distance from this point to another point

    Parameters

    Returns number

  • Calculate dot product

    Parameters

    Returns number

  • Check if the vector is anti-parallel to another vector.

    Parameters

    • vector: Vec3
    • Optional precision: number

      Set to zero for exact comparisons

    Returns boolean

  • Returns boolean

  • Get the length of the vector

    Returns number

  • Get the squared length of the vector.

    Returns number

  • Do a linear interpolation between two vectors

    Parameters

    • vector: Vec3
    • t: number

      A number between 0 and 1. 0 will make this function return u, and 1 will make it return v. Numbers in between will generate a vector in between them.

    • target: Vec3

    Returns void

  • Make the vector point in the opposite direction.

    Parameters

    • Optional target: Vec3

      Optional target to save in

    Returns Vec3

  • Normalize the vector. Note that this changes the values in the vector.

    Returns number

    Returns the norm of the vector

  • Multiply all the components of the vector with a scalar.

    Parameters

    • scalar: number
    • Optional target: Vec3

      The vector to save the result in.

    Returns Vec3

  • Set the vectors' 3 elements

    Parameters

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

    Returns Vec3

  • Set all components of the vector to zero.

    Returns void

  • Compute two artificial tangents to the vector

    Parameters

    • t1: Vec3

      Vector object to save the first tangent in

    • t2: Vec3

      Vector object to save the second tangent in

    Returns void

  • Converts to an array

    Returns [number, number, number]

  • Converts to a more readable format

    Returns string

  • Get the version of this vector that is of length 1.

    Parameters

    • Optional target: Vec3

      Optional target to save in

    Returns Vec3

    Returns the unit vector

  • Vector addition

    Parameters

    Returns Vec3

  • Parameters

    Returns void

  • Multiply the vector with an other vector, component-wise.

    Parameters

    • vector: Vec3
    • Optional target: Vec3

      The vector to save the result in.

    Returns Vec3

  • Vector subtraction

    Parameters

    Returns Vec3

  • Parameters

    Returns void