Class Quat

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

Implements

  • V4Q

Constructors

  • Parameters

    • Rest...args: number[]

    Returns Quat

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 normalW(): number
  • Getters and setters

    Returns number

  • get w(): number
  • Returns number

  • set w(w): void
  • Parameters

    • w: 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 ww(): any
  • (getter/sette) Swizzle WW

    Returns any

  • set ww(v): void
  • Parameters

    • v: any

    Returns void

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

    Returns any

  • set wx(v): void
  • Parameters

    • v: any

    Returns void

  • get wxyz(): any
  • (getter/sette) Swizzle XYZW

    Returns any

  • set wxyz(v): void
  • Parameters

    • v: any

    Returns void

  • get wy(): any
  • (getter/sette) Swizzle WY

    Returns any

  • set wy(v): void
  • Parameters

    • v: any

    Returns void

  • get wz(): any
  • (getter/sette) Swizzle WZ

    Returns any

  • set wz(v): void
  • Parameters

    • v: any

    Returns void

  • get x(): number
  • Returns number

  • set x(x): void
  • Parameters

    • x: number

    Returns void

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

    Returns any

  • set xw(v): void
  • Parameters

    • v: any

    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 YZX

    Returns any

  • set xyz(v): void
  • Parameters

    • v: any

    Returns void

  • get xyzw(): any
  • (getter/sette) Swizzle XYZW

    Returns any

  • set xyzw(v): void
  • Parameters

    • v: any

    Returns void

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

    Returns any

  • set xz(v): void
  • Parameters

    • v: any

    Returns void

  • get y(): number
  • Returns number

  • set y(y): void
  • Parameters

    • y: number

    Returns void

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

    Returns any

  • set yw(v): void
  • Parameters

    • v: any

    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 yzwx(): any
  • (getter/sette) Swizzle XYZW

    Returns any

  • set yzwx(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 zw(): any
  • (getter/sette) Swizzle XY

    Returns any

  • set zw(v): void
  • Parameters

    • v: any

    Returns void

  • get zwxy(): any
  • (getter/sette) Swizzle XYZW

    Returns any

  • set zwxy(v): void
  • Parameters

    • v: any

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

    • q: V4Q

    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

    • Rest...args: number[]

    Returns V4Q

  • Parameters

    • q: any

    Returns Quat

  • 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
    • rad: number

    Returns V4Q

  • Parameters

    • origin: V4Q
    • radian: number

    Returns V4Q

  • Parameters

    • origin: V4Q
    • rad: number

    Returns V4Q

  • Parameters

    • origin: V4Q
    • radian: number

    Returns V4Q

  • Parameters

    • origin: V4Q
    • rad: 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

  • Returns a string representation of an object.

    Returns string

  • Parameters

    • m: any

    Returns V4Q

  • Parameters

    • m: any

    Returns V4Q

  • Parameters

    • q: any

    Returns V4Q

  • Parameters

    • q: any

    Returns V4Q

  • Creates a quaternion from a given axis and rotation

    Parameters

    • axis: Vec3

      the axis around which to rotate

    • rad: number

      the angle in radians

    Returns Quat

  • Parameters

    • euler: any
    • Optionalorder: string

    Returns void | Quat

  • Parameters

    • a: any
    • b: any

    Returns number

  • Iterpolates a provided anonymous value into a vew Vec4

    Parameters

    • v: any

      The value to interpolate

    Returns Vec4

    out

  • Performs a linear interpolation between two Vec4's

    Parameters

    • v1: any

      the first operand

    • v2: any

      the second operand

    • d: any

      interpolation amount in the range of 0 - 1

    Returns Vec4