A JavaScript 2D vector maths library for Node.js and the browser.
Victor can be used in both Node.js and the browser.
Builds come with an UMD wrapper so it can be used in CommonJS and AMD environments, or as a global object.
Install Victor with bower, npm, or download the latest release.
Victor is licensed under the MIT license and can be used without restrictions.
Fork Victor on GitHub and help make it better.
You can manually download the latest build or use your favorite package manager.
Install Node.js and run the build and test scripts.
Different constructors allow instanciation in most practical way for the situation.
Can be used without the new keyword.
Copies the X component of another vector in to itself.
Copies the Y component of another vector in to itself.
Copies the X and Y components of another vector in to itself.
All manipulation functions are chainable.
Adds another vector's X component to itself.
Adds another vector's Y component to itself.
Subtracts another vector's X component from itself.
Subtracts another vector's Y component from itself.
Subtracts another vector from itself.
Multiplies the X component by a scalar.
Multiplies the Y component by a scalar.
Multiplies both components by a scalar.
Divides the X component by a scalar.
Divides the Y component by a scalar.
Divides both components by a scalar.
Performs a linear blend / interpolation of the X component towards another vector.
Performs a linear blend / interpolation of the Y component towards another vector.
Performs a linear blend / interpolation towards another vector.
Normalizes the vector by scaling it down to a length of 1 while keeping its direction.
Alias of normalize.
If either component is greater than max, multiplies the component by multiplier.
Rotates the vector to a certain angle.
Same as rotate but uses degrees
Rotates the vector by a rotation angle.
Same as rotateBy but uses degrees
Randomizes the X component with a value between topLeft and bottomRight.
Randomizes the Y component with a value between topLeft and bottomRight.
Randomizes the components with a value between topLeft and bottomRight.
Randomly randomizes either the X component or the Y component with a value between topLeft and bottomRight.
Returns the squared length / magnitude. If the length is only needed for comparison, this function is faster than length.
Returns the distance of the X component from another vector.
Same as distanceX but always returns an absolute value.
Returns the distance of the Y component from another vector.
Same as distanceY but always returns an absolute value.
Returns the euclidean distance between two vectors.
Returns the squared euclidean distance between two vectors. If the distance is only needed for comparison, this function is faster than distance.
Returns the angle towards X in radians.
Alias for horizontalAngle.
Alias for horizontalAngle.
Same as horizontalAngle but returns degrees.
Alias for horizontalAngleDeg.
Returns the angle towards Y in radians.
Same as verticalAngle but returns degrees.