Vector2
class Vector2 implements TypeWebGLConvertible
Represents a two-dimensional vector.
Constructors​
constructor​
public new Vector2from: PossibleVector2number: Vector2
Properties​
x​
public x: number = 0
y​
public y: number = 0
bottom​
A constant equal to Vector2(0, 1)
bottomLeft​
static readonly public bottomLeft: Vector2 = ...
A constant equal to Vector2(-1, 1)
bottomRight​
static readonly public bottomRight: Vector2 = ...
A constant equal to Vector2(1, 1)
down​
left​
one​
right​
symbol​
top​
A constant equal to Vector2(0, -1)
topLeft​
A constant equal to Vector2(-1, -1)
topRight​
A constant equal to Vector2(1, -1)
up​
zero​
Accessors​
ceiled​
public get ceiled(): Vector2
ctg​
public get ctg(): number
degrees​
public get degrees(): number
Return the angle in degrees between the vector and the positive x-axis.
The returned angle will be between -180 and 180 degrees.
flipped​
public get flipped(): Vector2
floored​
public get floored(): Vector2
height​
public set heightvalue: number: void
public get height(): number
Parameters
value: number
magnitude​
public get magnitude(): number
normalized​
public get normalized(): Vector2
perpendicular​
public get perpendicular(): Vector2
radians​
public get radians(): number
Return the angle in radians between the vector and the positive x-axis.
rounded​
public get rounded(): Vector2
safe​
public get safe(): Vector2
squaredMagnitude​
public get squaredMagnitude(): number
width​
public set widthvalue: number: void
public get width(): number
Parameters
value: number
Methods​
[iterator]​
public [iterator](): Generatornumbervoidunknown
add​
public addpossibleVector: PossibleVector2number: Vector2
Parameters
possibleVector: PossibleVector2number
addX​
Parameters
value: number
addY​
Parameters
value: number
cross​
public crosspossibleVector: PossibleVector2number: number
Parameters
possibleVector: PossibleVector2number
div​
public divpossibleVector: PossibleVector2number: Vector2
Parameters
possibleVector: PossibleVector2number
dot​
public dotpossibleVector: PossibleVector2number: number
Parameters
possibleVector: PossibleVector2number
equals​
Check if two vectors are equal to each other.
This method allows passing an allowed error margin when comparing vectors
to compensate for floating point inaccuracies. To check if two vectors are
exactly equal, use the exactlyEquals method, instead.
Parameters
other: Vector2The vector to compare.
threshold: number = EPSILONThe allowed error threshold when comparing the vectors.
exactlyEquals​
Check if two vectors are exactly equal to each other.
If you need to compensate for floating point inaccuracies, use the
equals method, instead.
Parameters
getOriginOffset​
Parameters
lerp​
Parameters
map​
Transform the components of the vector.
Examples
Parameters
mod​
public modpossibleVector: PossibleVector2number: Vector2
Parameters
possibleVector: PossibleVector2number
mul​
public mulpossibleVector: PossibleVector2number: Vector2
Parameters
possibleVector: PossibleVector2number
rotate​
public rotateangle: numbercenter: PossibleVector2number = Vector2.zero: Vector2
Rotate the vector around a point by the provided angle.
Parameters
angle: numberThe angle by which to rotate in degrees.
center: PossibleVector2number = Vector2.zeroThe center of rotation. Defaults to the origin.
scale​
Parameters
value: number
serialize​
public serialize(): SerializedVector2number
sub​
public subpossibleVector: PossibleVector2number: Vector2
Parameters
possibleVector: PossibleVector2number
toArray​
public toArray(): numbernumber
toString​
public toString(): string
toSymbol​
public toSymbol(): symbol
toUniform​
Parameters
transform​
public transformmatrix: PossibleMatrix2D: Vector2
Parameters
transformAsPoint​
public transformAsPointmatrix: PossibleMatrix2D: Vector2
Parameters
angleBetween​
Parameters
arcLerp​
Parameters
createArcLerp​
Parameters
createPolarLerp​
static public createPolarLerpcounterclockwise: boolean = falsecenter: PossibleVector2number = Vector2.zero: from: Vector2to: Vector2value: number => Vector2
Helper function to create a polarLerp interpolation
function with additional parameters.
Parameters
counterclockwise: boolean = falseWhether the point should get rotated counterclockwise.
center: PossibleVector2number = Vector2.zeroThe center of rotation. Defaults to the origin.
createSignal​
static public createSignalinitial?: SignalValuePossibleVector2numberinterpolation: InterpolationFunctionVector2any[] = Vector2.lerpowner?: any: Vector2SignalvoidVector2SignalContextvoid
Parameters
initial?: SignalValuePossibleVector2numberinterpolation: InterpolationFunctionVector2any[] = Vector2.lerpowner?: any
degrees​
Return the angle in degrees between the vector described by x and y and the positive x-axis.
The returned angle will be between -180 and 180 degrees.
Parameters
fromDegrees​
Parameters
degrees: number
fromOrigin​
Parameters
fromRadians​
Parameters
radians: number
fromScalar​
Parameters
value: number
lerp​
Parameters
magnitude​
Parameters
polarLerp​
Interpolates between two vectors on the polar plane by interpolating the angles and magnitudes of the vectors individually.
This function is useful when used in conjunction with rotate to
animate an object's position on a circular arc (see examples).
Examples
Parameters
from: Vector2The starting vector.
to: Vector2The target vector.
value: numberThe t-value of the interpolation.
counterclockwise: boolean = falseWhether the vector should get rotated counterclockwise. Defaults to
false.origin: Vector2 = Vector2.zeroThe center of rotation. Defaults to the origin.
radians​
Return the angle in radians between the vector described by x and y and the positive x-axis.