Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector2D

Represtens a mathematical Vector on a Plane. The Vector must have only two components.

Hierarchy

Index

Constructors

  • new Vector2D(...components: (number | number[] | readonly number[])[]): Vector2D

Properties

components: number[]

Contains all the components of the Vector.

Accessors

  • get x(): number
  • set x(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

  • get y(): number
  • set y(value: number): void
  • Returns number

  • Parameters

    • value: number

    Returns void

Methods

  • Sums all entries of this Vector with those of the passed one.

    remarks

    This method creates new components and returns an Array with them. If inPlace is set as true, the method modifies this array.

    Parameters

    • v: Vector

      The Vector with the addends.

    • inPlace: boolean = false

      Set as true to save the results in this Vector.

    Returns Vector

    A Vector containing the results.

  • Create a new Vector with all entries from this Vector and the passed one.

    Parameters

    • v: Vector

      Vector to be combined.

    Returns Vector

    The new Vector.

  • Returns the cross products between two vectors.

    Parameters

    Returns number

    The scalar number result of the cross product.

  • Returns the dot product of two Vectors.

    Parameters

    Returns number

    The dot product.

  • Returns true if the Vectors are equal.

    remarks

    This method takes in consideration the safe number precision of doubles.

    beta
    experimental

    Parameters

    Returns boolean

    A boolean.

  • Return true if the Vectors are normal (a.k.a. perpendicular) to each other.

    Parameters

    Returns boolean

    A boolean.

  • norm(l?: number): number
  • Return the required norm. By default return the length of the Vector.

    remarks

    If l = 1, return the l1-norm (a.k.a. the Manhattan norm). If l = 2, return the l2-norm (a.k.a. the Euclidian norm). If you have no idea what these are you probably just want the default value for the distance between two points.

    Parameters

    • l: number = 2

      The type of norm.

    Returns number

    The value of the required norm.

  • normalize(inPlace?: boolean): Vector
  • Scales this Vector so that its lenght is equal to one.

    Parameters

    • inPlace: boolean = false

      Set as true to save the results in this Vector.

    Returns Vector

    The normalized Vector.

  • opposite(inPlace?: boolean): Vector
  • Sets all entries with opposite sign of this Vector's.

    remarks

    This method creates new components and returns an Array with them. If inPlace is set as true, the method modifies this array.

    Parameters

    • inPlace: boolean = false

      Set as true to save the results in this Vector.

    Returns Vector

    A Vector that has all entries opposite to this' ones.

  • scalar(n: number, inPlace?: boolean): Vector
  • Scalar multiplication, scales this Vector by the given number.

    Parameters

    • n: number

      Scalar number

    • inPlace: boolean = false

      Set as true to save the results in this Vector.

    Returns Vector

    A scaled Vector.

  • set(id: number, value: number): void
  • Sets a single entry of the vector to a new value.

    Parameters

    • id: number
    • value: number

    Returns void

  • setComponents(newcomps: number[]): void
  • size(): number
  • Subtracts all entries of this Vector with those of the passed one.

    remarks

    This method creates new components and returns an Array with them. If inPlace is set as true, the method modifies this array.

    Parameters

    • v: Vector

      The Vector with the minuends.

    • inPlace: boolean = false

      Set as true to save the results in this Vector.

    Returns Vector

    A Vector containing the differences.

  • toArray(): number[]
  • Create an Array containing the components.

    Returns number[]

    An Array containing the components.

  • toObject(): object
  • toString(): string
  • Create a string describing the Vector.

    beta
    experimental

    Returns string

    A string describing the vector.

  • Create a new vector of size n with all entries set as zero.

    Parameters

    • n: number

      Size of the new vector of ones.

    Returns Vector

    The new Vector created.

  • Create a new vector of size n with all entries set as zero.

    Parameters

    • n: number

      Size of the new vector of zeros.

    Returns Vector

    The new Vector created.

Generated using TypeDoc