Vector2
class Vector2 implements TypeWebGLConvertible
Represents a two-dimensional vector.
Constructors
constructor
public new Vector2(): Vector2
Properties
x
public x: number = 0
y
public y: number = 0
bottom
static readonly public bottom: Vector2 = ...
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
static readonly public down: Vector2 = ...
left
static readonly public left: Vector2 = ...
one
static readonly public one: Vector2 = ...
right
static readonly public right: Vector2 = ...
symbol
static readonly public symbol: typeof symbol = ...
top
static readonly public top: Vector2 = ...
A constant equal to Vector2(0, -1)
topLeft
static readonly public topLeft: Vector2 = ...
A constant equal to Vector2(-1, -1)
topRight
static readonly public topRight: Vector2 = ...
A constant equal to Vector2(1, -1)
up
static readonly public up: Vector2 = ...
zero
static readonly public zero: Vector2 = ...
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: PossibleVector2: Vector2
Parameters
possibleVector: PossibleVector2
addX
public addXvalue: number: Vector2
Parameters
value: number
addY
public addYvalue: number: Vector2
Parameters
value: number
cross
public crosspossibleVector: PossibleVector2: number
Parameters
possibleVector: PossibleVector2
div
public divpossibleVector: PossibleVector2: Vector2
Parameters
possibleVector: PossibleVector2
dot
public dotpossibleVector: PossibleVector2: number
Parameters
possibleVector: PossibleVector2
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
public exactlyEqualsother: Vector2: boolean
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
other: Vector2The vector to compare.
getOriginOffset
public getOriginOffsetorigin: DirectionOrigin: Vector2
Parameters
origin: DirectionOrigin
lerp
Parameters
map
Transform the components of the vector.
Examples
Parameters
mod
public modpossibleVector: PossibleVector2: Vector2
Parameters
possibleVector: PossibleVector2
mul
public mulpossibleVector: PossibleVector2: Vector2
Parameters
possibleVector: PossibleVector2
rotate
Rotate the vector around a point by the provided angle.
Parameters
angle: numberThe angle by which to rotate in degrees.
center: PossibleVector2 = Vector2.zeroThe center of rotation. Defaults to the origin.
scale
public scalevalue: number: Vector2
Parameters
value: number
serialize
public serialize(): SerializedVector2
sub
public subpossibleVector: PossibleVector2: Vector2
Parameters
possibleVector: PossibleVector2
toArray
public toArray(): numbernumber
toString
public toString(): string
Returns a string representation of an object.
toSymbol
public toSymbol(): symbol
toUniform
Parameters
transform
public transformmatrix: PossibleMatrix2D: Vector2
Parameters
matrix: PossibleMatrix2D
transformAsPoint
public transformAsPointmatrix: PossibleMatrix2D: Vector2
Parameters
matrix: PossibleMatrix2D
angleBetween
Parameters
arcLerp
Parameters
createArcLerp
Parameters
createPolarLerp
static public createPolarLerpcounterclockwise: boolean = falsecenter: PossibleVector2 = Vector2.zero: from: Vector2to: Vector2value: number => Vector2
Helper function to create a Vector2.polarLerp interpolation
function with additional parameters.
Parameters
counterclockwise: boolean = falseWhether the point should get rotated counterclockwise.
center: PossibleVector2 = Vector2.zeroThe center of rotation. Defaults to the origin.
createSignal
static public createSignalinitial?: SignalValuePossibleVector2numberinterpolation: InterpolationFunctionVector2 = Vector2.lerpowner?: any: Vector2Signalvoid
Parameters
initial?: SignalValuePossibleVector2numberinterpolation: InterpolationFunctionVector2 = 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
static public fromDegreesdegrees: number: Vector2
Parameters
degrees: number
fromOrigin
static public fromOriginorigin: DirectionOrigin: Vector2
Parameters
origin: DirectionOrigin
fromRadians
static public fromRadiansradians: number: Vector2
Parameters
radians: number
fromScalar
static public fromScalarvalue: number: Vector2
Parameters
value: number
lerp
Parameters
magnitude
Parameters
polarLerp
static public polarLerpfrom: Vector2to: Vector2value: numbercounterclockwise: boolean = falseorigin: Vector2 = Vector2.zero: Vector2
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.