# vectors

A grab bag of vector utility functions for 2D and 3D vectors that operate on plain arrays. Much like cog, each method can be required individually to limit the amount of bloat you get from using the module on the client with browserify.

## Usage

Each method is requireable from vectors/\${method}, followed by calling the returned generator function with the number of dimensions you want your vectors to be. e.g.:

If you want something totally generic, you can assume in most cases that appending -nd to your require will return a less performant but more flexible function:

Most of the methods in this module support vectors of arbitrary dimensions, but the ones that don't will throw an error to let you know.

Each method takes a vec vector, which if returning a new vector will almost always do so by modifying it directly:

Adds the other vector to vec:

Or add a scalar to the entire array:

You can disable this by passing scalars: false to the generator function for faster results:

### copy(vec)

Returns a copy of the vector vec:

### cross(vec, other)

Returns the cross product of vectors vec and other:

This method only works in 2 and 3 dimensions.

### dist(vec, other)

Returns the distance between vectors vec and other:

### div(vec, other[, ...])

Divides the vector vec by a other value:

Or divide multiple arrays from each other:

You can disable this by passing vectors: false to the generator function for faster results:

### dot(vec, other)

Returns the dot product of vectors vec and other:

Mutliplies the vector vec by a scalar value:

### lerp(vec, start, finish, scalar)

Set vec to the linear interpolation between vectors start and finish:

### limit(vec, scalar)

Limits the vector vec to a magnitude of scalar units.

### mag(vec)

Returns the magnitude of the vector:

### mult(vec, other[, ...])

Mutliplies the vector vec by a other value:

Or multiply multiple arrays:

You can disable this by passing vectors: false to the generator function for faster results:

### normalize(vec, scalar)

Normalizes the vector (i.e. scales it to make its distance 1 unit).

### sub(vec, other[, ...])

Subtracts the other vector from vec:

Or subtract a scalar from the entire array:

You can disable this by passing scalars: false to the generator function for faster results: