Constructor
new Vector2(x, y)
Creates a new vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x |
Number | 0 | The x component. The default is 0. |
y |
Number | 0 | The y component. The default is 0. |
- Source:
Members
(static) one
A Vector2 with its x and y components equal to one.
- Source:
(static) unitX
A unit Vector2 along the x axis.
- Source:
(static) unitY
A unit Vector2 along the y axis.
- Source:
(static) zero
A Vector2 with its x and y components equal to zero.
- Source:
Methods
add(vector) → {Vector2}
Adds the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to add. |
- Source:
Returns:
The vector.
- Type
- Vector2
addScalar(s) → {Vector2}
Adds a scalar to the x and y components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to add. |
- Source:
Returns:
The vector.
- Type
- Vector2
addValues(x, y) → {Vector2}
Adds a value to each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to add to the x component. |
y |
Number | The value to add to the y component. |
- Source:
Returns:
The vector.
- Type
- Vector2
addVectors(u, v) → {Vector2}
Sets the vector to the addition of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector2 | The first vector. |
v |
Vector2 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector2
clone() → {Vector2}
Creates a clone of the vector.
- Source:
Returns:
The cloned vector.
- Type
- Vector2
copy(vector) → {Vector2}
Copies the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to copy. |
- Source:
Returns:
The vector.
- Type
- Vector2
distanceTo(vector) → {Number}
Calculates the distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to calculate the distance to. |
- Source:
Returns:
The distance.
- Type
- Number
distanceToSquared(vector) → {Number}
Calculates the squared distance to another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to calculate the squared distance to. |
- Source:
Returns:
The squared distance.
- Type
- Number
divideScalar(s) → {Vector2}
Divides the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to divide. |
- Source:
Returns:
The vector.
- Type
- Vector2
dot(vector) → {Number}
Calculates the dot product with another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to calculate the dot product with. |
- Source:
Returns:
The dot product.
- Type
- Number
equals(vector) → {Boolean}
Compares if the components of the vector are equal to the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to compare the components to. |
- Source:
Returns:
A value indicating whether all the components are equal.
- Type
- Boolean
length() → {Number}
Calculates the length of the vector.
- Source:
Returns:
The length.
- Type
- Number
lengthSquared() → {Number}
Calculates the squared length of the vector.
- Source:
Returns:
The squared length.
- Type
- Number
lerpVectors(u, v, t) → {Vector2}
Sets the vector to the interpolation of two other vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector2 | The first vector of the interpolation. |
v |
Vector2 | The second vector of the interpolation. |
t |
Number | The interpolation value. |
- Source:
Returns:
The vector.
- Type
- Vector2
multiplyScalar(s) → {Vector2}
Multiplies the components of the vector by a scalar.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to multiply. |
- Source:
Returns:
The vector.
- Type
- Vector2
negate() → {Vector2}
Negates the components of the vector.
- Source:
Returns:
The vector.
- Type
- Vector2
negateVector(vector) → {Vector2}
Sets the components to the negation of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to negate. |
- Source:
Returns:
The vector.
- Type
- Vector2
normalize() → {Vector2}
Normalizes the vector.
When the vector length is 0, it does nothing.
- Source:
Returns:
The vector.
- Type
- Vector2
set(x, y) → {Vector2}
Sets the x and y components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The x component. |
y |
Number | The y component. |
- Source:
Returns:
The vector.
- Type
- Vector2
setX(value) → {Vector2}
Sets the x component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The x component. |
- Source:
Returns:
The vector.
- Type
- Vector2
setY(value) → {Vector2}
Sets the y component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | The y component. |
- Source:
Returns:
The vector.
- Type
- Vector2
subtract(vector) → {Vector2}
Subtracts the components of another vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector2 | The vector to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector2
subtractScalar(s) → {Vector2}
Subtracts a scalar from the x and y components of the vector.
Parameters:
Name | Type | Description |
---|---|---|
s |
Number | The scalar to subtract. |
- Source:
Returns:
The vector.
- Type
- Vector2
subtractValues(x, y) → {Vector2}
Subtracts a value from each component of the vector.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number | The value to subtract from the x component. |
y |
Number | The value to subtract from the y component. |
- Source:
Returns:
The vector.
- Type
- Vector2
subtractVectors(u, v) → {Vector2}
Sets the vector to the difference of two vectors.
Parameters:
Name | Type | Description |
---|---|---|
u |
Vector2 | The first vector. |
v |
Vector2 | The second vector. |
- Source:
Returns:
The vector.
- Type
- Vector2