wtc-math
    Preparing search index...

    Class Vec4

    A basic 3D Vector class that provides simple algebraic functionality in the form of 3D Vectors.

    We use Getters/setters for both principle properties (x & y) as well as virtual properties (rotation, length etc.).

    Vec4

    Liam Egan liam@wethecollective.com

    1.0.0

    Jan 07, 2020

    Hierarchy (View Summary)

    Implements

    • V4Q
    Index

    Constructors

    • The Vector Class constructor

      Parameters

      • ...args: number[]

      Returns Vec4

    Accessors

    • get area(): number

      (getter) Vector area.

      Returns number

    • get array(): number[]

      (getter) Returns the basic array representation of this vector.

      Returns number[]

    • get depth(): number

      Returns number

    • set depth(h: number): void

      (getter/setter) Vector height. Alias of Vector#x x

      Parameters

      • h: number

      Returns void

    • get height(): number

      Returns number

    • set height(h: number): void

      (getter/setter) Vector height. Alias of Vector#x x

      Parameters

      • h: number

      Returns void

    • get length(): number

      Returns number

    • set length(length: number): void

      (getter/setter) The length of the vector

      Parameters

      • length: number

      Returns void

      0
      
    • get lengthSquared(): number

      Returns number

    • set lengthSquared(length: number): void

      (getter/setter) The length of the vector presented as a square. If you're using length for comparison, this is quicker.

      Parameters

      • length: number

      Returns void

      0
      
    • get w(): number

      Returns number

    • set w(w: number): void

      Parameters

      • w: number

      Returns void

    • get width(): number

      Returns number

    • set width(w: number): void

      (getter/setter) Vector width. Alias of Vector#x x

      Parameters

      • w: number

      Returns void

    • get x(): number

      Returns number

    • set x(x: number): void

      Parameters

      • x: number

      Returns void

    • get y(): number

      Returns number

    • set y(y: number): void

      Parameters

      • y: number

      Returns void

    • get z(): number

      Returns number

    • set z(z: number): void

      Parameters

      • z: number

      Returns void

    Methods

    • Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

      Returns {
          next(): | { done: boolean; value: number }
          | { done: boolean; value?: undefined };
      }

    • Adds one vector to another.

      Parameters

      • vector: V4Q

        The vector to add to this one

      Returns V4Q

      Returns itself, modified

    • Clones the vector and adds the vector to it instead

      Parameters

      • vector: V4Q

        The vector to add to this one

      Returns V4Q

      Returns the clone of itself, modified

    • Adds a scalar to the vector, modifying both the x and y

      Parameters

      • scalar: number

        The scalar to add to the vector

      Returns V4Q

      Returns itself, modified

    • Clones the vector and adds the scalar to it instead

      Parameters

      • scalar: number

        The scalar to add to the vector

      Returns V4Q

      Returns the clone of itself, modified

    • Returns V4Q

    • Returns V4Q

    • Clones the vector

      Returns V4Q

      The cloned vector

    • Calculates the cross product between this and two other supplied vectors

      Parameters

      • v: V4Q
      • w: V4Q

      Returns V4Q

      The cross product of the two vectors

      // returns -2
      new Vector(2, -3).cross(new Vector(-4, 2))
      new Vector(-4, 2).cross(new Vector(2, -3))
      // returns 2
      new Vector(2, -4).cross(new Vector(-3, 2))
    • Parameters

      • v: V4Q
      • w: V4Q

      Returns V4Q

    • Calculates the distance between this and the supplied vector

      Parameters

      • vector: V4Q

        The vector to calculate the distance from

      Returns number

      The distance between this and the supplied vector

    • Calculated the distance on the W axis between this and the supplied vector

      Parameters

      • vector: V4Q

        The vector to calculate the distance from

      Returns number

      The distance, along the y axis, between this and the supplied vector

    • Calculates the distance on the X axis between this and the supplied vector

      Parameters

      • vector: V4Q

        The vector to calculate the distance from

      Returns number

      The distance, along the x axis, between this and the supplied vector

    • Calculated the distance on the Y axis between this and the supplied vector

      Parameters

      • vector: V4Q

        The vector to calculate the distance from

      Returns number

      The distance, along the y axis, between this and the supplied vector

    • Calculated the distance on the Z axis between this and the supplied vector

      Parameters

      • vector: V4Q

        The vector to calculate the distance from

      Returns number

      The distance, along the y axis, between this and the supplied vector

    • Divides one vector by another.

      Parameters

      • vector: V4Q

        The vector to divide this by

      Returns V4Q

      Returns itself, modified

    • Clones the vector and divides it by the vector instead

      Parameters

      • vector: V4Q

        The vector to divide the clone by

      Returns V4Q

      Returns the clone of itself, modified

    • Divides the vector by a scalar.

      Parameters

      • scalar: number

        The scalar to divide both x and y by

      Returns V4Q

      Returns itself, modified

    • Clones the vector and divides it by the provided scalar.

      Parameters

      • scalar: number

        The scalar to divide both x and y by

      Returns V4Q

      Returns the clone of itself, modified

    • Calculates the dot product between this and a supplied vector

      Parameters

      • vector: V4Q

        The vector object against which to calculate the dot product

      Returns number

      The dot product of the two vectors

      // returns -14
      new Vector(2, -3).dot(new Vector(-4, 2))
      new Vector(-4, 2).dot(new Vector(2, -3))
      new Vector(2, -4).dot(new Vector(-3, 2))
    • Returns V4Q

    • Returns V4Q

    • Returns V4Q

    • Returns V4Q

    • Inverses the vector.

      Returns V4Q

      Returns itself, modified

    • Clones the vector and then inverses it.

      Returns V4Q

      Returns itself, modified

    • Multiplies one vector by another.

      Parameters

      • vector: V4Q

        The vector to multiply this by

      Returns V4Q

      Returns itself, modified

    • Clones the vector and multiplies it by the vector instead

      Parameters

      • q: V4Q

      Returns V4Q

      Returns the clone of itself, modified

    • Multiplies the vector by a scalar.

      Parameters

      • scalar: number

        The scalar to multiply both x and y by

      Returns V4Q

      Returns itself, modified

    • Clones the vector and multiplies it by the provided scalar.

      Parameters

      • scalar: number

        The scalar to multiply both x and y by

      Returns V4Q

      Returns the clone of itself, modified

    • Negates the vector.

      Returns V4Q

      Returns itself, modified

    • Clones the vector and negates it.

      Returns V4Q

      Returns itself, modified

    • Normalises the vector down to a length of 1 unit

      Returns V4Q

      Returns itself, modified

    • Clones the vector and normalises it

      Returns V4Q

      Returns a clone of itself, modified

    • Resets the vector coordinates

      Parameters

      • ...args: number[]

      Returns V4Q

    • Resets the vector coordinates to another vector object

      Parameters

      • v: V4Q

        The vector object to use to reset the coordinates

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Parameters

      • origin: V4Q
      • radian: number

      Returns V4Q

    • Returns V4Q

    • Returns V4Q

    • Alias of Vector#multiplyScalar__anchor multiplyScalar

      Parameters

      • scalar: number

      Returns V4Q

    • Alias of Vector#multiplyScalarNew__anchor multiplyScalarNew

      Parameters

      • scalar: number

      Returns V4Q

    • Subtracts one vector from another.

      Parameters

      • vector: V4Q

        The vector to subtract from this one

      Returns V4Q

      Returns itself, modified

    • Clones the vector and subtracts the vector from it instead

      Parameters

      • vector: V4Q

        The vector to subtract from this one

      Returns V4Q

      Returns the clone of itself, modified

    • Subtracts a scalar from the vector, modifying both the x and y

      Parameters

      • scalar: number

        The scalar to subtract from the vector

      Returns V4Q

      Returns itself, modified

    • Clones the vector and subtracts the scalar from it instead

      Parameters

      • scalar: number

        The scalar to add to the vector

      Returns V4Q

      Returns the clone of itself, modified

    • Iterpolates a provided anonymous value into a vew Vec4

      Parameters

      • v: string | number | Vec4Like

        The value to interpolate

      Returns Vec4

      out

    • Performs a linear interpolation between two Vec4's

      Parameters

      • v1: Vec4

        the first operand

      • v2: Vec4

        the second operand

      • d: number

        interpolation amount in the range of 0 - 1

      Returns Vec4