Options

Vector2d

Vector2d: Vector2d

constructor

  • constructor(a?: number, b?: number): Vector2d
  • constructor gives the initial values of the vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(); // [0:0] 
     var velocity: Vector2d = new Vector2d(5, 3) // [5:3] 

    Parameters

    • a?: number optional
    • b?: number optional

    Returns Vector2d

private ab

ab: Float32Array

Array ab keeps the values of the vector

a

  • a(value: number)
  • a(): number
  • Mutator method for a

    Parameters

    • value: number
  • Accessor method for a

    Returns number

angle

  • angle(): number
  • Accessor method for angle

    Returns number

b

  • b(value: number)
  • b(): number
  • Mutator method for b

    Parameters

    • value: number
  • Accessor method for b

    Returns number

magnitude

  • magnitude(): number
  • Accessor method for magnitude

    Returns number

squareMagnitude

  • squareMagnitude(): number
  • Accessor method for magnitude

    Returns number

Abs

  • makes the vector values absolute

    Example Usage:

     var velocity: Vector2d = new Vector2d(-4, -8); 
     velocity.Abs(); //velocity vector is [4:8] now

    Returns Vector2d

    the rounded vector

Add

  • Adds the given vector to this vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 6); 
     force.Add(velocity).Add(force); //force vector [11:18] now

    Parameters

    • vector2: Vector2d

      The vector which is desired to add

    Returns Vector2d

    the result vector

AddScaled

  • Adds the given vector to this vector, scaled by the given

    Example Usage:

     var velocity: Vector2d = new Vector2d(6, 6); 
     var force: Vector2d = new Vector(0, 0); 
     force.AddScaled(velocity,2); //force vector [12:12] now

    Parameters

    • vector2: Vector2d

      The vector which is desired to assign

    • scale: number

      The rescale parameter for the given vector

    Returns Vector2d

    the result vector

static Angle

  • Returns the angle in degrees between from and to.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(4, 2); 
     var angle: number = Vector2d.Angle(velocity, force); 

    Parameters

    Returns number

    the angle between vector 1 and vector 2

static ClampMagnitude

  • Returns a copy of vector with its magnitude clamped to maxLength.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var clampled: Vector2d = Vector2d.ClampMagnitude(velocity, 5); 

    Parameters

    • vector1: Vector2d

      The vector which is desired to clamp

    • maxLength: number

      The maxlength of the clamped vector

    Returns Vector2d

    the clamped vector

Clone

  • Clones this vector and returns it

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var clone: Vector2d = velocity.Clone();

    Returns Vector2d

    a copy of thic vector

Cross

  • Returns the z-axis of the cross products for this vector and the given vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 2); 
     var cross: number = velocity.Cross(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find the cross product

    Returns number

    the z-axis of the cross products

static CrossProduct

  • Z-axis of cross product of two vectors.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(4, 2); 
     var crossZ: number = Vector2d.CrossProduct(velocity, force); 

    Parameters

    Returns number

    the z-axis of cross product between vector1 and vector2

Debug

  • Debug()
  • Logs this vector to the console

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     velocity.Debug(); //Writes [5:6] to the console

Distance

  • Returns the distance from another vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 2); 
     var distance: number = velocity.Distance(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find the distance between

    Returns number

    the distance

static Distance

  • Returns the distance between vector1 and vector2.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(4, 2); 
     var distance: number = Vector2d.Distance(velocity, force); 

    Parameters

    Returns number

    the distance between vector 1 and vector 2

Divide

  • Divide(scale: number, scaleY?: number): Vector2d
  • Divides this vector by the given scalar value

    Example Usage:

     var velocity: Vector2d = new Vector2d(10, 15); 
     velocity.Divide(2, 3); //velocity vector is [5:5] now

    Parameters

    • scale: number

      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.)

    • scaleY?: number optional

      The scale number for the b value of this vectr

    Returns Vector2d

    the result vector

