Array ab keeps the values of the vector
Mutator method for a
Accessor method for a
Accessor method for angle
Mutator method for b
Accessor method for b
Accessor method for magnitude
Accessor method for magnitude
makes the vector values absolute
var velocity: Vector2d = new Vector2d(-4, -8); 
 velocity.Abs(); //velocity vector is [4:8] now
the rounded vector
Adds the given vector to this vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 6); 
 force.Add(velocity).Add(force); //force vector [11:18] now
The vector which is desired to add
the result vector
Adds the given vector to this vector, scaled by the given
var velocity: Vector2d = new Vector2d(6, 6); 
 var force: Vector2d = new Vector(0, 0); 
 force.AddScaled(velocity,2); //force vector [12:12] now
The vector which is desired to assign
The rescale parameter for the given vector
the result vector
Returns the angle in degrees between from and to.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(4, 2); 
 var angle: number = Vector2d.Angle(velocity, force);
the angle between vector 1 and vector 2
Returns a copy of vector with its magnitude clamped to maxLength.
var velocity: Vector2d = new Vector2d(5, 6); 
 var clampled: Vector2d = Vector2d.ClampMagnitude(velocity, 5);
The vector which is desired to clamp
The maxlength of the clamped vector
the clamped vector
Clones this vector and returns it
var velocity: Vector2d = new Vector2d(5, 6); 
 var clone: Vector2d = velocity.Clone();
a copy of thic vector
Returns the z-axis of the cross products for this vector and the given vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 var cross: number = velocity.Cross(force);
The vector which is desired to find the cross product
the z-axis of the cross products
Z-axis of cross product of two vectors.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(4, 2); 
 var crossZ: number = Vector2d.CrossProduct(velocity, force);
the z-axis of cross product between vector1 and vector2
Logs this vector to the console
var velocity: Vector2d = new Vector2d(5, 6); 
 velocity.Debug(); //Writes [5:6] to the console
Returns the distance from another vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 var distance: number = velocity.Distance(force);
The vector which is desired to find the distance between
the distance
Returns the distance between vector1 and vector2.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(4, 2); 
 var distance: number = Vector2d.Distance(velocity, force);
the distance between vector 1 and vector 2
Divides this vector by the given scalar value
var velocity: Vector2d = new Vector2d(10, 15); 
 velocity.Divide(2, 3); //velocity vector is [5:5] now
The scale number for the a value of this vector (if the scaleY isn't given, this value is used for the b value, too.)
The scale number for the b value of this vectr
the result vector
Returns dot products of this vector and the given vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 var dot: number = velocity.Dot(force);
The vector which is desired to find the dot product
the result of Dot Prodcut
Dot Product of two vectors.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(4, 2); 
 var dot: number = Vector2d.DotProduct(velocity, force);
the dot product of vector1 and vector2
Draws the vector to the screen
var velocity: Vector2d = new Vector2d(5, 6); 
 velocity.DrawDebug(ctx, "blue"); //Draws a blue [5:6] vector to the canvas
Returns the angle between this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 var angle: number = velocity.GetAngleBetween(force);
The vector which is desired to find angle beetween
the angle
Returns the cosine angle between this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 var angle: number = velocity.GetAngleBetweenCos(force);
The vector which is desired to find cos(a) beetween
the cosine of the angle
Returns a new vector which is left hand normal to this vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var leftNormal: Vector2d = velocity.GetLeftNormal();
the left normal vector
Returns a new vector which is right hand normal to this vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var rightNormal: Vector2d = velocity.GetRightNormal();
the right normal vector
Returns the sine of the angle between this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6);< 
 var force: Vector2d = new Vector(3, 2); 
 var angle: number = velocity.GetAngleBetweenSin(force);
The vector which is desired to find sin(a) beetween
the sine of the angle
Returns true if this vector has opposite direction compared to the vector2.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.HasOppositeDirection(force) { 
 alert("They have the opposite direction"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if this vector has similar direction compared to the vector2.
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.HasSameDirection(force) { 
 alert("They have the same direction"); 
 }
The vector which is desired to test with this vector
true or false
Inverts (negates) this vector
var velocity: Vector2d = new Vector2d(14, 6); 
 velocity.Invert(); //velocity vector is [-14:-6] now
the negated vector
Returns true if this vector is collinear with the vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsCollinear(force) { 
 alert("They are collinear in the same way"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if equality test is successful between this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsEqualTo(force) { 
 alert("They are equal"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if normality test is successful beetween this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsNormalTo(force) { 
 alert("Force is normal to Velocity"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if this vector is in line with the vector2 (either in the same or the opposite direction)
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsOnline(force) { 
 alert("They are on the same line"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if this vector is opposite collinear with the vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsOppositeCollinear(force) { 
 alert("They are collinear in the opposite way"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if parallelity test is successful beetween this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6);
 var force: Vector2d = new Vector2d(3, 7); 
 if(velocity.IsParallelTo(force) { 
 alert("They are parallel"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if this vector perpendicular to the vector2
var velocity: Vector2d = new Vector2d(5, 6);
 var force: Vector2d = new Vector2d(3, 7);
 if(velocity. IsPerpendicular(force) { 
 alert("They are perpendicular to each other"); 
 }
The vector which is desired to test with this vector
true or false
Returns true if this vector is unit vector (normalized or normalised)
var velocity: Vector2d = new Vector2d(5, 6); 
 if(velocity.IsUnit() { 
 alert("It is Unit Vector"); 
 }
true or false
Returns true if this vector is valid
var velocity: Vector2d = new Vector2d(5, 6); 
 if(velocity.Valid() { 
 alert("It is valid vector"); 
 }
true or false
Returns true if all values of this vector is 0
var velocity: Vector2d = new Vector2d(0, 0); 
 if(velocity.IsZero() { 
 alert("It is zero vector"); 
 }
true or false
Returns the magnitude of the vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var magnitude: number = Vector2d.Magnitude(velocity);
The vector which is desired to find its magnitude
the magnitude of the vector2
Multiplies this vector by the given scalar value, or values respectively
var velocity: Vector2d = new Vector2d(5, 6); 
 velocity.Multiply(2, 4); //velocity vector is [10:24] now
The scale number for the a value of this vector (if the scaleY isn't given, this value is used for the b value, too.)
The scale number for the b value of this vectr
the result vector
Returns a copy of the unit vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var unit: Vector2d = velocity.Normalize();
the unit vector
Sets this vector to the projection of this vector onto vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(2, 5); 
 force.Project(velocity); //force vector projected onto the velocity vector and setted to projected vector
The vector which is desired to be projected onto
the projected vector
Sets this vector to the reflection of this vector over vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(4, 2); 
 force.Reflect(velocity); //force vector is Reflected over velocity vector now and setted to the reflected vector
The vector which is desired to be reflected over
the reflected vector
Rotates this vector by given angle a in degrees
var velocity: Vector2d = new Vector2d(10, 15); 
 velocity.Rotate(45); //velocity vector is rotated 45 degrees now
The amgle which is desired to rotate the vecotr
the rotated vector
rounds this vector with an efficient way (JsPerf -> 778,136,300 ops/sec)
var velocity: Vector2d = new Vector2d(4.4, 6.8); 
 velocity.Round(); //velocity vector is [4:7] now
the rounded vector
Takes the inputs and assigns them to the values of the vector
var velocity: Vector2d = new Vector2d(); 
 velocity.Set(15, 5); //The vector is [15:5] now
The value of the vector on the x-axis
The value of the vector on the y-axis
the initialized vector
Sets this vector to the given vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector() 
 force.SetVector(velocity); //force vector equals to velocity vector now
The vector which is desired to assign
the initialized vector
Returns the square of this magnitude
var velocity: Vector2d = new Vector2d(5, 6); 
 var squareMagnitude: number = Vector2d.SquareMagnitude(velocity);
The vector which is desired to find its square magnitude
the square magnitude of the vector2
Subtracts the given vector from this vector
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(); 
 force.Subtract(velocity); //force vector [-5,-6] now
The vector which is desired to subtract
the result vector
Subracts the given vector from this vector, scaled by the given
var velocity: Vector2d = new Vector2d(3, 6); 
 var force: Vector2d = new Vector(); 
 force.SubtractScaled(velocity, -3); //force vector [1:2] now
The vector which is desired to subtract
The rescale parameter for the given vector
the result vector
Swaps the values of this vector and vector2
var velocity: Vector2d = new Vector2d(5, 6); 
 var force: Vector2d = new Vector(3, 2); 
 force.Swap(velocity); //force vector is [5:6] and velocity vector is [3:2] now
The vector which is desired to swap its values
the swapped vector
Overrides the toSting method
var velocity: Vector2d = new Vector2d(5, 6); 
 console.log(velocity.toString()); //Writes [5:6] to the console
the vector in a understandable way
Generated using TypeDoc
constructor gives the initial values of the vector
Example Usage: