A JavaScript 2D vector maths library for Node.js and the browser.
This page documents a fork of Victor that is currently maintained.
That means issues are being resolved and pull requests will be merged!
Victor is licensed under the MIT license and can be used without restrictions.
Fork Victor on GitHub and help make it better.
You can use NPM to install Victor.
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 by a rotation angle, given in radians CCW from +X axis.
Same as rotate but uses degrees.
Sets the angle of a vector, preserving only its magnitude.
Same as rotateTo but uses degrees.
This function is deprecated and its behaviour is undefined.
Use rotate or rotateTo instead.
This function is deprecated and its behaviour is undefined.
Use rotateDeg or rotateToDeg instead.
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.
This fork is maintained by Andrei D. Robu.