Dot

  • Returns dot products of this vector and the given vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 2); 
     var dot: number = velocity.Dot(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find the dot product

    Returns number

    the result of Dot Prodcut

static DotProduct

  • Dot Product of two vectors.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(4, 2); 
     var dot: number = Vector2d.DotProduct(velocity, force); 

    Parameters

    Returns number

    the dot product of vector1 and vector2

DrawDebug

  • DrawDebug(ctx: CanvasRenderingContext2D, color: string, x: number, y: number)
  • Draws the vector to the screen

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     velocity.DrawDebug(ctx, "blue"); //Draws a blue [5:6] vector to the canvas

    Parameters

    • ctx: CanvasRenderingContext2D
    • color: string
    • x: number
    • y: number

GetAngleBetween

  • GetAngleBetween(vector2: Vector2d): number
  • Returns the angle between this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 2); 
     var angle: number = velocity.GetAngleBetween(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find angle beetween

    Returns number

    the angle

GetAngleBetweenCos

  • GetAngleBetweenCos(vector2: Vector2d): number
  • Returns the cosine angle between this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(3, 2); 
     var angle: number = velocity.GetAngleBetweenCos(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find cos(a) beetween

    Returns number

    the cosine of the angle

GetLeftNormal

  • Returns a new vector which is left hand normal to this vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var leftNormal: Vector2d = velocity.GetLeftNormal();

    Returns Vector2d

    the left normal vector

GetRightNormal

  • Returns a new vector which is right hand normal to this vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var rightNormal: Vector2d = velocity.GetRightNormal();

    Returns Vector2d

    the right normal vector

GetSinAngleBetweenSin

  • GetSinAngleBetweenSin(vector2: Vector2d): number
  • Returns the sine of the angle between this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6);< 
     var force: Vector2d = new Vector(3, 2); 
     var angle: number = velocity.GetAngleBetweenSin(force);

    Parameters

    • vector2: Vector2d

      The vector which is desired to find sin(a) beetween

    Returns number

    the sine of the angle

HasOppositeDirection

  • HasOppositeDirection(vector2: Vector2d): boolean
  • Returns true if this vector has opposite direction compared to the vector2.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(3, 7); 
     if(velocity.HasOppositeDirection(force) { 
         alert("They have the opposite direction"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

HasSameDirection

  • HasSameDirection(vector2: Vector2d): boolean
  • Returns true if this vector has similar direction compared to the vector2.

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(3, 7); 
     if(velocity.HasSameDirection(force) { 
         alert("They have the same direction"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

Invert

  • Inverts (negates) this vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(14, 6); 
     velocity.Invert(); //velocity vector is [-14:-6] now

    Returns Vector2d

    the negated vector

IsCollinear

  • IsCollinear(vector2: Vector2d): boolean
  • Returns true if this vector is collinear with the vector2

    Example Usage:

     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"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsEqualTo

  • Returns true if equality test is successful between this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(3, 7); 
     if(velocity.IsEqualTo(force) { 
         alert("They are equal"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsNormalTo

  • IsNormalTo(vector2: Vector2d): boolean
  • Returns true if normality test is successful beetween this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector2d(3, 7); 
     if(velocity.IsNormalTo(force) { 
         alert("Force is normal to Velocity"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsOnline

  • Returns true if this vector is in line with the vector2 (either in the same or the opposite direction)

    Example Usage:

     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"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsOppositeCollinear

  • IsOppositeCollinear(vector2: Vector2d): boolean
  • Returns true if this vector is opposite collinear with the vector2

    Example Usage:

     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"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsParallelTo

  • IsParallelTo(vector2: Vector2d): boolean
  • Returns true if parallelity test is successful beetween this vector and vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6);
     var force: Vector2d = new Vector2d(3, 7); 
     if(velocity.IsParallelTo(force) { 
         alert("They are parallel"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsPerpendicular

  • IsPerpendicular(vector2: Vector2d): boolean
  • Returns true if this vector perpendicular to the vector2

    Example Usage:

     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"); 
     } 

    Parameters

    • vector2: Vector2d

      The vector which is desired to test with this vector

    Returns boolean

    true or false

IsUnit

  • IsUnit(): boolean
  • Returns true if this vector is unit vector (normalized or normalised)

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     if(velocity.IsUnit() { 
         alert("It is Unit Vector"); 
     } 

    Returns boolean

    true or false

IsValid

  • IsValid(): boolean
  • Returns true if this vector is valid

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     if(velocity.Valid() { 
         alert("It is valid vector"); 
     } 

    Returns boolean

    true or false

IsZero

  • IsZero(): boolean
  • Returns true if all values of this vector is 0

    Example Usage:

     var velocity: Vector2d = new Vector2d(0, 0); 
     if(velocity.IsZero() { 
         alert("It is zero vector"); 
     } 

    Returns boolean

    true or false

static Magnitude

  • Returns the magnitude of the vector2

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var magnitude: number = Vector2d.Magnitude(velocity); 

    Parameters

    • vector2: Vector2d

      The vector which is desired to find its magnitude

    Returns number

    the magnitude of the vector2

Multiply

  • Multiply(scale: number, scaleY?: number): Vector2d
  • Multiplies this vector by the given scalar value, or values respectively

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     velocity.Multiply(2, 4); //velocity vector is [10:24] now

    Parameters

    • scale: number

      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.)

    • scaleY?: number optional

      The scale number for the b value of this vectr

    Returns Vector2d

    the result vector

Normalize

  • Returns a copy of the unit vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var unit: Vector2d = velocity.Normalize();

    Returns Vector2d

    the unit vector

Project

  • Sets this vector to the projection of this vector onto vector2

    Example Usage:

     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

    Parameters

    • vector2: Vector2d

      The vector which is desired to be projected onto

    Returns Vector2d

    the projected vector

Reflect

  • Sets this vector to the reflection of this vector over vector2

    Example Usage:

     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

    Parameters

    • vector2: Vector2d

      The vector which is desired to be reflected over

    Returns Vector2d

    the reflected vector

Rotate

  • Rotates this vector by given angle a in degrees

    Example Usage:

     var velocity: Vector2d = new Vector2d(10, 15); 
     velocity.Rotate(45); //velocity vector is rotated 45 degrees now

    Parameters

    • angle: number

      The amgle which is desired to rotate the vecotr

    Returns Vector2d

    the rotated vector

Round

  • rounds this vector with an efficient way (JsPerf -> 778,136,300 ops/sec)

    Example Usage:

     var velocity: Vector2d = new Vector2d(4.4, 6.8); 
     velocity.Round(); //velocity vector is [4:7] now

    Returns Vector2d

    the rounded vector

Set

  • Takes the inputs and assigns them to the values of the vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(); 
     velocity.Set(15, 5); //The vector is [15:5] now 

    Parameters

    • a: number

      The value of the vector on the x-axis

    • b: number

      The value of the vector on the y-axis

    Returns Vector2d

    the initialized vector

SetVector

  • Sets this vector to the given vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector() 
     force.SetVector(velocity); //force vector equals to velocity vector now

    Parameters

    • vector2: Vector2d

      The vector which is desired to assign

    Returns Vector2d

    the initialized vector

static SquareMagnitude

  • SquareMagnitude(vector2: Vector2d): number
  • Returns the square of this magnitude

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var squareMagnitude: number = Vector2d.SquareMagnitude(velocity); 

    Parameters

    • vector2: Vector2d

      The vector which is desired to find its square magnitude

    Returns number

    the square magnitude of the vector2

Subtract

  • Subtracts the given vector from this vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var force: Vector2d = new Vector(); 
     force.Subtract(velocity); //force vector [-5,-6] now

    Parameters

    • vector2: Vector2d

      The vector which is desired to subtract

    Returns Vector2d

    the result vector

SubtractScaled

  • Subracts the given vector from this vector, scaled by the given

    Example Usage:

     var velocity: Vector2d = new Vector2d(3, 6); 
     var force: Vector2d = new Vector(); 
     force.SubtractScaled(velocity, -3); //force vector [1:2] now

    Parameters

    • vector2: Vector2d

      The vector which is desired to subtract

    • scale: number

      The rescale parameter for the given vector

    Returns Vector2d

    the result vector

Swap

  • Swaps the values of this vector and vector2

    Example Usage:

     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

    Parameters

    • vector2: Vector2d

      The vector which is desired to swap its values

    Returns Vector2d

    the swapped vector

static Zero

  • Zeros the given vector

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     var zeroV: Vector2d = Vector2d.Zero(velocity); 

    Parameters

    • vector2: Vector2d

      The vector which is desired to zero

    Returns Vector2d

    the zerod vector

toString

  • toString(): string
  • Overrides the toSting method

    Example Usage:

     var velocity: Vector2d = new Vector2d(5, 6); 
     console.log(velocity.toString()); //Writes [5:6] to the console 

    Returns string

    the vector in a understandable way

Legend

  • Container, dynamic module
  • Enumeration
  • Enumeration member
  • Object literal
  • Constructor
  • Variable
  • Function, call signature, accessor
  • Index signature
  • Interface
  • Constructor
  • Property
  • Member, accessor
  • Index signature
  • Class
  • Constructor
  • Property
  • Member, accessor
  • Index signature
  •  
  • Inherited constructor
  • Inherited property
  • Inherited member
  •  
  • Private constructor
  • Private property
  • Private member
  •  
  •  
  • Static property
  • Static member

Generated using TypeDoc