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 with the X component of another vector.
Multiplies the Y component with the Y component of another vector.
Multiplies both components with another vector.
Divides the X component by the X component of another vector.
Divides the Y component by the Y component of another vector.
Divides both components by another vector.
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, in radians CCW from +X axis.
Same as rotate but uses degrees
Rotates the vector by a rotation angle, given in radians CCW from +X axis.
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 cross product of two vectors.
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.