Vector2
Represents a vector with two single-precision floating-point values.
let vec2 = new Vector2(x: number = 0, y: number = 0)
Instance properties
x
: The x component of the vector.y
: The y component of the vector.
Static properties
One
: Gets the vector (1,1).UnitX
: Gets the vector (1,0).UnitY
: Gets the vector (0,1).Zero
: Gets the vector (0,0).
Instance methods
clone
vec2.clone(): Vector2
Returns a new Vector2 with the same x, y values as this one.
equals
vec2.equals(v: Vector2): boolean
Returns true if the components of this vector and v are strictly equal; false otherwise.
length
vec2.length(): number
Returns the length of the vector.
lengthSqr
vec2.lengthSqr(): number
Returns the length of the vector squared.
distance
vec2.distanceTo(v: Vector2): number
Computes the Euclidean distance between the two given points.
distanceSqr
vec2.distanceToSqr(v: Vector2): number
Computes the Euclidean distance squared between the two given points.
angle
vec2.angle(): number
Return the angle in radians of this vector with respect to the positive x-axis.
Static methods
add
Vector2.add(v1: Vector2, v2: Vector2): Vector2
Adds two vectors together.
sub
Vector2.sub(v1: Vector2, v2: Vector2): Vector2
Subtracts the second vector from the first.
multiply
Vector2.multiply(v1: Vector2, v2: Vector2): Vector2
Returns a new vector whose values are the product of each pair of elements in two specified vectors.
divide
Vector2.divide(v1: Vector2, v2: Vector2): Vector2
Divides the first vector by the second.
addScalar
Vector2.addScalar(v: Vector2, s: number): Vector2
Adds the scalar value s to this vector's x, y values.
subScalar
Vector2.subScalar(v: Vector2, s: number): Vector2
Subtracts the scalar value s to this vector's x, y values.
multiplyScalar
Vector2.multiplyScalar(v: Vector2, s: number): Vector2
Multiplies a vector by a specified scalar.
divideScalar
Vector2.divideScalar(v: Vector2, s: number): Vector2
Divides the specified vector by a specified scalar value.
dot
Vector2.dot(v1: Vector2, v2: Vector2): Vector2
Returns the dot product of two vectors.
cross
Vector2.cross(v1: Vector2, v2: Vector2): Vector2
Returns the cross product of two vectors.
normalize
Vector2.normalize(v: Vector2): Vector2
Returns a vector with the same direction as the specified vector, but with a length of one.
max
Vector2.max(v1: Vector2, v2: Vector2): Vector2
Returns a vector whose elements are the maximum of each of the pairs of elements in two specified vectors.
min
Vector2.min(v1: Vector2, v2: Vector2): Vector2
Returns a vector whose elements are the minimum of each of the pairs of elements in two specified vectors.
lerp
Vector2.lerp(v1: Vector2, v2: Vector2, alpha: number): Vector2
Linearly interpolate between this vector and v, where alpha is the percent distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.
clamp
Vector2.clamp(v: Vector2, min: Vector2, max: Vector2): Vector2
Restricts a vector between a minimum and a maximum value.
negate
Vector2.negate(v: Vector2): Vector2
Negates a specified vector.
abs
Vector2.abs(v: Vector2): Vector2
Returns a vector whose elements are the absolute values of each of the specified vector's elements.
applyMat3
Vector2.applyMat3(v: Vector2, m: Matrix3): Vector2
Transforms a vector by a specified 3x3 matrix.
applyMat4
Vector2.applyMat4(v: Vector2, m: Matrix4): Vector2
Transforms a vector by a specified 4x4 matrix.
applyQuat
Vector2.applyQuat(v: Vector2, q: Quaternion): Vector2
Transforms a vector by the specified Quaternion rotation value.