Constructor
new Vector2(xopt, yopt)
Parameters:
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. |
Methods
add(v) → {t3d.Vector2}
Adds v to this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector2
addVectors(a, b) → {t3d.Vector2}
Sets this vector to a + b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector2
angle() → {Number}
Computes the angle in radians of this vector with respect to the positive x-axis.
Returns:
- Type:
- Number
clone() → {t3d.Vector2}
Returns a new Vector2 with the same x and y values as this one.
Returns:
- Type:
- t3d.
Vector2
copy(v) → {t3d.Vector2}
Copies the values of the passed Vector2's x and y properties to this Vector2.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector2
distanceTo(v) → {Number}
Computes the distance from this vector to v.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- 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.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- Number
dot(a) → {Number}
Calculate the dot product of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. |
Returns:
- Type:
- Number
fromArray(array, offsetopt, denormalizeopt) → {t3d.Vector2}
Sets this vector's x value to be array[ offset ] and y value to be array[ offset + 1 ].
Parameters:
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. |
Returns:
- Type:
- t3d.
Vector2
getLength() → {Number}
Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).
Returns:
- 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.
Returns:
- Type:
- Number
lerpVectors(v1, v2, ratio) → {t3d.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.
Parameters:
Name | Type | Description |
---|---|---|
v1 | t3d. | the starting Vector2. |
v2 | t3d. | Vector2 to interpolate towards. |
ratio | Number | interpolation factor, typically in the closed interval [0, 1]. |
Returns:
- Type:
- t3d.
Vector2
max(v) → {t3d.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.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector2
min(v) → {t3d.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.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector2
multiplyScalar(scalar) → {t3d.Vector2}
Multiplies this vector by scalar.
Parameters:
Name | Type | Description |
---|---|---|
scalar | Number |
Returns:
- Type:
- t3d.
Vector2
negate() → {t3d.Vector2}
Inverts this vector - i.e. sets x = -x, y = -y.
Returns:
- Type:
- t3d.
Vector2
normalize(thicknessopt) → {t3d.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.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
thickness | Number | <optional> | 1 |
Returns:
- Type:
- t3d.
Vector2
set(x, y) → {t3d.Vector2}
Sets the x and y components of this vector.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
x | Number | 0 | |
y | Number | 0 |
Returns:
- Type:
- t3d.
Vector2
sub(v) → {t3d.Vector2}
Subtracts v from this vector.
Parameters:
Name | Type | Description |
---|---|---|
v | t3d. |
Returns:
- Type:
- t3d.
Vector2
subVectors(a, b) → {t3d.Vector2}
Sets this vector to a - b.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
b | t3d. |
Returns:
- Type:
- t3d.
Vector2
subtract(a, target) → {t3d.Vector2}
Subtracts v from the vector.
Parameters:
Name | Type | Description |
---|---|---|
a | t3d. | |
target | t3d. | the result vector2 |
Returns:
- Type:
- t3d.
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.
Parameters:
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. |
Returns:
- Type:
- Array.<Number>