Vector2

Vector2

This is a 2D vector class.

Constructor

new Vector2(xopt, yopt)

Source:
Parameters:
Name Type Attributes Default Description
x number <optional>
0 the x coordinate of the vector
y number <optional>
0 the y coordinate of the vector

Classes

Vector2

Members

(readonly) ZERO :Vector2

Description:
  • A vector whose x and y values will remain 0.
Source:
A vector whose x and y values will remain 0.
Type:

Methods

add(v)

Description:
  • Adds a given vector into this
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2

addScalar(n)

Description:
  • Adds a scalar value into this vector's x and y values
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
n number

clamp(minopt, maxopt) → {this}

Description:
  • Forces this vector to have a length between the min and max.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Attributes Default Description
min number <optional>
0 The smallest value the length of this vector is allowed to have.
max number <optional>
1 The biggest value the length of this vector is allowed to have.
Returns:
Type
this

clone()

Description:
  • Copies x and y values of this vector to a new vector and returns the new vector.
Source:
Deprecated:
  • Yes
Returns:
Vector2

copy(v)

Description:
  • Copies x and y values of another vector to this vector.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2
Returns:
this

cross(v) → {number}

Description:
  • Calculates the cross product of two vectors.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2
Returns:
Type
number

distanceTo(v)

Source:
Deprecated:
  • Calculates length of this vector to another vector
Parameters:
Name Type Description
v Vector2 the other vector

distanceToSquared(v) → {number}

Description:
  • Calculates length squared of this vector to another vector
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2 the other vector
Returns:
Type
number

divide(n) → {this}

Description:
  • Divides this vector with a scalar.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
n number
Returns:
Type
this

dot(v) → {number}

Description:
  • Calculates the dot product of two vectors.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2
Returns:
Type
number

equals(v) → {boolean}

Description:
  • Checks to see if this vector is equal to another vector.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2
Returns:
Type
boolean

equalsZero() → {boolean}

Description:
  • Checks if the vector length is zero.
Source:
Deprecated:
  • Yes
Returns:
Type
boolean

magnitude() → {number}

Source:
Deprecated:
  • Calculates length of this vector and returns it
Returns:
Type
number

magnitudeSquared()

Source:
Deprecated:
  • Calculates length squared of vector and returns it

multiply(n) → {this}

Description:
  • Multiplies this vector with a scalar.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
n number
Returns:
Type
this

normal(l, targetopt) → {Vector2}

Description:
  • Returns a scaled vector normal to this vector,when scaled to 1,it returns a unit vector.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Attributes Default Description
l number 1 the length of the vector returned.
target Vector2 <optional>
Vector2 Vector2 in which results are stored.
Returns:
Type
Vector2

normalFast(targetopt) → {Vector2}

Description:
  • Returns the normal to a vector, the normal has the same length as the vector.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Attributes Default Description
target Vector2 <optional>
Vector2 Vector2 in which results are stored.
Returns:
Type
Vector2

normalize() → {this}

Description:
  • Makes this vector a unit vector by dividing its components with its length.
Source:
Deprecated:
  • Yes
Returns:
Type
this

reflect(normal, targetopt) → {Vector2}

Description:
  • Returns a vector of this reflected on a sirface perpendicular to the normal.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Attributes Description
normal Vector2 the unit vector perpendicular to reflection surface
target Vector2 <optional>
Returns:
Type
Vector2

reverse() → {this}

Description:
  • Negates the values of this vector.
Source:
Deprecated:
  • Yes
Returns:
Type
this

rotate(rad) → {this}

Description:
  • Rotates this vector by a given angle in radians.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
rad number Angle in radians
Returns:
Type
this

rotateFast(cos, sin) → {this}

Description:
  • Rotates this vector by a given angle in radians.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
cos number
sin number
Returns:
Type
this

set(x, y)

Description:
  • Sets x and y values of this vector to the given parameter.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
x Number
y Number

setMagnitude(length)

Source:
Deprecated:
  • Sets a vector to have the given length.
Parameters:
Name Type Description
length number

sub(v) → {this}

Description:
  • Subtracts a given vector from this vector
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
v Vector2
Returns:
Type
this

subScalar(n) → {this}

Description:
  • Subtracts a scalar value from this vector's x and y values.
Source:
Deprecated:
  • Yes
Parameters:
Name Type Description
n number
Returns:
Type
this

toArray(targetopt)

Source:
Deprecated:
  • Returns an array with x and y values of this vector pushed into the array in that order.
Parameters:
Name Type Attributes Default Description
target Array.<number> <optional>
[] The array to push values.Defaults to creating a new array if not provided one
Returns:
number[]

