A 2 dimensional vector.


Maths

Hierarchy

  • Vector2

Constructors

  • Creates a vector2.

    Returns

    The newly constructed Vector2.

    Parameters

    • Optional pX: number
      in
      x value of the vector.
    • Optional pY: number
      in
      y value of the vector.

    Returns Vector2

Properties

x: number

x value of the vector.

y: number

y value of the vector.

Methods

  • Computes this + (pX,pY) and stores it into pOut.

    If pOut is omitted, the result is stored in "this".

    Returns pOut.

    Returns

    pOut.

    Parameters

    • pX: number
      in
      x value of the vector to add.
    • pY: number
      in
      y value of the vector to add.
    • Optional pOut: Vector2
      out
      The resulting Vector2.

    Returns Vector2

  • Computes this + pOther and stores it into pOut.

    If pOut is omitted, the result is stored in "this".

    Returns pOut.

    Returns

    pOut.

    Parameters

    • pOther: Vector2
      in
      The vector2 to add.
    • Optional pOut: Vector2
      out
      The resulting vector2.

    Returns Vector2

  • Copies "this" to pOther vector.

    If pOther is not supplied, a new Vector2 is allocated.

    Returns

    The copied vector.

    Parameters

    • Optional pOut: Vector2
      out
      The Vector2 to copy to.

    Returns Vector2

  • Computes the euclidean distance between this and pVec.

    Returns

    The distance between this and pVec.

    Parameters

    • pVec: Vector2
      in
      The other vector to compute the distance to.

    Returns number

  • Computes the dot product between this and (pX,pY).

    Returns

    The dot product ( dot(this, (pX,pY)) ) .

    Parameters

    • pX: number
      in
      x value of the vector to compute the dot with.
    • pY: number
      in
      y value of the vector to compute the dot with.

    Returns number

  • Computes the dot product between this and pOther.

    Returns

    The dot product ( dot(this, pOther) ) .

    Parameters

    • pOther: Vector2
      in
      The other vector2 to compute the dot with.

    Returns number

  • Tells if the two vectors are strictly identical.

    Returns

    true if the two vectors are strictly identical.

    Parameters

    • pOtherVector: Vector2
      in
      The other vector to compare to.

    Returns boolean

  • Gets the euclidean length of "this".

    Returns

    The length of this.

    Returns number

  • Gets the squared euclidean length of "this".

    Returns

    The squared length of this.

    Returns number

  • Computes the linear interpolation between this and (pX,pY) and stores the result in pOut.

    pOut = this + pTime x ( (pX,pY) - this).
    If pTime=0, pOut = this.
    If pTime=1, pOut = (pX,pY).

    If pOut is omitted, the result of the interpolation is stored in this.

    No check is done to ensure pTime is in the range [0,1].

    Returns

    pOut.

    Parameters

    • pX: number
      in
      x value of the destination vector.
    • pY: number
      in
      y value of the destination vector.
    • pTime: number
      in
      Interpolation parameter in the range [0,1].
    • Optional pOut: Vector2
      out
      The resulting vector2.

    Returns Vector2

  • Computes the linear interpolation between this and pOther and stores the result in pOut.

    pOut = this + pTime x ( pOther - this).
    If pTime=0, pOut = this.
    If pTime=1, pOut = pOther.

    If pOut is omitted, the result of the interpolation is stored in this.

    No check is done to ensure pTime is in the range [0,1].

    Returns

    pOut.

    Parameters

    • pOther: Vector2
      in
      The destination vector.
    • pTime: number
      in
      Interpolation parameter in the range [0,1].
    • Optional pOut: Vector2
      out
      The resulting vector2.

    Returns Vector2

  • Computes the opposite of this (-this) and stores the result in pOut.

    If pOut is omitted, the result is stored in "this".

    Returns

    pOut.

    Parameters

    • Optional pOut: Vector2
      out
      The resulting vector.

    Returns Vector2

  • Computes the normalization of this (i.e. scales "this" such that pOut.length() == 1, a zero vector is left unchanged) and stores the result in pOut.

    If pOut is omitted, "this" is normalized.

    Returns

    pOut.

    Parameters

    • Optional pOut: Vector2
      out
      The resulting vector.

    Returns Vector2

  • Computes the scale of this by the scalar pScalar, and stores the result in pOut.

    pOut = pScalar x this.

    If pOut is omitted, the result is stored in this.

    Returns

    pOut.

    Parameters

    • pScalar: number
      in
      The scale factor.
    • Optional pOut: Vector2
      out
      The resulting vector.

    Returns Vector2

  • Sets the vector components.

    Returns

    this.

    Parameters

    • pX: number
      in
      x value.
    • pY: number
      in
      y value.

    Returns Vector2

  • Computes the squared euclidean distance between this and pVec.

    Returns

    The squared distance between this and pVec.

    Parameters

    • pVec: Vector2
      in
      The other vector to compute the distance to.

    Returns number

  • Computes this - (pX,pY) and stores it into pOut.

    If pOut is omitted, the result is stored in "this".

    Returns pOut.

    Returns

    pOut.

    Parameters

    • pX: number
      in
      x value of the vector to subtract.
    • pY: number
      in
      y value of the vector to subtract.
    • Optional pOut: Vector2
      out
      The resulting vector2.

    Returns Vector2

  • Computes this - pOther and stores it into pOut.

    If pOut is omitted, the result is stored in "this".

    Returns pOut.

    Returns

    pOut.

    Parameters

    • pOther: Vector2
      in
      The vector2 to subtract.
    • Optional pOut: Vector2
      out
      The resulting vector2.

    Returns Vector2

  • Gets the string representation of the vector.

    Returns

    The string representation of the vector.

    Returns string