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

angle(v) → {number}

get the angle thia and given vector
Parameters:
Name Type Description
v Vector

View Source Vector.js, line 168

number

angle2(vLeft, vRight) → {Vector}

Parameters:
Name Type Description
vLeft Vector
vRight Vector

View Source Vector.js, line 177

Vector

array() → {Array}

return an array representation of this vector

View Source Vector.js, line 327

Array

copy() → {Vector}

copy this vector

View Source Vector.js, line 309

Vector

dist(v) → {number}

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

View Source Vector.js, line 288

number

distSq(v) → {number}

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

View Source Vector.js, line 299

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 279

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 267

Vector

mag() → {number}

get the magnitude of this vector

View Source Vector.js, line 201

number

magSq() → {number}

get the magnitude sqr of this vector

View Source Vector.js, line 209

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 317

Vector

normalize() → {Vector}

normalize this vector

View Source Vector.js, line 240

Vector

normalizeTo(length) → {Vector}

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

View Source Vector.js, line 253

Vector

project(v) → {Vector}

Parameters:
Name Type Description
v Vector

View Source Vector.js, line 344

Vector

rotate(a)

rotate this vector
Parameters:
Name Type Description
a number

View Source Vector.js, line 355

rotateBy(origin, theta) → {Vector}

rotate this vector by some origin and angle
Parameters:
Name Type Description
origin Vector
theta theta

View Source Vector.js, line 187

Vector

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 230

Vector

setXY(x, y) → {Vector}

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

View Source Vector.js, line 219

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 335

String