API Docs for: 0.3.0
Show:

Math.Vector2D Class

Module: Math

The Vector2D class allow you to create a vector2D object

For a more simplier use, most of methods which take Vector2D in parameter can also take a basic object instead:

vector.add({ x: 20, y: 20 });
vector.dotProduct({ x: 10, y: 10 });

This inclues add, sub, dotProduct and crossProduct. Warning: getAngleBetween need a full Vector2D object.

Constructor

Math.Vector2D

(
  • x
  • y
)

Parameters:

  • x Number

    the x coordinate of the Vector2D

  • y Number

    the y coordinate of the Vector2D

Methods

add

(
  • vector
)
chainable

The add method allow you to add two vectors.

Parameters:

  • vector Vector2D

    the Vector2D to add with the current Vector2D object.

crossProduct

(
  • vector2
)
Number

compute the cross product of the current Vector2D and vector2

Parameters:

  • vector2 Vector2D

    the second vector to use to compute the cross product

Returns:

Number: returns the cross product between the current Vector2D and vector2

div

(
  • scalar
)
chainable

The div method allow you to div the current Vector2D by a scalar.

Parameters:

  • scalar Number

dotProduct

(
  • vector2
)
Number

compute the dot product of the current Vector2D

Parameters:

  • vector2 Vector2D

    the second vector to compute the dot product

Returns:

Number: returns the dot product between the current Vector2D and vector2.

getAngle

() Number

get the angle of the current Vector2D

Returns:

Number: returns the angle of the current Vector2D (expressed in degree).

getAngleBetween

(
  • vector2
)
Number

compute the angle between the current Vector2D and vector2

Parameters:

  • vector2 Vector2D

    the second vector to compute the angle between. Note that vector2 must be a full Vector2D object.

Returns:

Number: returns the angle between the current Vector2D and vector2 (expressed in degree).

getLength

() Number

get the length of the Vector2D

Returns:

Number: returns the length of the Vector2D.

getSquaredLength

() Number

get the squared length of this vector

Returns:

Number: squared length

mult

(
  • scalar
)
chainable

The mult method allow you to mult the current Vector2D by a scalar.

Parameters:

  • scalar Number

    the scalar who multiply the current Vector2D

normalize

()

normalize the current Vector2D

setAngle

(
  • angle
)

set the angle of the current Vector2D

Parameters:

  • angle Number

    the angle to apply to the current Vector2D (angle is expressed in degree)

setLength

(
  • length
)

set the length of the current Vector2D

Parameters:

  • length Number

    the length to apply to the current Vector2D

sub

(
  • vector
)
chainable

The sub method allow you to sub two vectors.

Parameters:

  • vector Vector2D

    the Vector2D to subtract to the current Vector2D object.

toString

() String

give a data representation of Vector2D

Returns:

String: data representation of Vector2D

Properties

x

Number

x coordinate

y

Number

y coordinate