Class: Vector2

Vector2(x, y)

new Vector2(x, y)

Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent points in space, directions, etc.
Parameters:
Name Type Description
x number
y number
Source:

Methods

add(v)

Add the content of another vector to this one.
Parameters:
Name Type Description
v Vector2
Source:

addScalar(s)

Add a scalar value to booth vector components.
Parameters:
Name Type Description
s number
Source:

addScaledVector(v, s)

Scale a vector components and add the result to this vector.
Parameters:
Name Type Description
v Vector2
s number
Source:

addVectors(a, b)

Add two vectors and store the result in this vector.
Parameters:
Name Type Description
a Vector2
b Vector2
Source:

angle()

Computes the angle in radians with respect to the positive x-axis
Source:

ceil()

Round the vector coordinates to integer by ceiling to the bigger integer.
Source:

clone()

Create a clone of this vector object.
Source:

copy(v)

Copy the content of another vector into this one.
Parameters:
Name Type Description
v Vector2
Source:

cross(vector) → {number}

Cross multiplication between this vector and another vector.
Parameters:
Name Type Description
vector Vector2
Source:
Returns:
Result of the cross multiplication.
Type
number

distanceTo()

Distance between two vector positions.
Source:

distanceToSquared()

Distance between two vector positions squared. Faster for comparisons.
Source:

divide(v)

Divide the content of another vector from this one.
Parameters:
Name Type Description
v Vector2
Source:

divideScalar(s)

Divide a scalar value by booth vector components.
Parameters:
Name Type Description
s number
Source:

dot(vector) → {number}

Dot multiplication between this vector and another vector.
Parameters:
Name Type Description
vector Vector2
Source:
Returns:
Result of the dot multiplication.
Type
number

equals(v)

Check if two vectors are equal.
Parameters:
Name Type Description
v Vector2
Source:

floor()

Round the vector coordinates to integer by flooring to the smaller integer.
Source:

fromArray(array, offsetopt)

Set vector value from array with a offset.
Parameters:
Name Type Attributes Description
array array
offset number <optional>
Source:

length()

Length of the vector.
Source:

lengthSq()

Squared length of the vector. Faster for comparions.
Source:

manhattanDistanceTo()

Manhattan distance between two vector positions.
Source:

manhattanLength()

Manhattan length of the vector.
Source:

max(v)

Set the maximum of x and y coordinates between two vectors. X is set as the max between this vector and the other vector.
Parameters:
Name Type Description
v Vector2
Source:

min(v)

Set the minimum of x and y coordinates between two vectors. X is set as the min between this vector and the other vector.
Parameters:
Name Type Description
v Vector2
Source:

multiply(v)

Multiply the content of another vector to this one.
Parameters:
Name Type Description
v Vector2
Source:

multiplyScalar(s)

Multiply a scalar value by booth vector components.
Parameters:
Name Type Description
s number
Source:

negate()

Negate the coordinates of this vector.
Source:

normalize()

Normalize the vector (make it length one).
Source:

rotateAround(center, angle)

Rotate the vector around a central point.
Parameters:
Name Type Description
center Vector2
angle number
Source:

round()

Round the vector coordinates to their closest integer.
Source:

set(x, y)

Set vector x and y values.
Parameters:
Name Type Description
x number
y number
Source:

setLength()

Scale the vector to have a defined length value.
Source:

setScalar()

Set a scalar value into the x and y values.
Source:

sub(v)

Subtract the content of another vector to this one.
Parameters:
Name Type Description
v Vector2
Source:

subScalar(s)

Subtract a scalar value to booth vector components.
Parameters:
Name Type Description
s number
Source:

subVectors(a, b)

Subtract two vectors and store the result in this vector.
Parameters:
Name Type Description
a Vector2
b Vector2
Source:

toArray(array, offsetopt)

Convert this vector to an array.
Parameters:
Name Type Attributes Description
array array
offset number <optional>
Source: