Vector2
A vector with two components.
Constructor Summary
Public Constructor | ||
public |
constructor(x: Number, y: Number) Constructs a new vector. |
Member Summary
Public Members | ||
public get |
The height. |
|
public set |
Sets the height. |
|
public get |
The width. |
|
public set |
Sets the width. |
|
public |
The X component. |
|
public |
The Y component. |
Method Summary
Public Methods | ||
public |
Adds a vector to this one. |
|
public |
Adds a scalar to this vector. |
|
public |
addScaledVector(v: Vector2, s: Number): Vector2 Adds a scaled vector to this one. |
|
public |
addVectors(a: Vector2, b: Vector2): Vector2 Sets this vector to the sum of two given vectors. |
|
public |
Computes the angle in radians with respect to the positive X-axis. |
|
public |
applyMatrix3(m: Matrix3): Vector2 Applies the given matrix to this vector. |
|
public |
Ceils this vector. |
|
public |
Clamps this vector. |
|
public |
Clones this vector. |
|
public |
Copies the values of another vector. |
|
public |
Calculates the cross product with another vector. |
|
public |
distanceTo(v: Vector2): Number Calculates the distance to a given vector. |
|
public |
Calculates the squared distance to a given vector. |
|
public |
Divides this vector by another vector. |
|
public |
divideScalar(s: Number): Vector2 Divides this vector by a given scalar. |
|
public |
Calculates the dot product with another vector. |
|
public |
Checks if this vector equals the given one. |
|
public |
Floors this vector. |
|
public |
Copies values from an array. |
|
public |
Calculates the length of this vector. |
|
public |
Calculates the squared length of this vector. |
|
public |
Lerps towards the given vector. |
|
public |
lerpVectors(v1: Vector2, v2: Vector2, alpha: Number): Vector2 Sets this vector to the lerp result of the given vectors. |
|
public |
Calculates the Manhattan distance to a given vector. |
|
public |
Calculates the Manhattan length of this vector. |
|
public |
adopts the max value for each component of this vector and the given one. |
|
public |
Adopts the min value for each component of this vector and the given one. |
|
public |
Multiplies this vector with another vector. |
|
public |
multiplyScalar(s: Number): Vector2 Multiplies this vector with a given scalar. |
|
public |
Negates this vector. |
|
public |
Normalizes this vector. |
|
public |
Randomizes the values of this vector |
|
public |
rotateAround(center: Vector2, angle: Number): Vector2 Rotates this vector around a given center. |
|
public |
Rounds this vector. |
|
public |
Sets the values of this vector |
|
public |
Sets the length of this vector. |
|
public |
Subtracts a vector from this vector. |
|
public |
Subtracts a scalar from this vector. |
|
public |
subVectors(a: Vector2, b: Vector2): Vector2 Sets this vector to the difference between two given vectors. |
|
public |
Stores this vector in an array. |
Public Constructors
Public Members
Public Methods
public add(v: Vector2): Vector2 source
Adds a vector to this one.
Params:
Name | Type | Attribute | Description |
v | Vector2 | The vector to add. |
public addScalar(s: Number): Vector2 source
Adds a scalar to this vector.
Params:
Name | Type | Attribute | Description |
s | Number | The scalar to add. |
public addVectors(a: Vector2, b: Vector2): Vector2 source
Sets this vector to the sum of two given vectors.
public applyMatrix3(m: Matrix3): Vector2 source
Applies the given matrix to this vector.
Params:
Name | Type | Attribute | Description |
m | Matrix3 | A matrix. |
public copy(v: Vector2): Vector2 source
Copies the values of another vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public cross(v: Vector2): Number source
Calculates the cross product with another vector.
This method calculates a scalar that would result from a regular 3D cross product of the input vectors, while taking their Z values implicitly as 0.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public distanceTo(v: Vector2): Number source
Calculates the distance to a given vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public distanceToSquared(v: Vector2): Number source
Calculates the squared distance to a given vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public divide(v: Vector2): Vector2 source
Divides this vector by another vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public divideScalar(s: Number): Vector2 source
Divides this vector by a given scalar.
Params:
Name | Type | Attribute | Description |
s | Number | A scalar. |
public dot(v: Vector2): Number source
Calculates the dot product with another vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public equals(v: Vector2): Boolean source
Checks if this vector equals the given one.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public lerpVectors(v1: Vector2, v2: Vector2, alpha: Number): Vector2 source
Sets this vector to the lerp result of the given vectors.
public manhattanDistanceTo(v: Vector2): Number source
Calculates the Manhattan distance to a given vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public max(v: Vector2): Vector2 source
adopts the max value for each component of this vector and the given one.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public min(v: Vector2): Vector2 source
Adopts the min value for each component of this vector and the given one.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public multiply(v: Vector2): Vector2 source
Multiplies this vector with another vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | A vector. |
public multiplyScalar(s: Number): Vector2 source
Multiplies this vector with a given scalar.
Params:
Name | Type | Attribute | Description |
s | Number | A scalar. |
public rotateAround(center: Vector2, angle: Number): Vector2 source
Rotates this vector around a given center.
public setLength(length: Number): Vector2 source
Sets the length of this vector.
Params:
Name | Type | Attribute | Description |
length | Number | The new length. |
public sub(v: Vector2): Vector2 source
Subtracts a vector from this vector.
Params:
Name | Type | Attribute | Description |
v | Vector2 | The vector to subtract. |
public subScalar(s: Number): Vector2 source
Subtracts a scalar from this vector.
Params:
Name | Type | Attribute | Description |
s | Number | The scalar to subtract. |