Vector

creates a new 2D or 3D vector

Constructor

new Vector(xopt, yopt, zopt)

Parameters:
NameTypeAttributesDefaultDescription
xnumber<optional>
0
ynumber<optional>
0
znumber<optional>
0

Methods

add(vopt, yopt, zopt)

adds two vectors together

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

array() → {Array.<number>}

returns the array form of the vector

Returns:
  • the array
Type: 
Array.<number>

cross(vopt, yopt, zopt) → {Vector}

get the cross product of two vectors

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See
Returns:
  • the cross product
Type: 
Vector

dist(vec) → {number}

gets the distance between two vectors

Parameters:
NameTypeDescription
vecVector

vector

Returns:
  • the distance
Type: 
number

div(vopt, yopt, zopt)

divide one vector from another

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

dot(vopt, yopt, zopt) → {number}

get the dot product of two vectors

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See
Returns:
  • the dot product
Type: 
number

get() → {Vector}

returns a new vector with the same (x, y, z) values

Returns:
  • copied vector
Type: 
Vector

heading() → {number}

returns the angle of the vector only for 2D vectors

Returns:
  • angle
Type: 
number

lerp(vopt, yopt, zopt)

lerps a vector toward another

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

limit(len)

limit the length of a vector

Parameters:
NameTypeDescription
lennumber

length

mag() → {number}

returns the magnitude of the vector

Returns:
  • the magnitude
Type: 
number

magSq() → {number}

returns the squared magnitude of the vector

Returns:
  • the squared magnitude
Type: 
number

mult(vopt, yopt, zopt)

multiply two vectors together

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

normalize()

normalizes a vector to length 1

object() → {Object}

returns the object form of the vector

Returns:
  • the object
Type: 
Object

project(vopt, yopt, zopt) → {Vector}

xxx HS16 Projects the current vector onto another

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
Returns:

The projected vector

Type: 
Vector

rotate(ang)

rotates a vector a certain angle for 2D vectors only

Parameters:
NameTypeDescription
angnumber

angle

set(vopt, yopt, zopt)

sets the value of a vector

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

setMag(vec, lenopt) → {Vector}

sets the magnitude of the vector

Parameters:
NameTypeAttributesDescription
vecnumber | Vector

length or vector

lennumber<optional>

length

Returns:
  • only if len is defined
Type: 
Vector

sub(vopt, yopt, zopt)

subtracts one vector from another

Parameters:
NameTypeAttributesDescription
vnumber | Vector | Array | Object<optional>
ynumber<optional>
znumber<optional>
See

toString() → {string}

returns the string form of the vector

Returns:
  • the string of the vector coordinates
Type: 
string

(static) angleBetween(vec1, vec2) → {number}

returns the angle between two vectors

Parameters:
NameTypeDescription
vec1Vector
vec2Vector
Returns:
  • angle
Type: 
number

(static) from(vopt, yopt, zopt) → {Vector}

takes any range of values an' makes 'em a vector. aka magic.

Parameters:
NameTypeAttributesDefaultDescription
vnumber | Vector | Array | Object<optional>

if y, Vector, object, or array of values representing the vector; else, x coordinate.

ynumber<optional>
znumber<optional>
0
Returns:
Type: 
Vector

(static) fromAngle(ang, vecopt) → {Vector}

creates a vector from an angle

Parameters:
NameTypeAttributesDefaultDescription
angnumber

angle

vecVector<optional>
new Vector

vector

Returns:
  • the vector
Type: 
Vector

(static) random2D(vecopt) → {Vector}

creates a random 2D vector

Parameters:
NameTypeAttributesDefaultDescription
vecVector<optional>
new Vector

vector

Returns:
  • the vector
Type: 
Vector

(static) random3D(vecopt) → {Vector}

creates a random 3D vector

Parameters:
NameTypeAttributesDefaultDescription
vecVector<optional>
new Vector

vector

Returns:
  • the vector
Type: 
Vector