Vector2

Class representing a vector containing 2 coordinates

Hierarchy

Index

Constructors

constructor

Find examples in Playground
  • new Vector2(x?: number, y?: number): Vector2
  • Creates a new Vector2 from the given x and y coordinates

    Parameters

    • Optional x: number

      defines the first coordinate

    • Optional y: number

      defines the second coordinate

    Returns Vector2

Properties

x

Find examples in Playground
x: number

defines the first coordinate

y

Find examples in Playground
y: number

defines the second coordinate

Methods

add

Find examples in Playground
  • Add another vector with the current one

    Parameters

    Returns Vector2

    a new Vector2 set with the addition of the current Vector2 and the given one coordinates

addInPlace

Find examples in Playground
  • Set the Vector2 coordinates by adding the given Vector2 coordinates

    Parameters

    Returns Vector2

    the current updated Vector2

addToRef

Find examples in Playground
  • Sets the "result" coordinates with the addition of the current Vector2 and the given one coordinates

    Parameters

    Returns Vector2

    the unmodified current Vector2

addVector3

Find examples in Playground
  • Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates

    Parameters

    • otherVector: Vector3

      defines the other vector

    Returns Vector2

    a new Vector2

asArray

Find examples in Playground
  • asArray(): number[]
  • Copy the current vector to an array

    Returns number[]

    a new array with 2 elements: the Vector2 coordinates.

clone

Find examples in Playground
  • Gets a new Vector2 copied from the Vector2

    Returns Vector2

    a new Vector2

copyFrom

Find examples in Playground
  • Sets the Vector2 coordinates with the given Vector2 coordinates

    Parameters

    Returns Vector2

    the current updated Vector2

copyFromFloats

Find examples in Playground
  • copyFromFloats(x: number, y: number): Vector2
  • Sets the Vector2 coordinates with the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    the current updated Vector2

divide

Find examples in Playground
  • Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2

divideInPlace

Find examples in Playground
  • Divides the current Vector2 coordinates by the given ones

    Parameters

    Returns Vector2

    the current updated Vector2

divideToRef

Find examples in Playground
  • Sets the "result" coordinates with the Vector2 divided by the given one coordinates

    Parameters

    Returns Vector2

    the unmodified current Vector2

equals

Find examples in Playground
  • Gets a boolean if two vectors are equals

    Parameters

    Returns boolean

    true if the given vector coordinates strictly equal the current Vector2 ones

equalsWithEpsilon

Find examples in Playground
  • Gets a boolean if two vectors are equals (using an epsilon value)

    Parameters

    • otherVector: DeepImmutable<Vector2>

      defines the other vector

    • Optional epsilon: number

      defines the minimal distance to consider equality

    Returns boolean

    true if the given vector coordinates are close to the current ones by a distance of epsilon.

floor

Find examples in Playground
  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

fract

Find examples in Playground
  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

getClassName

Find examples in Playground
  • getClassName(): string
  • Gets class name

    Returns string

    the string "Vector2"

getHashCode

Find examples in Playground
  • getHashCode(): number
  • Gets current vector hash code

    Returns number

    the Vector2 hash code as a number

length

Find examples in Playground
  • length(): number
  • Gets the length of the vector

    Returns number

    the vector length (float)

lengthSquared

Find examples in Playground
  • lengthSquared(): number
  • Gets the vector squared length

    Returns number

    the vector squared length (float)

multiply

Find examples in Playground
  • Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates

    Parameters

    Returns Vector2

    a new Vector2

multiplyByFloats

Find examples in Playground
  • multiplyByFloats(x: number, y: number): Vector2
  • Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    a new Vector2

multiplyInPlace

Find examples in Playground
  • Multiplies in place the current Vector2 coordinates by the given ones

    Parameters

    Returns Vector2

    the current updated Vector2

multiplyToRef

Find examples in Playground
  • Sets "result" coordinates with the multiplication of the current Vector2 and the given one coordinates

    Parameters

    Returns Vector2

    the unmodified current Vector2

negate

Find examples in Playground
  • Gets a new Vector2 with current Vector2 negated coordinates

    Returns Vector2

    a new Vector2

normalize

Find examples in Playground
  • Normalize the vector

    Returns Vector2

    the current updated Vector2

scale

Find examples in Playground
  • Returns a new Vector2 scaled by "scale" from the current Vector2

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    a new Vector2

scaleAndAddToRef

