Constructor
new Vector2(xopt, yopt)
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
x | number | <optional> | 0 | the x value of this vector.  | 
y | number | <optional> | 0 | the y value of this vector.  | 
Members
(readonly) isVector2 :boolean
This flag can be used for type testing.
- boolean
 
- Default Value
 - true
 
Methods
add(v) → {Vector2}
Adds v to this vector.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - Vector2
 
addVectors(a, b) → {Vector2}
Sets this vector to a + b.
- Type:
 - Vector2
 
angle() → {number}
Computes the angle in radians of this vector with respect to the positive x-axis.
- Type:
 - number
 
clone() → {Vector2}
Returns a new Vector2 with the same x and y values as this one.
- Type:
 - Vector2
 
copy(v) → {Vector2}
Copies the values of the passed Vector2's x and y properties to this Vector2.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - Vector2
 
distanceTo(v) → {number}
Computes the distance from this vector to v.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - number
 
distanceToSquared(v) → {number}
Computes the squared distance from this vector to v. If you are just comparing the distance with another distance, you should compare the distance squared instead as it is slightly more efficient to calculate.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - number
 
dot(a) → {number}
Calculate the dot product of this vector and v.
| Name | Type | Description | 
|---|---|---|
a | Vector2 | 
- Type:
 - number
 
equals(v) → {boolean}
Checks for strict equality of this vector and v.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - boolean
 
fromArray(array, offsetopt, denormalizeopt) → {Vector2}
Sets this vector's x value to be array[ offset ] and y value to be array[ offset + 1 ].
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
array | Array.<number> | the source array.  | ||
offset | number | <optional> | 0 | offset into the array.  | 
denormalize | boolean | <optional> | false | if true, denormalize the values, and array should be a typed array.  | 
- Type:
 - Vector2
 
getLength() → {number}
Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).
- Type:
 - number
 
getLengthSquared() → {number}
Computes the square of the Euclidean length (straight-line length) from (0, 0) to (x, y). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.
- Type:
 - number
 
lerpVectors(v1, v2, ratio) → {Vector2}
Sets this vector to be the vector linearly interpolated between v1 and v2 where ratio is the percent distance along the line connecting the two vectors
- ratio = 0 will be v1, and ratio = 1 will be v2.
 
| Name | Type | Description | 
|---|---|---|
v1 | Vector2 | the starting Vector2.  | 
v2 | Vector2 | Vector2 to interpolate towards.  | 
ratio | number | interpolation factor, typically in the closed interval [0, 1].  | 
- Type:
 - Vector2
 
max(v) → {Vector2}
If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - Vector2
 
min(v) → {Vector2}
If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - Vector2
 
multiplyScalar(scalar) → {Vector2}
Multiplies this vector by scalar.
| Name | Type | Description | 
|---|---|---|
scalar | number | 
- Type:
 - Vector2
 
negate() → {Vector2}
Inverts this vector - i.e. sets x = -x, y = -y.
- Type:
 - Vector2
 
normalize(thicknessopt) → {Vector2}
Converts this vector to a unit vector - that is, sets it equal to a vector with the same direction as this one, but length 1.
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
thickness | number | <optional> | 1 | 
- Type:
 - Vector2
 
set(x, y) → {Vector2}
Sets the x and y components of this vector.
| Name | Type | Default | Description | 
|---|---|---|---|
x | number | 0 | |
y | number | 0 | 
- Type:
 - Vector2
 
sub(v) → {Vector2}
Subtracts v from this vector.
| Name | Type | Description | 
|---|---|---|
v | Vector2 | 
- Type:
 - Vector2
 
subVectors(a, b) → {Vector2}
Sets this vector to a - b.
- Type:
 - Vector2
 
subtract(a, target) → {Vector2}
Subtracts v from the vector.
- Type:
 - Vector2
 
toArray(arrayopt, offsetopt, normalizeopt) → {Array.<number>}
Sets this array[ offset ] value to be vector's x and array[ offset + 1 ] to be vector's y.
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
array | Array.<number> | <optional> | the target array.  | |
offset | number | <optional> | 0 | offset into the array.  | 
normalize | boolean | <optional> | false | if true, normalize the values, and array should be a typed array.  | 
- Type:
 - Array.<number>