modeling/maths/vec2

Represents a two dimensional vector.

Source:

Methods

(static) abs(out, vector) → {vec2}

Source:

Calculates the absolute coordinates of the given vector.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector of reference

Returns:

out

Type
vec2

(static) add(out, a, b) → {vec2}

Source:

Adds the coordinates of two vectors (A+B).

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) angleDegrees(vector) → {Number}

Source:

Calculate the angle of the given vector.

Parameters:
Name Type Description
vector vec2

vector of reference

Returns:

angle in degrees

Type
Number

(static) angleRadians(vector) → {Number}

Source:

Calculate the angle of the given vector.

Parameters:
Name Type Description
vector vec2

vector of reference

Returns:

angle in radians

Type
Number

(static) clone(vector) → {vec2}

Source:

Create a clone of the given vector.

Parameters:
Name Type Description
vector vec2

vector to clone

Returns:

a new vector

Type
vec2

(static) copy(out, vector) → {vec2}

Source:

Create a copy of the given vector.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

source vector

Returns:

out

Type
vec2

(static) create() → {vec2}

Source:

Creates a new vector, initialized to [0,0].

Returns:

a new vector

Type
vec2

(static) cross(out, a, b) → {vec3}

Source:

Computes the cross product (3D) of two vectors.

Parameters:
Name Type Description
out vec3

receiving vector (3D)

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec3

(static) distance(a, b) → {Number}

Source:

Calculates the distance between two vectors.

Parameters:
Name Type Description
a vec2

first operand

b vec2

second operand

Returns:

distance

Type
Number

(static) divide(out, a, b) → {vec2}

Source:

Divides the coordinates of two vectors (A/B).

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) dot(a, b) → {Number}

Source:

Calculates the dot product of two vectors.

Parameters:
Name Type Description
a vec2

first operand

b vec2

second operand

Returns:

dot product

Type
Number

(static) equals(a, b) → {Boolean}

Source:

Compare the given vectors for equality.

Parameters:
Name Type Description
a vec2

first operand

b vec2

second operand

Returns:

true if a and b are equal

Type
Boolean

(static) fromAngleDegrees(out, degrees) → {vec2}

Source:

Create a new vector in the direction of the given angle.

Parameters:
Name Type Description
out vec2

receiving vector

degrees Number

angle in degrees

Returns:

out

Type
vec2

(static) fromAngleRadians(out, radians) → {vec2}

Source:

Create a new vector in the direction of the given angle.

Parameters:
Name Type Description
out vec2

receiving vector

radians Number

angle in radians

Returns:

out

Type
vec2

(static) fromScalar(out, scalar) → {vec2}

Source:

Create a vector from a single scalar value.

Parameters:
Name Type Description
out vec2

receiving vector

scalar Number

the scalar value

Returns:

out

Type
vec2

(static) fromValues(x, y) → {vec2}

Source:

Creates a new vector initialized with the given values.

Parameters:
Name Type Description
x Number

X coordinate

y Number

Y coordinate

Returns:

a new vector

Type
vec2

(static) length(vector) → {Number}

Source:

Calculates the length of the given vector.

Parameters:
Name Type Description
vector vec2

vector of reference

Returns:

length

Type
Number

(static) lerp(out, a, b, t) → {vec2}

Source:

Performs a linear interpolation between two vectors.

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

t Number

interpolation amount between the two vectors

Returns:

out

Type
vec2

(static) max(out, a, b) → {vec2}

Source:

Returns the maximum coordinates of two vectors.

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) min(out, a, b) → {vec2}

Source:

Returns the minimum coordinates of two vectors.

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) multiply(out, a, b) → {vec2}

Source:

Multiplies the coordinates of two vectors (A*B).

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) negate(out, vector) → {vec2}

Source:

Negates the coordinates of the given vector.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to negate

Returns:

out

Type
vec2

(static) normal(out, vector) → {vec2}

Source:

Calculates the normal of the given vector. The normal value is the given vector rotated 90 degrees.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

given value

Returns:

out

Type
vec2

(static) normalize(out, vector) → {vec2}

Source:

Normalize the given vector.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to normalize

Returns:

out

Type
vec2

(static) rotate(out, vector, origin, radians) → {vec2}

Source:

Rotates the given vector by the given angle.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to rotate

origin vec2

origin of the rotation

radians Number

angle of rotation (radians)

Returns:

out

Type
vec2

(static) scale(out, vector, amount) → {vec2}

Source:

Scales the coordinates of the given vector.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to scale

amount Number

amount to scale

Returns:

out

Type
vec2

(static) snap(out, vector, epsilon) → {vec2}

Source:

Snaps the coordinates of the given vector to the given epsilon.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to snap

epsilon Number

epsilon of precision, less than 0

Returns:

out

Type
vec2

(static) squaredDistance(a, b) → {Number}

Source:

Calculates the squared distance between the given vectors.

Parameters:
Name Type Description
a vec2

first operand

b vec2

second operand

Returns:

squared distance

Type
Number

(static) squaredLength(vector) → {Number}

Source:

Calculates the squared length of the given vector.

Parameters:
Name Type Description
vector vec2

vector of reference

Returns:

squared length

Type
Number

(static) subtract(out, a, b) → {vec2}

Source:

Subtracts the coordinates of two vectors (A-B).

Parameters:
Name Type Description
out vec2

receiving vector

a vec2

first operand

b vec2

second operand

Returns:

out

Type
vec2

(static) toString(vector) → {String}

Source:

Convert the given vector to a representative string.

Parameters:
Name Type Description
vector vec2

vector of reference

Returns:

string representation

Type
String

(static) transform(out, vector, matrix) → {vec2}

Source:

Transforms the given vector using the given matrix.

Parameters:
Name Type Description
out vec2

receiving vector

vector vec2

vector to transform

matrix mat4

matrix to transform with

Returns:

out

Type
vec2