wtc-math
    Preparing search index...

    Class Vec3

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

    Vec3

    Liam Egan liam@wethecollective.com

    1.0.0

    Jan 07, 2020

    Index

    Constructors

    • The Vector Class constructor

      Parameters

      • ...args: number[]

      Returns Vec3

    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 phi(): number

      Returns number

    • set phi(p: number): void

      (getter/setter) Spherical phi. For using a vec3 as spherical coordinates. Alias of Vector#y y

      Parameters

      • p: number

      Returns void

    • get radius(): number

      Returns number

    • set radius(s: number): void

      (getter/setter) Spherical radius. For using a vec3 as spherical coordinates. Alias of Vector#x x

      Parameters

      • s: number

      Returns void

    • get theta(): number

      Returns number

    • set theta(t: number): void

      (getter/setter) Spherical theta. For using a vec3 as spherical coordinates. Alias of Vector#z z

      Parameters

      • t: 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: Vec3

        The vector to add to this one

      Returns Vec3

      Returns itself, modified

    • Clones the vector and adds the vector to it instead

      Parameters

      • vector: Vec3

        The vector to add to this one

      Returns Vec3

      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 Vec3

      Returns itself, modified

    • Clones the vector and adds the scalar to it instead

      Parameters

      • scalar: number

        The scalar to add to the vector

      Returns Vec3

      Returns the clone of itself, modified

    • Calculates the cross product between this and the supplied vector.

      Parameters

      • vector: Vec3

        The vector object against which to calculate the cross product

      Returns Vec3

      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))
    • Calculates the distance between this and the supplied vector

      Parameters

      • vector: Vec3

        The vector to calculate the distance from

      Returns number

      The distance between this and the supplied vector

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

      Parameters

      • vector: Vec3

        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: Vec3

        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: Vec3

        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: Vec3

        The vector to divide this by

      Returns Vec3

      Returns itself, modified

    • Clones the vector and divides it by the vector instead

      Parameters

      • vector: Vec3

        The vector to divide the clone by

      Returns Vec3

      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 Vec3

      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 Vec3

      Returns the clone of itself, modified

    • Calculates the dot product between this and a supplied vector

      Parameters

      • vector: Vec3

        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))
    • Inverses the vector.

      Returns Vec3

      Returns itself, modified

    • Clones the vector and then inverses it.

      Returns Vec3

      Returns itself, modified

    • Multiplies one vector by another.

      Parameters

      • vector: Vec3

        The vector to multiply this by

      Returns Vec3

      Returns itself, modified

    • Clones the vector and multiplies it by the vector instead

      Parameters

      • vector: Vec3

        The vector to multiply the clone by

      Returns Vec3

      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 Vec3

      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 Vec3

      Returns the clone of itself, modified

    • Negates the vector.

      Returns Vec3

      Returns itself, modified

    • Clones the vector and negates it.

      Returns Vec3

      Returns itself, modified

    • Normalises the vector down to a length of 1 unit

      Returns Vec3

      Returns itself, modified

    • Clones the vector and normalises it

      Returns Vec3

      Returns a clone of itself, modified

    • Resets the vector coordinates

      Parameters

      • ...args: number[]

      Returns Vec3

    • Resets the vector coordinates to another vector object

      Parameters

      • v: Vec3

        The vector object to use to reset the coordinates

      Returns Vec3

    • Alias of Vector#multiplyScalar__anchor multiplyScalar

      Parameters

      • scalar: number

      Returns Vec3

    • Alias of Vector#multiplyScalarNew__anchor multiplyScalarNew

      Parameters

      • scalar: number

      Returns Vec3

    • Subtracts one vector from another.

      Parameters

      • vector: Vec3

        The vector to subtract from this one

      Returns Vec3

      Returns itself, modified

    • Clones the vector and subtracts the vector from it instead

      Parameters

      • vector: Vec3

        The vector to subtract from this one

      Returns Vec3

      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 Vec3

      Returns itself, modified

    • Clones the vector and subtracts the scalar from it instead

      Parameters

      • scalar: number

        The scalar to add to the vector

      Returns Vec3

      Returns the clone of itself, modified

    • Iterpolates a provided anonymous value into a vew Vec3

      Parameters

      • v: string | number | Vec3Like

        The value to interpolate

      Returns Vec3

      out

    • Performs a linear interpolation between two Vec3's

      Parameters

      • v1: Vec3

        the first operand

      • v2: Vec3

        the second operand

      • d: number

        interpolation amount in the range of 0 - 1

      Returns Vec3