Options
All
  • Public
  • Public/Protected
  • All
Menu

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

author

Liam Egan liam@wethecollective.com

version

1.0.0

created

Jan 07, 2020

Hierarchy

  • Vec3

Index

Constructors

constructor

  • new Vec3(...args: number[]): Vec3
  • The Vector Class constructor

    Parameters

    • Rest ...args: number[]

    Returns Vec3

Properties

Private #x

#x: number = 0

(getter/setter) The x value of the vector.

default

0

Private #y

#y: number = 0

(getter/setter) The y value of the vector.

default

0

Private #z

#z: number = 0

(getter/setter) The y value of the vector.

default

0

Accessors

area

  • get area(): number
  • (getter) Vector area.

    readonly

    Returns number

array

  • get array(): number[]
  • (getter) Returns the basic array representation of this vector.

    readonly

    Returns number[]

depth

  • get depth(): number
  • set depth(h: number): void
  • (getter/setter) Vector height. Alias of {@link Vector#x x}

    Returns number

  • (getter/setter) Vector height. Alias of {@link Vector#x x}

    Parameters

    • h: number

    Returns void

height

  • get height(): number
  • set height(h: number): void
  • (getter/setter) Vector height. Alias of {@link Vector#x x}

    Returns number

  • (getter/setter) Vector height. Alias of {@link Vector#x x}

    Parameters

    • h: number

    Returns void

length

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

    Returns number

  • (getter/setter) The length of the vector

    default

    0

    Parameters

    • length: number

    Returns void

lengthSquared

  • get lengthSquared(): 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.

    Returns number

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

    default

    0

    Parameters

    • length: number

    Returns void

phi

  • get phi(): number
  • set phi(p: number): void
  • (getter/setter) Spherical phi. For using a vec3 as spherical coordinates. Alias of {@link Vector#y y}

    Returns number

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

    Parameters

    • p: number

    Returns void

radius

  • get radius(): number
  • set radius(s: number): void
  • (getter/setter) Spherical radius. For using a vec3 as spherical coordinates. Alias of {@link Vector#x x}

    Returns number

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

    Parameters

    • s: number

    Returns void

theta

  • get theta(): number
  • set theta(t: number): void
  • (getter/setter) Spherical theta. For using a vec3 as spherical coordinates. Alias of {@link Vector#z z}

    Returns number

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

    Parameters

    • t: number

    Returns void

width

  • get width(): number
  • set width(w: number): void
  • (getter/setter) Vector width. Alias of {@link Vector#x x}

    Returns number

  • (getter/setter) Vector width. Alias of {@link Vector#x x}

    Parameters

    • w: number

    Returns void

x

  • get x(): number
  • set x(x: number): void

xx

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

    Returns any

  • (getter/sette) Swizzle XX

    Parameters

    • v: any

    Returns void

xy

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

    Returns any

  • (getter/sette) Swizzle XY

    Parameters

    • v: any

    Returns void

xyz

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

    Returns any

  • (getter/sette) Swizzle XYZ

    Parameters

    • v: any

    Returns void

y

  • get y(): number
  • set y(y: number): void

yx

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

    Returns any

  • (getter/sette) Swizzle YX

    Parameters

    • v: any

    Returns void

yy

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

    Returns any

  • (getter/sette) Swizzle YY

    Parameters

    • v: any

    Returns void

yz

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

    Returns any

  • (getter/sette) Swizzle YZ

    Parameters

    • v: any

    Returns void

yzx

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

    Returns any

  • (getter/sette) Swizzle YZX

    Parameters

    • v: any

    Returns void

z

  • get z(): number
  • set z(z: number): void

zx

  • get zx(): any
  • set zx(v: any): void
  • (getter/sette) Swizzle zx

    Returns any

  • (getter/sette) Swizzle zx

    Parameters

    • v: any

    Returns void

zxy

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

    Returns any

  • (getter/sette) Swizzle ZXY

    Parameters

    • v: any

    Returns void

zy

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

    Returns any

  • (getter/sette) Swizzle ZY

    Parameters

    • v: any

    Returns void

zz

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

    Returns any

  • (getter/sette) Swizzle ZZ

    Parameters

    • v: any

    Returns void

Methods

[iterator]

  • [iterator](): { next: any }
  • Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

    Returns { next: any }

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

add

  • Adds one vector to another.

    chainable

    Parameters

    • vector: Vec3

      The vector to add to this one

    Returns Vec3

    Returns itself, modified

addNew

  • Clones the vector and adds the vector to it instead

    chainable

    Parameters

    • vector: Vec3

      The vector to add to this one

    Returns Vec3

    Returns the clone of itself, modified

addScalar

  • addScalar(scalar: number): Vec3
  • Adds a scalar to the vector, modifying both the x and y

    chainable

    Parameters

    • scalar: number

      The scalar to add to the vector

    Returns Vec3

    Returns itself, modified

addScalarNew

  • addScalarNew(scalar: number): Vec3
  • Clones the vector and adds the scalar to it instead

    chainable

    Parameters

    • scalar: number

      The scalar to add to the vector

    Returns Vec3

    Returns the clone of itself, modified

ceil

ceilNew

clone

  • Clones the vector

    Returns Vec3

    The cloned vector

cross

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

    example

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

    • vector: Vec3

      The vector object against which to calculate the cross product

    Returns Vec3

    The cross product of the two vectors

crossNew

distance

  • distance(vector: Vec3): number
  • 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

distanceX

  • distanceX(vector: Vec3): number
  • 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

distanceY

  • distanceY(vector: Vec3): number
  • 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

distanceZ

  • distanceZ(vector: Vec3): number
  • 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

divide

  • Divides one vector by another.

    chainable

    Parameters

    • vector: Vec3

      The vector to divide this by

    Returns Vec3

    Returns itself, modified

divideNew

  • Clones the vector and divides it by the vector instead

    chainable

    Parameters

    • vector: Vec3

      The vector to divide the clone by

    Returns Vec3

    Returns the clone of itself, modified

divideScalar

  • divideScalar(scalar: number): Vec3
  • Divides the vector by a scalar.

    chainable

    Parameters

    • scalar: number

      The scalar to divide both x and y by

    Returns Vec3

    Returns itself, modified

divideScalarNew

  • divideScalarNew(scalar: number): Vec3
  • Clones the vector and divides it by the provided scalar.

    chainable

    Parameters

    • scalar: number

      The scalar to divide both x and y by

    Returns Vec3

    Returns the clone of itself, modified

dot

  • dot(vector: Vec3): number
  • Calculates the dot product between this and a supplied vector

    example

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

    Parameters

    • vector: Vec3

      The vector object against which to calculate the dot product

    Returns number

    The dot product of the two vectors

floor

floorNew

fract

fractNew

inverse

  • Inverses the vector.

    chainable

    Returns Vec3

    Returns itself, modified

inverseNew

  • inverseNew(): Vec3
  • Clones the vector and then inverses it.

    chainable

    Returns Vec3

    Returns itself, modified

multiply

  • Multiplies one vector by another.

    chainable

    Parameters

    • vector: Vec3

      The vector to multiply this by

    Returns Vec3

    Returns itself, modified

multiplyNew

  • Clones the vector and multiplies it by the vector instead

    chainable

    Parameters

    • vector: Vec3

      The vector to multiply the clone by

    Returns Vec3

    Returns the clone of itself, modified

multiplyScalar

  • multiplyScalar(scalar: number): Vec3
  • Multiplies the vector by a scalar.

    chainable

    Parameters

    • scalar: number

      The scalar to multiply both x and y by

    Returns Vec3

    Returns itself, modified

multiplyScalarNew

  • multiplyScalarNew(scalar: number): Vec3
  • Clones the vector and multiplies it by the provided scalar.

    chainable

    Parameters

    • scalar: number

      The scalar to multiply both x and y by

    Returns Vec3

    Returns the clone of itself, modified

negate

  • Negates the vector.

    chainable

    Returns Vec3

    Returns itself, modified

negateNew

  • Clones the vector and negates it.

    chainable

    Returns Vec3

    Returns itself, modified

normalise

  • Normalises the vector down to a length of 1 unit

    chainable

    Returns Vec3

    Returns itself, modified

normaliseNew

  • normaliseNew(): Vec3
  • Clones the vector and normalises it

    chainable

    Returns Vec3

    Returns a clone of itself, modified

reset

  • reset(...args: number[]): Vec3
  • Resets the vector coordinates

    chainable

    Parameters

    • Rest ...args: number[]

    Returns Vec3

resetToVector

  • Resets the vector coordinates to another vector object

    chainable

    Parameters

    • v: Vec3

      The vector object to use to reset the coordinates

    Returns Vec3

rotateX

  • rotateX(origin: Vec3, radian: number): Vec3

rotateXNew

  • rotateXNew(origin: Vec3, radian: number): Vec3

rotateY

  • rotateY(origin: Vec3, radian: number): Vec3

rotateZ

  • rotateZ(origin: Vec3, radian: number): Vec3

rotateZNew

  • rotateZNew(origin: Vec3, radian: number): Vec3

rotateyNew

  • rotateyNew(origin: Vec3, radian: number): Vec3

round

roundNew

scale

  • scale(scalar: number): Vec3
  • Alias of {@link Vector#multiplyScalar__anchor multiplyScalar}

    Parameters

    • scalar: number

    Returns Vec3

scaleNew

  • scaleNew(scalar: number): Vec3
  • Alias of {@link Vector#multiplyScalarNew__anchor multiplyScalarNew}

    Parameters

    • scalar: number

    Returns Vec3

subtract

  • Subtracts one vector from another.

    chainable

    Parameters

    • vector: Vec3

      The vector to subtract from this one

    Returns Vec3

    Returns itself, modified

subtractNew

  • Clones the vector and subtracts the vector from it instead

    chainable

    Parameters

    • vector: Vec3

      The vector to subtract from this one

    Returns Vec3

    Returns the clone of itself, modified

subtractScalar

  • subtractScalar(scalar: number): Vec3
  • Subtracts a scalar from the vector, modifying both the x and y

    chainable

    Parameters

    • scalar: number

      The scalar to subtract from the vector

    Returns Vec3

    Returns itself, modified

subtractScalarNew

  • subtractScalarNew(scalar: number): Vec3
  • Clones the vector and subtracts the scalar from it instead

    chainable

    Parameters

    • scalar: number

      The scalar to add to the vector

    Returns Vec3

    Returns the clone of itself, modified

transformByMat3

  • transformByMat3(m: any): Vec3

transformByMat3New

  • transformByMat3New(m: any): Vec3

transformByMat4

  • transformByMat4(m: any): Vec3

transformByMat4New

  • transformByMat4New(m: any): Vec3

transformByQuat

  • transformByQuat(q: any): Vec3

transformByQuatNew

  • transformByQuatNew(q: any): Vec3

Static fromRotationMatrix

  • fromRotationMatrix(m: any, order?: String): void | Vec3
  • Parameters

    • m: any
    • order: String = "YXZ"

    Returns void | Vec3

Static getAngle

Static interpolate

  • interpolate(v: any): Vec3
  • Iterpolates a provided anonymous value into a vew Vec3

    Parameters

    • v: any

      The value to interpolate

    Returns Vec3

    out

Static lerp

  • 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

Generated using TypeDoc