Skip to main content

Vector2

class Vector2 implements TypeWebGLConvertible

Represents a two-dimensional vector.

Constructors

constructor

public new Vector2(): Vector2
public new Vector2from: PossibleVector2number: Vector2
public new Vector2x: numbery: number: 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


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

Methods

[iterator]

public [iterator](): Generatornumbervoidunknown

add

Parameters


addX

public addXvalue: number: Vector2

Parameters


addY

public addYvalue: number: Vector2

Parameters


cross

public crosspossibleVector: PossibleVector2number: number

Parameters


div

Parameters


dot

public dotpossibleVector: PossibleVector2number: number

Parameters


equals

public equalsother: Vector2threshold: number = EPSILON: boolean

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: Vector2

    The vector to compare.

  • threshold: number = EPSILON

    The 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


getOriginOffset

public getOriginOffsetorigin: DirectionOrigin: Vector2

Parameters


lerp

public lerpto: Vector2value: numberVector2: Vector2

Parameters


map

public mapcallback: value: numberindex: number => number: Vector2

Transform the components of the vector.

Examples

Parameters


mod

Parameters


mul

Parameters


rotate

public rotateangle: numbercenter: PossibleVector2number = Vector2.zero: Vector2

Rotate the vector around a point by the provided angle.

Parameters

  • angle: number

    The angle by which to rotate in degrees.

  • center: PossibleVector2number = Vector2.zero

    The center of rotation. Defaults to the origin.


scale

public scalevalue: number: Vector2

Parameters


serialize

public serialize(): SerializedVector2number

sub

Parameters


toArray

public toArray(): number[]

toString

public toString(): string

toSymbol

public toSymbol(): symbol

toUniform

public toUniformgl: WebGL2RenderingContextlocation: WebGLUniformLocation: void

Parameters

  • gl: WebGL2RenderingContext
  • location: WebGLUniformLocation

transform

public transformmatrix: PossibleMatrix2D: Vector2

Parameters


transformAsPoint

public transformAsPointmatrix: PossibleMatrix2D: Vector2

Parameters


angleBetween

static public angleBetweenu: Vector2v: Vector2: number

Parameters


arcLerp

static public arcLerpfrom: Vector2to: Vector2value: numberreverse: boolean = falseratio?: number: Vector2

Parameters


createArcLerp

static public createArcLerpreverse?: booleanratio?: number: from: Vector2to: Vector2value: number => Vector2

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


createSignal

Parameters


degrees

static public degreesx: numbery: number: number

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

  • x: number

    The x component of the vector.

  • y: number

    The y component of the vector.


fromDegrees

static public fromDegreesdegrees: number: Vector2

Parameters


fromOrigin

static public fromOriginorigin: DirectionOrigin: Vector2

Parameters


fromRadians

static public fromRadiansradians: number: Vector2

Parameters


fromScalar

static public fromScalarvalue: number: Vector2

Parameters


lerp

static public lerpfrom: Vector2to: Vector2value: numberVector2: Vector2

Parameters


magnitude

static public magnitudex: numbery: number: number

Parameters

  • x: number
  • y: number

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: Vector2

    The starting vector.

  • to: Vector2

    The target vector.

  • value: number

    The t-value of the interpolation.

  • counterclockwise: boolean = false

    Whether the vector should get rotated counterclockwise. Defaults to false.

  • origin: Vector2 = Vector2.zero

    The center of rotation. Defaults to the origin.


radians

static public radiansx: numbery: number: number

Return the angle in radians between the vector described by x and y and the positive x-axis.

Parameters

  • x: number

    The x component of the vector.

  • y: number

    The y component of the vector.


squaredMagnitude

static public squaredMagnitudex: numbery: number: number

Parameters

  • x: number
  • y: number