Represents a 2 dimensional vector.

Constructors

  • Constructs a vector.

    Parameters

    • x: number
    • y: number
    • Optional w: number

      This is the third component in the vector. This component is used when for example performing transformations. Then a matrix multiplication might result in the w component becoming not equal to 1. In this case one should normalize the vector so that w becomes one again to have a valid vector.

      Why does this happen with matrix multiplications? Well most often it doesn't, for example translate operations or rotations don't cause this. But if you use Skew operations, this is might happen. I'd need to read up on it more myself to have a better answer.

    Returns Vector

Properties

w?: number

This is the third component in the vector. This component is used when for example performing transformations. Then a matrix multiplication might result in the w component becoming not equal to 1. In this case one should normalize the vector so that w becomes one again to have a valid vector.

Why does this happen with matrix multiplications? Well most often it doesn't, for example translate operations or rotations don't cause this. But if you use Skew operations, this is might happen. I'd need to read up on it more myself to have a better answer.

x: number
y: number
null: Vector = ...

Methods

  • Returns this vector as an array of numbers as [x, y, w]

    Returns number[]

  • Returns the clockwise perpendicular vector to this one. A perpendicular vector can be found by defining a vector where the dot product equals 0. Now, there will be two perpendicular vectors, one that is defined clockwise, and one that is found counter clockwise.

    Returns Vector

  • Returns the scalar value of the cross product between this vector and v2. Normally cross product is performed in three dimensions, but here we assume z value equals 0, and returns then the size of the resulting z dimension.

    Parameters

    Returns number

  • Gives the dot product between the two vectors.

    Parameters

    Returns number

  • Returns whether this vector is the null vector (x and y components are null) or not.

    Returns boolean

  • The euclidean length of this vector.

    Returns number

  • Returns a vector that is normalized to have norm2 = 1, pointing in the same direction as this vector.

    Returns Vector

  • Return true if this vector is pointing in the same direction as the other vector.

    Parameters

    Returns boolean

  • Returns the perpendicular component vector of this vector compared to another vector.

    Parameters

    Returns Vector

  • Returns a new vector that is this vector multiplied by the given scalar.

    Parameters

    • factor: number

    Returns Vector

  • This vector dot producted with itself.

    Returns number

  • Returns this vector in string form.

    Returns string

Generated using TypeDoc