# vectors

A grab bag of vector utility functions for 2D and 3D vectors that operate on plain arrays

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

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:

Returns a copy of the vector `vec`:

Returns the cross product of vectors `vec` and `other`:

This method only works in 2 and 3 dimensions.

Returns the distance between vectors `vec` and `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:

Returns the dot product of vectors `vec` and `other`:

Mutliplies the vector `vec` by a `scalar` value:

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

Limits the vector `vec` to a magnitude of `scalar` units.

Returns the magnitude of the vector:

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:

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

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: