Math.Vector2D Class
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
Numberthe x coordinate of the Vector2D
-
y
Numberthe y coordinate of the Vector2D
Item Index
Methods
Methods
add
-
vector
The add method allow you to add two vectors.
Parameters:
-
vector
Vector2Dthe Vector2D to add with the current Vector2D object.
crossProduct
-
vector2
compute the cross product of the current Vector2D and vector2
Parameters:
-
vector2
Vector2Dthe second vector to use to compute the cross product
Returns:
div
-
scalar
The div method allow you to div the current Vector2D by a scalar.
Parameters:
-
scalar
Number
dotProduct
-
vector2
compute the dot product of the current Vector2D
Parameters:
-
vector2
Vector2Dthe second vector to compute the dot product
Returns:
getAngle
()
Number
get the angle of the current Vector2D
Returns:
getAngleBetween
-
vector2
compute the angle between the current Vector2D and vector2
Parameters:
-
vector2
Vector2Dthe second vector to compute the angle between. Note that
vector2
must be a fullVector2D
object.
Returns:
getLength
()
Number
get the length of the Vector2D
Returns:
getSquaredLength
()
Number
get the squared length of this vector
Returns:
mult
-
scalar
The mult method allow you to mult the current Vector2D by a scalar.
Parameters:
-
scalar
Numberthe scalar who multiply the current Vector2D
normalize
()
normalize the current Vector2D
setAngle
-
angle
set the angle of the current Vector2D
Parameters:
-
angle
Numberthe angle to apply to the current Vector2D (angle is expressed in degree)
setLength
-
length
set the length of the current Vector2D
Parameters:
-
length
Numberthe length to apply to the current Vector2D
sub
-
vector
The sub method allow you to sub two vectors.
Parameters:
-
vector
Vector2Dthe Vector2D to subtract to the current Vector2D object.
toString
()
String
give a data representation of Vector2D
Returns:
Properties
x
Number
x coordinate
y
Number
y coordinate