# Vector2

Class representing a vector containing 2 coordinates

• Vector2

## 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

## Properties

### x

Find examples in Playground
x: number

defines the first coordinate

### y

Find examples in Playground
y: number

defines the second coordinate

## Methods

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

#### Parameters

• ##### otherVector: Vector2

defines the other vector

#### Returns Vector2

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

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

#### Parameters

• ##### otherVector: Vector2

defines the other vector

#### Returns Vector2

the current updated Vector2

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

#### Parameters

• ##### otherVector: Vector2

defines the other vector

• ##### result: Vector2

defines the target vector

#### Returns Vector2

the unmodified current Vector2

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

• ##### source: Vector2

defines the source Vector2

#### 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

• ##### otherVector: Vector2

defines the other vector

#### 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

• ##### otherVector: Vector2

defines the other vector

• ##### result: Vector2

defines the target vector

#### Returns Vector2

the unmodified current Vector2

### equals

Find examples in Playground
• equals(otherVector: Vector2): boolean
• Gets a boolean if two vectors are equals

#### Parameters

• ##### otherVector: Vector2

defines the other vector

#### Returns boolean

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

### equalsWithEpsilon

Find examples in Playground
• equalsWithEpsilon(otherVector: Vector2, epsilon?: number): boolean
• Gets a boolean if two vectors are equals (using an epsilon value)

#### Parameters

• ##### otherVector: 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

• ##### otherVector: Vector2

defines the other vector

#### 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

• ##### otherVector: Vector2

defines the other vector

#### 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

• ##### otherVector: Vector2

defines the other vector

• ##### result: Vector2

defines the target vector

#### 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

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

• ##### otherVector: Vector2

defines the other vector

#### 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

• ##### otherVector: Vector2

defines the other vector

• ##### result: Vector2

defines the target vector

#### 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

• ##### value1: Vector2

defines 1st point of control

• ##### value2: Vector2

defines 2nd point of control

• ##### value3: Vector2

defines 3rd point of control

• ##### value4: Vector2

defines 4th point of control

• ##### amount: number

defines the interpolation factor

#### Returns Vector2

a new Vector2

### Static Center

Find examples in Playground
• Gets a new Vector2 located at the center of the vectors "value1" and "value2"

#### Parameters

• ##### value1: Vector2

defines first vector

• ##### value2: Vector2

defines second vector

#### Returns Vector2

a new Vector2

### 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

• ##### value: Vector2

defines the value to clamp

• ##### min: Vector2

defines the lower limit

• ##### max: Vector2

defines the upper limit

#### Returns Vector2

a new Vector2

### Static Distance

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

#### Parameters

• ##### value1: Vector2

defines first vector

• ##### value2: Vector2

defines second vector

#### 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

• ##### p: Vector2

defines the middle point

• ##### segA: Vector2

defines one point of the segment

• ##### segB: Vector2

defines the other point of the segment

#### Returns number

the shortest distance

### Static DistanceSquared

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

#### Parameters

• ##### value1: Vector2

defines first vector

• ##### value2: Vector2

defines second vector

#### 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

• ##### left: Vector2

defines first vector

• ##### right: Vector2

defines second vector

#### Returns number

the dot product (float)

### Static FromArray

Find examples in Playground
• FromArray(array: ArrayLike<number>, offset?: number): Vector2
• Gets a new Vector2 set from the given index element of the given array

#### Parameters

• ##### array: 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
• FromArrayToRef(array: ArrayLike<number>, offset: number, result: Vector2): void
• Sets "result" from the given index element of the given array

#### Parameters

• ##### array: ArrayLike<number>

defines the data source

• ##### offset: number

defines the offset in the data source

• ##### result: Vector2

defines the target vector

### 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

• ##### value1: Vector2

defines the 1st control point

• ##### tangent1: Vector2

defines the outgoing tangent

• ##### value2: Vector2

defines the 2nd control point

• ##### tangent2: Vector2

defines the incoming tangent

• ##### amount: number

defines the interpolation factor

#### 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

• ##### start: Vector2

defines the start vector

• ##### end: Vector2

defines the end vector

• ##### amount: number

defines the interpolation factor

#### Returns Vector2

a new Vector2

### Static Maximize

Find examples in Playground
• Gets a new Vecto2 set with the maximal coordinate values from the "left" and "right" vectors

#### Parameters

• ##### left: Vector2

defines 1st vector

• ##### right: Vector2

defines 2nd vector

#### Returns Vector2

a new Vector2

### Static Minimize

Find examples in Playground
• Gets a new Vector2 set with the minimal coordinate values from the "left" and "right" vectors

#### Parameters

• ##### left: Vector2

defines 1st vector

• ##### right: Vector2

defines 2nd vector

#### Returns Vector2

a new Vector2

### Static Normalize

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

#### Parameters

• ##### vector: Vector2

defines the vector to normalize

#### 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
• Determines if a given vector is included in a triangle

#### Parameters

• ##### p: Vector2

defines the vector to test

• ##### p0: Vector2

defines 1st triangle point

• ##### p1: Vector2

defines 2nd triangle point

• ##### p2: Vector2

defines 3rd triangle point

#### Returns boolean

true if the point "p" is in the triangle defined by the vertors "p0", "p1", "p2"

### 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

• ##### vector: Vector2

defines the vector to transform

• ##### transformation: Matrix

defines the matrix to apply

#### 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

• ##### vector: Vector2

defines the vector to transform

• ##### transformation: Matrix

defines the matrix to apply

• ##### result: Vector2

defines the target vector

### Static Zero

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

#### Returns Vector2

a new Vector2

Generated using TypeDoc