Class: Vector

Vector(x, y)

the class Vector

Constructor

new Vector(x, y)

Parameters:
Name Type Description
x Number the x component of the vector
y Number the y component of the vector
Source:

Members

angle

the angle of the vector
Source:

isZeroVector

whether the vector is a zero vector or not
Source:

magnitude

the magnitude of the vector
Source:

slope

the slope of the vector, calculated by y/x
Source:

unitVector

the unit vector of the given vector
Source:

Methods

flipX() → {Vector}

flip the vector horizontally, update is made to the original vector
Source:
Returns:
the flipped vector
Type
Vector

flipY() → {Vector}

flip the vector horizontally, update is made to the original vector
Source:
Returns:
the flipped vector
Type
Vector

negative() → {Vector}

the negative of the vector
Source:
Returns:
the flipped vector
Type
Vector

rotate(angle) → {Vector}

rotate the vector by the given degree, update is made to the original vector
Parameters:
Name Type Description
angle Number the angle to rotate in radian
Source:
Returns:
the rotated vector
Type
Vector

scale(factor) → {Vector}

scale the vector by the given scale factor
Parameters:
Name Type Description
factor Number the scale factor
Source:
Returns:
the scaled vector
Type
Vector

scaleX(factor) → {Vector}

scale the vector in the x-direction only by the given scale factor
Parameters:
Name Type Description
factor Number the scale factor
Source:
Returns:
the scaled vector
Type
Vector

scaleY(factor) → {Vector}

scale the vector in the y-direction only by the given scale factor
Parameters:
Name Type Description
factor Number the scale factor
Source:
Returns:
the scaled vector
Type
Vector