API Docs for: 0.7.1
Show:

# vec2 Class

Defined in: src/math/vec2.js:23

The vec2 object from glMatrix, with some extensions and some removed methods. See http://glmatrix.net.

## Methods

(
• out
• a
• b
)
Array static

#### Parameters:

• out Array

the receiving vector

• a Array

the first operand

• b Array

the second operand

Array:

out

### centroid

(
• out
• a
• b
• c
)
Array static

Compute centroid of a triangle spanned by vectors a,b,c. See http://easycalculation.com/analytical/learn-centroid.php

• out Array
• a Array
• b Array
• c Array

Array:

The out object

### clone

(
• a
)
Array static

Creates a new vec2 initialized with values from an existing vector

#### Parameters:

• a Array

vector to clone

Array:

a new 2D vector

### copy

(
• out
• a
)
Array static

Copy the values from one vec2 to another

#### Parameters:

• out Array

the receiving vector

• a Array

the source vector

Array:

out

### create

() Array static

Creates a new, empty vec2

Array:

a new 2D vector

### crossLength

(
• a
• b
)
Number static

Defined in src/math/vec2.js:32

Make a cross product and only return the z component

• a Array
• b Array

Number:

### crossVZ

(
• out
• vec
• zcomp
)
Number static

Defined in src/math/vec2.js:44

Cross product between a vector and the Z component of a vector

• out Array
• vec Array
• zcomp Number

Number:

### crossZV

(
• out
• zcomp
• vec
)
Number static

Defined in src/math/vec2.js:59

Cross product between a vector and the Z component of a vector

• out Array
• zcomp Number
• vec Array

Number:

### dist

() static

Alias for vec2.distance

### distance

(
• a
• b
)
Number static

Calculates the euclidian distance between two vec2's

#### Parameters:

• a Array

the first operand

• b Array

the second operand

#### Returns:

Number:

distance between a and b

### div

() static

Alias for vec2.divide

### divide

(
• out
• a
• b
)
Array static

Divides two vec2's

#### Parameters:

• out Array

the receiving vector

• a Array

the first operand

• b Array

the second operand

Array:

out

### dot

(
• a
• b
)
Number static

Calculates the dot product of two vec2's

#### Parameters:

• a Array

the first operand

• b Array

the second operand

#### Returns:

Number:

dot product of a and b

### fromValues

(
• x
• y
)
Array static

Creates a new vec2 initialized with the given values

• x Number

X component

• y Number

Y component

Array:

a new 2D vector

### getLineSegmentsIntersection

(
• out
• p0
• p1
• p2
• p3
)
Boolean static

Get the intersection point between two line segments.

• out Array
• p0 Array
• p1 Array
• p2 Array
• p3 Array

#### Returns:

Boolean:

True if there was an intersection, otherwise false.

### getLineSegmentsIntersectionFraction

(
• p0
• p1
• p2
• p3
)
Number static

Get the intersection fraction between two line segments. If successful, the intersection is at p0 + t * (p1 - p0)

• p0 Array
• p1 Array
• p2 Array
• p3 Array

#### Returns:

Number:

A number between 0 and 1 if there was an intersection, otherwise -1.

### len

() static

Alias for vec2.length

### length

(
• a
)
Number static

Calculates the length of a vec2

#### Parameters:

• a Array

vector to calculate length of

Number:

length of a

### lerp

(
• out
• a
• b
• t
)
static

Linearly interpolate/mix two vectors.

#### Parameters:

• out Array
• a Array

First vector

• b Array

Second vector

• t Number

Lerp factor

### mul

() static

Alias for vec2.multiply

### multiply

(
• out
• a
• b
)
Array static

Multiplies two vec2's

#### Parameters:

• out Array

the receiving vector

• a Array

the first operand

• b Array

the second operand

Array:

out

### negate

(
• out
• a
)
Array static

Negates the components of a vec2

#### Parameters:

• out Array

the receiving vector

• a Array

vector to negate

Array:

out

### normalize

(
• out
• a
)
Array static

Normalize a vec2

#### Parameters:

• out Array

the receiving vector

• a Array

vector to normalize

Array:

out

### reflect

(
• out
• vector
• normal
)
static

Reflect a vector along a normal.

• out Array
• vector Array
• normal Array

### rotate

(
• out
• a
• angle
)
static

Defined in src/math/vec2.js:74

Rotate a vector by an angle

• out Array
• a Array
• angle Number

### rotate90cw

(
• out
• a
• angle
)
static

Defined in src/math/vec2.js:96

Rotate a vector 90 degrees clockwise

• out Array
• a Array
• angle Number

### scale

(
• out
• a
• b
)
Array static

Scales a vec2 by a scalar number

#### Parameters:

• out Array

the receiving vector

• a Array

the vector to scale

• b Number

amount to scale the vector by

Array:

out

### set

(
• out
• x
• y
)
Array static

Set the components of a vec2 to the given values

#### Parameters:

• out Array

the receiving vector

• x Number

X component

• y Number

Y component

Array:

out

### sqrDist

() static

Alias for vec2.squaredDistance

### sqrLen

() static

Alias for vec2.squaredLength

### squaredDistance

(
• a
• b
)
Number static

Calculates the squared euclidian distance between two vec2's

#### Parameters:

• a Array

the first operand

• b Array

the second operand

#### Returns:

Number:

squared distance between a and b

### squaredLength

(
• a
)
Number static

Calculates the squared length of a vec2

#### Parameters:

• a Array

vector to calculate squared length of

#### Returns:

Number:

squared length of a

### str

(
• vec
)
String static

Returns a string representation of a vector

#### Parameters:

• vec Array

vector to represent as a string

#### Returns:

String:

string representation of the vector

### sub

() static

Alias for vec2.subtract

### subtract

(
• out
• a
• b
)
Array static

Subtracts two vec2's

#### Parameters:

• out Array

the receiving vector

• a Array

the first operand

• b Array

the second operand

Array:

out

### toGlobalFrame

(
• out
• localPoint
• framePosition
• frameAngle
)

Transform a point position to global frame.

#### Parameters:

• out Array
• localPoint Array
• framePosition Array
• frameAngle Number

### toGlobalFrame

(
• out
• localVector
• frameAngle
)

Transform a point position to global frame.

#### Parameters:

• out Array
• localVector Array
• frameAngle Number

### toLocalFrame

(
• out
• worldPoint
• framePosition
• frameAngle
)

Transform a point position to local frame.

#### Parameters:

• out Array
• worldPoint Array
• framePosition Array
• frameAngle Number

### vectorToLocalFrame

(
• out
• worldVector
• frameAngle
)

Transform a vector to local frame.

#### Parameters:

• out Array
• worldVector Array
• frameAngle Number