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

Constructors

  • The Vector Class constructor

    Parameters

    • Rest...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): void
  • (getter/setter) Vector height. Alias of Vector#x x

    Parameters

    • h: number

    Returns void

  • get height(): number
  • Returns number

  • set height(h): void
  • (getter/setter) Vector height. Alias of Vector#x x

    Parameters

    • h: number

    Returns void

  • get length(): number
  • Returns number

  • set length(length): void
  • (getter/setter) The length of the vector

    Parameters

    • length: number

    Returns void

    0
    
  • get lengthSquared(): number
  • Returns number

  • set lengthSquared(length): 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): 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): 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): 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): void
  • (getter/setter) Vector width. Alias of Vector#x x

    Parameters

    • w: number

    Returns void

  • get x(): number
  • Returns number

  • set x(x): void
  • Parameters

    • x: number

    Returns void

  • get xx(): any
  • (getter/sette) Swizzle XX

    Returns any

  • set xx(v): void
  • Parameters

    • v: any

    Returns void

  • get xy(): any
  • (getter/sette) Swizzle XY

    Returns any

  • set xy(v): void
  • Parameters

    • v: any

    Returns void

  • get xyz(): any
  • (getter/sette) Swizzle XYZ

    Returns any

  • set xyz(v): void
  • Parameters

    • v: any

    Returns void

  • get y(): number
  • Returns number

  • set y(y): void
  • Parameters

    • y: number

    Returns void

  • get yx(): any
  • (getter/sette) Swizzle YX

    Returns any

  • set yx(v): void
  • Parameters

    • v: any

    Returns void

  • get yy(): any
  • (getter/sette) Swizzle YY

    Returns any

  • set yy(v): void
  • Parameters

    • v: any

    Returns void

  • get yz(): any
  • (getter/sette) Swizzle YZ

    Returns any

  • set yz(v): void
  • Parameters

    • v: any

    Returns void

  • get yzx(): any
  • (getter/sette) Swizzle YZX

    Returns any

  • set yzx(v): void
  • Parameters

    • v: any

    Returns void

  • get z(): number
  • Returns number

  • set z(z): void
  • Parameters

    • z: number

    Returns void

  • get zx(): any
  • (getter/sette) Swizzle zx

    Returns any

  • set zx(v): void
  • Parameters

    • v: any

    Returns void

  • get zxy(): any
  • (getter/sette) Swizzle ZXY

    Returns any

  • set zxy(v): void
  • Parameters

    • v: any

    Returns void

  • get zy(): any
  • (getter/sette) Swizzle ZY

    Returns any

  • set zy(v): void
  • Parameters

    • v: any

    Returns void

  • get zz(): any
  • (getter/sette) Swizzle ZZ

    Returns any

  • set zz(v): void
  • Parameters

    • v: any

    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;
        };
    }

    • next:function
      • Returns {
            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

  • Returns Vec3

  • Returns Vec3

  • Clones the vector

    Returns Vec3

    The cloned vector

  • 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))
  • Parameters

    Returns Vec3

  • 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))
  • Returns Vec3

  • Returns Vec3

  • Returns Vec3

  • Returns Vec3

  • 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

    • Rest...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

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Parameters

    • origin: Vec3
    • radian: number

    Returns Vec3

  • Returns Vec3

  • 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

  • Parameters

    • m: any

    Returns Vec3

  • Parameters

    • m: any

    Returns Vec3

  • Parameters

    • m: any

    Returns Vec3

  • Parameters

    • m: any

    Returns Vec3

  • Parameters

    • q: any

    Returns Vec3

  • Parameters

    • q: any

    Returns Vec3

  • Parameters

    • m: any
    • Optionalorder: String

    Returns void | Vec3

  • Parameters

    Returns number

  • Iterpolates a provided anonymous value into a vew Vec3

    Parameters

    • v: any

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

      interpolation amount in the range of 0 - 1

    Returns Vec3