Constructor
The vector's x coordinate
The vector's y coordinate
The vector's x coordinate
The vector's y coordinate
Adds the given scalar to both axes of the vecta and returns a new Vecta with the result
The angle between the y axis, (0, 0) and this vector in degrees.
The angle between the x axis, (0, 0) and this vector in radians.
Finds the angle between this vector and another vector in degrees.
Finds the angle between this vector and another vector in radians.
Returns a new Vecta with the same x and y values.
Returns the cross product of this vector with the other vector. Cross product = a.x * b.y - a.x * b.y Results in a 3D vector with only a z component. Returns the magnitude of that z component.
Calculates the Euclidean distance between this vector and the given vector.
Returns the dot product of this vector with the other vector. Dot product = a.x * b.x + a.y * b.y
Returns the vector's x value
Returns the vector's y value
Interpolates between two vectors. Factor indicates how progressed (between 0 and 1) the interpolation is towards the given vector. The interpolation method allows for nonlinear interpolation
The vector to interpolate to
Progression towards vector (0 to 1) on x axis
Progression towards vector (0 to 1) on y axis
Inverts the vector (multiplies by -1) and returns the result in a new Vecta.
Limits a vector by multiplying values outside of the range by the factor.
Multiplies the vector by the given scalar. If only the X scalar is given, then uses that same value for the Y scalar.
Rounds the x and y coordinates
Returns a vector with x = 0 and y = 0
Converts an array containing two numbers in the format [x, y] into a Vecta
Converts an object containing the properties x and y of type number into a Vecta
Creates a new vector at a pseudorandom point in a rectangle defined by the * given top-left and bottom-right corners. topLeft v--------------- | | | | | | | r | <-- R might be the random location | | ---------------v bottomRight
The top-left corner of the square
The bottom-right corner of the square
Returns a vector with x = 0 and y = 0
Generated using TypeDoc
2D vector class.
This class is designed to be immutable. The x and y coordinates are private and so should not be changed. None of the class methods change these values - they instead all return a new Vecta with equal values.
All methods are designed with chaining in mind, unless it returns a scalar value.