Find examples in Playground
  • Scale the current Vector2 values by a factor and add the result to a given Vector2

    Parameters

    • scale: number

      defines the scale factor

    • result: Vector2

      defines the Vector2 object where to store the result

    Returns Vector2

    the unmodified current Vector2

scaleInPlace

Find examples in Playground
  • scaleInPlace(scale: number): Vector2
  • Multiply the Vector2 coordinates by scale

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    the current updated Vector2

scaleToRef

Find examples in Playground
  • Scale the current Vector2 values by a factor to a given Vector2

    Parameters

    • scale: number

      defines the scale factor

    • result: Vector2

      defines the Vector2 object where to store the result

    Returns Vector2

    the unmodified current Vector2

set

Find examples in Playground
  • set(x: number, y: number): Vector2
  • Sets the Vector2 coordinates with the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    the current updated Vector2

subtract

Find examples in Playground
  • Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2

subtractInPlace

Find examples in Playground
  • Sets the current Vector2 coordinates by subtracting from it the given one coordinates

    Parameters

    Returns Vector2

    the current updated Vector2

subtractToRef

Find examples in Playground
  • Sets the "result" coordinates with the subtraction of the given one from the current Vector2 coordinates.

    Parameters

    Returns Vector2

    the unmodified current Vector2

toArray

Find examples in Playground
  • Sets the Vector2 coordinates in the given array or Float32Array from the given index.

    Parameters

    • array: FloatArray

      defines the source array

    • Optional index: number

      defines the offset in source array

    Returns Vector2

    the current Vector2

toString

Find examples in Playground
  • toString(): string
  • Gets a string with the Vector2 coordinates

    Returns string

    a string with the Vector2 coordinates

Static CatmullRom

Find examples in Playground
  • Gets a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the given four Vector2

    Parameters

    Returns Vector2

    a new Vector2

Static Center

Find examples in Playground

Static Clamp

Find examples in Playground
  • Returns a new Vector2 set with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max". If a coordinate of "value" is lower than "min" coordinates, the returned Vector2 is given this "min" coordinate. If a coordinate of "value" is greater than "max" coordinates, the returned Vector2 is given this "max" coordinate

    Parameters

    Returns Vector2

    a new Vector2

Static Distance

Find examples in Playground
  • Gets the distance between the vectors "value1" and "value2"

    Parameters

    Returns number

    the distance between vectors

Static DistanceOfPointFromSegment

Find examples in Playground
  • Gets the shortest distance (float) between the point "p" and the segment defined by the two points "segA" and "segB".

    Parameters

    Returns number

    the shortest distance

Static DistanceSquared

Find examples in Playground
  • Returns the squared distance between the vectors "value1" and "value2"

    Parameters

    Returns number

    the squared distance between vectors

Static Dot

Find examples in Playground
  • Gets the dot product of the vector "left" and the vector "right"

    Parameters

    Returns number

    the dot product (float)

Static FromArray

Find examples in Playground
  • Gets a new Vector2 set from the given index element of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the data source

    • Optional offset: number

      defines the offset in the data source

    Returns Vector2

    a new Vector2

Static FromArrayToRef

Find examples in Playground
  • Sets "result" from the given index element of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the data source

    • offset: number

      defines the offset in the data source

    • result: Vector2

      defines the target vector

    Returns void

Static Hermite

Find examples in Playground
  • Returns a new Vector2 located for "amount" (float) on the Hermite spline defined by the vectors "value1", "value3", "tangent1", "tangent2"

    Parameters

    Returns Vector2

    a new Vector2

Static Lerp

Find examples in Playground
  • Returns a new Vector2 located for "amount" (float) on the linear interpolation between the vector "start" adn the vector "end".

    Parameters

    Returns Vector2

    a new Vector2

Static Maximize

Find examples in Playground

Static Minimize

Find examples in Playground

Static Normalize

Find examples in Playground
  • Returns a new Vector2 equal to the normalized given vector

    Parameters

    Returns Vector2

    a new Vector2

Static One

Find examples in Playground
  • Gets a new Vector2(1, 1)

    Returns Vector2

    a new Vector2

Static PointInTriangle

Find examples in Playground

Static Transform

Find examples in Playground
  • Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix

    Parameters

    Returns Vector2

    a new Vector2

Static TransformToRef

Find examples in Playground
  • Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector "result" coordinates

    Parameters

    Returns void

Static Zero

Find examples in Playground
  • Gets a new Vector2(0, 0)

    Returns Vector2

    a new Vector2

Generated using TypeDoc