Class

Vector

Vector(x, y)

Constructor

new Vector(x, y)

Parameters:
Name Type Description
x number
y number
Version:
  • v1.0.0
Author:
  • Anurag Hazra

View Source Vector.js, line 1

Methods

static add(v1, v2) → {Vector}

add two vectors
Parameters:
Name Type Description
v1 Vector
v2 Vector

View Source Vector.js, line 51

Vector

static dist(v1, v2) → {number}

get distance from two vectors
Parameters:
Name Type Description
v1 Vector
v2 Vector

View Source Vector.js, line 21

number

static distSq(v1, v2) → {number}

get distance squared from two vectors
Parameters:
Name Type Description
v1 Vector
v2 Vector

View Source Vector.js, line 31

number

static fromAngle(angle)

create vector from angle
Parameters:
Name Type Description
angle number

View Source Vector.js, line 59

static random2D() → {Vector}

create random2d vector

View Source Vector.js, line 70

Vector

static sub(v1, v2) → {Vector}

subtract two vectors
Parameters:
Name Type Description
v1 Vector
v2 Vector

View Source Vector.js, line 41

Vector

add(x, y) → {Vector}

add this vector to another vector
Parameters:
Name Type Description
x Vector | number
y Number

View Source Vector.js, line 93

Vector

array() → {Array}

return an array representation of this vector

View Source Vector.js, line 294

Array

copy() → {Vector}

copy this vector

View Source Vector.js, line 276

Vector

dist(v) → {number}

get distance between this and specific vector
Parameters:
Name Type Description
v Vector

View Source Vector.js, line 255

number

distSq(v) → {number}

get distance sqr between this and specific vector
Parameters:
Name Type Description
v Vector

View Source Vector.js, line 266

number

div(v) → {Vector}

divide this vector to a scalar value or a vector
Parameters:
Name Type Description
v Vector | number

View Source Vector.js, line 142

Vector

heading() → {number}

get heading of this vector in radians

View Source Vector.js, line 246

number

jitter(a, b) → {Vector}

adds random jitter motion
Parameters:
Name Type Description
a number
b number

View Source Vector.js, line 80

Vector

limit(max) → {Vector}

limit this vector
Parameters:
Name Type Description
max number

View Source Vector.js, line 234

Vector

mag() → {number}

get the magnitude of this vector

View Source Vector.js, line 168

number

magSq() → {number}

get the magnitude sqr of this vector

View Source Vector.js, line 176

number

mult(v) → {Vector}

multiply this vector to a scalar value or a vector
Parameters:
Name Type Description
v Vector | number

View Source Vector.js, line 126

Vector

negative() → {Vector}

revert this vector

View Source Vector.js, line 284

Vector

normalize() → {Vector}

normalize this vector

View Source Vector.js, line 207

Vector

normalizeTo(length) → {Vector}

normalize this vector to a specific length
Parameters:
Name Type Description
length number

View Source Vector.js, line 220

Vector

project(v) → {Vector}

Parameters:
Name Type Description
v Vector

View Source Vector.js, line 311

Vector

rotate(a)

rotate this vector
Parameters:
Name Type Description
a number

View Source Vector.js, line 322

setAngle(angle)

set this vectors angle
Parameters:
Name Type Description
angle number

View Source Vector.js, line 157

setMag(value) → {Vector}

set the magnitude of this vector
Parameters:
Name Type Description
value number

View Source Vector.js, line 197

Vector

setXY(x, y) → {Vector}

set x, y of this vector
Parameters:
Name Type Description
x number
y number

View Source Vector.js, line 186

Vector

sub(x, y) → {Vector}

subtracts this vector to another vector
Parameters:
Name Type Description
x Vector | number
y Number

View Source Vector.js, line 110

Vector

toString() → {String}

return a string representation of this vector

View Source Vector.js, line 302

String