Options
All
  • Public
  • Public/Protected
  • All
Menu

Simple vector class with two elements, x and y.

Hierarchy

  • Vector2

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Vector2(x?: number, y?: number): Vector2
  • Defaults x and y as 0 if no values passed.

    Parameters

    • Default value x: number = 0
    • Default value y: number = 0

    Returns Vector2

Properties

x

x: number

First component of the vector.

y

y: number

Second component of the vector.

Methods

add

  • add(other: Vector2): void
  • add(x: number, y: number): void
  • Adds another vector element wise.

    Parameters

    Returns void

  • Adds element wise, x and y as if they were another vector.

    Parameters

    • x: number
    • y: number

    Returns void

dot

  • dot(other: Vector2): number
  • dot(x: number, y: number): number
  • Parameters

    Returns number

    The dot product of this and the passed vector.

  • Parameters

    • x: number
    • y: number

    Returns number

    The dot product of this and the passed x and y as if they were another vector.

magnitude

  • magnitude(): number

normalize

  • normalize(): void
  • Will normalize a non zero vector to a magnitude of 1.

    Returns void

scale

  • scale(scalar: number): void
  • Scales vector based on scalar passed. Multiplication if you don't know linear algebra.

    Parameters

    • scalar: number

    Returns void

subtract

  • subtract(other: Vector2): void
  • subtract(x: number, y: number): void
  • Subtracts another vector element wise.

    Parameters

    Returns void

  • Subtracts element wise, x and y as if they were another vector.

    Parameters

    • x: number
    • y: number

    Returns void

Static copy

Generated using TypeDoc