(static) absEqual(v1, v2)

Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) add(v1, v2, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
v2 Vector_like
out Vector_like <optional>

(static) addScalar(v1, n, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
n number
out Vector_like <optional>

(static) clampMagnitude(v, min, max, out)

Source:
Parameters:
Name Type Description
v Vector_like
min number
max number
out Vector_like

(static) copy(v, outopt)

Source:
Parameters:
Name Type Attributes Default Description
v Vector_like
out Vector_like <optional>
new Vector2()

(static) cross(v1, v2)

Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) crossScalar(v1, n, out)

Source:
Parameters:
Name Type Description
v1 Vector_like
n number
out Vector_like

(static) distanceTo(v1, v2)

Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) distanceToSquared(v1, v2)

Description:
  • Calculates length squared of this vector to another vector
Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) divide(v1, v2, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
v2 Vector_like
out Vector_like <optional>

(static) divideScalar(v1, n, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
n number
out Vector_like <optional>

(static) dot(v1, v2)

Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) equal(v1, v2)

Source:
Parameters:
Name Type Description
v1 Vector_like
v2 Vector_like

(static) equalsZero(v)

Source:
Parameters:
Name Type Description
v Vector_like

(static) fromAngle(radian, outopt) → {Vector2}

Description:
  • Returns a unit vector pointing in the given angle starting from the positive x axis.
Source:
Parameters:
Name Type Attributes Description
radian number angle in radians from 0 to `Math.PI * 2`
out Vector2 <optional>
Vector2 to store results in.
Returns:
Type
Vector2

(static) getAbsAngleBetween(v1, v2) → {number}

Description:
  • Same as ` Vector2.getAbsDegBtwn` but returns in radians.
Source:
Parameters:
Name Type Description
v1 Vector2 start of the angle
v2 Vector2 end of the angle
Returns:
Type
number

(static) getAbsDegBtwn(v1, v2) → {number}

Description:
  • Gets the angle (in degrees) between two vectors in the range 0° to 360° in the anticlockwise direction from v1 to v2
Source:
Parameters:
Name Type Description
v1 Vector2 start of the angle
v2 Vector2 end of the angle
Returns:
Type
number

(static) getAngleBetween(v1, v2) → {number}

Description:
  • Gets the angle (in radians) between two vectors in the shortest direction from v1 to v2 in the range of `0` to `Math.PI`
Source:
Parameters:
Name Type Description
v1 Vector2 start of the angle
v2 Vector2 end of the angle
Returns:
Type
number

(static) getDegBtwn(v1, v2) → {number}

Description:
  • Gets the angle (in degrees) between two vectors in shortest direction from v1 to v2 in the range `0°` to `180°`
Source:
Parameters:
Name Type Description
v1 Vector2 start of the angle
v2 Vector2 end of the angle
Returns:
Type
number

(static) lerp(v1, v2, t, outopt) → {Vector2}

Description:
  • Returns a Vector2 that has been lerped between v1 and v2
Source:
Parameters:
Name Type Attributes Description
v1 Vector2 the vector to lerp from
v2 Vector2 the vector to lerp from
t number a value from 0 to 1 to scale the new Vector2 between v1 and v2
out Vector2 <optional>
the vector to store results into
Returns:
Type
Vector2

(static) magnitude(v)

Source:
Parameters:
Name Type Description
v Vector_like

(static) magnitudeSquared(v)

Source:
Parameters:
Name Type Description
v Vector_like

(static) multiply(v1, v2, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
v2 Vector_like
out Vector_like <optional>

(static) multiplyScalar(v1, n, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
n number
out Vector_like <optional>

(static) normal(v, out)

Source:
Parameters:
Name Type Description
v Vector_like
out Vector_like

(static) normalize(v, outopt)

Source:
Parameters:
Name Type Attributes Default Description
v Vector_like
out Vector_like <optional>
new Vector2()

(static) random(outopt) → {Vector2}

Description:
  • Generates a new unit Vector2 in a random direction
Source:
Parameters:
Name Type Attributes Description
out Vector2 <optional>
Returns:
Type
Vector2

(static) reflect(v, normal, outopt)

Source:
Parameters:
Name Type Attributes Description
v Vector_like
normal Vector_like
out Vector_like <optional>

(static) reverse(v, outopt)

Source:
Parameters:
Name Type Attributes Default Description
v Vector_like
out Vector_like <optional>
new Vector2()

(static) rotate(v, angle, out)

Source:
Parameters:
Name Type Description
v Vector_like
angle number
out Vector_like

(static) rotateFast(v, cos, sin, out)

Source:
Parameters:
Name Type Description
v Vector_like
cos number
sin number
out Vector_like

(static) set(v, x, y)

Source:
Parameters:
Name Type Description
v Vector_like
x number
y number

(static) setMagnitude(v, length)

Source:
Parameters:
Name Type Description
v Vector_like
length number

(static) sub(v1, v2, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
v2 Vector_like
out Vector_like <optional>

(static) subScalar(v1, n, outopt)

Source:
Parameters:
Name Type Attributes Description
v1 Vector_like
n number
out Vector_like <optional>

(static) toAngle(v) → {number}

Description:
  • Returns the angle in radians between the positive x-axis and the vector.
Source:
Parameters:
Name Type Description
v Vector2
Returns:
Type
number