wtc-math (master) doxdox documentation

A math library that provides discrete components for common math operations. Includes vectors, matrices and quaternions.

# a11()

(getter/setter) The a11 value of the matrix.

# a12()

(getter/setter) The a12 value of the matrix.

# a21()

(getter/setter) The a21 value of the matrix.

# a22()

(getter/setter) The a22 value of the matrix.

# adjoint()

Calculates the adjugate of a mat2

# array()

(getter) Returns the basic array representation of this matrix.

# columnArray()

(getter) Returns the basic array representation of this matrix. this returns the array in column-major form.

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# a11()

(getter/setter) The a11 value of the matrix.

# a12()

(getter/setter) The a12 value of the matrix.

# a13()

(getter/setter) The a13 value of the matrix.

# a21()

(getter/setter) The a21 value of the matrix.

# a22()

(getter/setter) The a22 value of the matrix.

# a23()

(getter/setter) The a23 value of the matrix.

# a31()

(getter/setter) The a31 value of the matrix.

# a32()

(getter/setter) The a32 value of the matrix.

# a33()

(getter/setter) The a33 value of the matrix.

# array()

(getter) Returns the basic array representation of this matrix.

# columnArray()

(getter) Returns the basic array representation of this matrix. this returns the array in column-major form.

# determinant()

Calculates the determinant of the mat3

# fromMat4(a)

Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix

Parameters

Name Types Description
a mat4 Mat4 to derive the normal matrix from

# fromProjection(width, height)

Generates a 2D projection matrix with the given bounds

Parameters

Name Types Description
width number Width of your gl context
height number Height of gl context

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# a11()

(getter/setter) The a11 value of the matrix.

# a12()

(getter/setter) The a12 value of the matrix.

# a13()

(getter/setter) The a13 value of the matrix.

# a14()

(getter/setter) The a14 value of the matrix.

# a21()

(getter/setter) The a21 value of the matrix.

# a22()

(getter/setter) The a22 value of the matrix.

# a23()

(getter/setter) The a23 value of the matrix.

# a24()

(getter/setter) The a24 value of the matrix.

# a31()

(getter/setter) The a31 value of the matrix.

# a32()

(getter/setter) The a32 value of the matrix.

# a33()

(getter/setter) The a33 value of the matrix.

# a34()

(getter/setter) The a34 value of the matrix.

# a41()

(getter/setter) The a41 value of the matrix.

# a42()

(getter/setter) The a42 value of the matrix.

# a43()

(getter/setter) The a43 value of the matrix.

# a44()

(getter/setter) The a44 value of the matrix.

# array()

(getter) Returns the basic array representation of this matrix.

# determinant()

Calculates the determinant of the mat4

# determinantFunction()

Calculates the determinant function the mat4

# fromQuat(q)

Calculates a 4x4 matrix from the given quaternion

Parameters

Name Types Description
q quat Quaternion to create matrix from

# fromRotationTranslationScale(q, v, s)

Creates a matrix from a quaternion rotation, vector translation and vector scale This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); let quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat); mat4.scale(dest, scale)

Parameters

Name Types Description
q quat4 Rotation quaternion
v vec3 Translation vector
s vec3 Scaling vector

# fromRotationTranslationScaleOrigin(q, v, s, o)

Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); mat4.translate(dest, origin); let quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat); mat4.scale(dest, scale) mat4.translate(dest, negativeOrigin);

Parameters

Name Types Description
q quat4 Rotation quaternion
v vec3 Translation vector
s vec3 Scaling vector
o vec3 The origin vector around which to scale and rotate

# frustum(left, right, bottom, top, near, far)

Generates a frustum matrix with the given bounds

Parameters

Name Types Description
left Number Left bound of the frustum
right Number Right bound of the frustum
bottom Number Bottom bound of the frustum
top Number Top bound of the frustum
near Number Near bound of the frustum
far Number Far bound of the frustum

# lookAt(out, eye, center, up)

Generates a look-at matrix with the given eye position, focal point, and up axis. If you want a matrix that actually makes an object look at another object, you should use targetTo instead.

Parameters

Name Types Description
out mat4 mat4 frustum matrix will be written into
eye vec3 Position of the viewer
center vec3 Point the viewer is looking at
up vec3 vec3 pointing up

# ortho(left, right, bottom, top, near, far)

Generates a orthogonal projection matrix with the given bounds

Parameters

Name Types Description
left number Left bound of the frustum
right number Right bound of the frustum
bottom number Bottom bound of the frustum
top number Top bound of the frustum
near number Near bound of the frustum
far number Far bound of the frustum

# perspective(fovy, aspect, near, far)

Generates a perspective projection matrix with the given bounds. Passing null/undefined/no value for far will generate infinite projection matrix.

Parameters

Name Types Description
fovy number Vertical field of view in radians
aspect number Aspect ratio. typically viewport width/height
near number Near bound of the frustum
far number Far bound of the frustum, can be null or Infinity

# rotate(r, axis)

Rotates a mat4 by the given angle around the given axis

Parameters

Name Types Description
r Number the angle to rotate the matrix by
axis vec3 the axis to rotate around

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# targetTo(eye, center, up)

Generates a matrix that makes something look at something else.

Parameters

Name Types Description
eye vec3 Position of the viewer
center vec3 Point the viewer is looking at
up vec3 vec3 pointing up

# transform(v)

Transforms the mat4 by a given amount

Parameters

Name Types Description
v Vec3 The amount to add to the matrixes transformation properties

# transformTo(v)

Transforms the mat4 to a given position

Parameters

Name Types Description
v Vec3 The amount to add to the matrixes transformation properties

# translate(v)

Translates the mat4 to a given position

Parameters

Name Types Description
v Vec3 The amount to add to the matrixes translation properties

# ...args(x, y)

The Vector Class constructor

Parameters

Name Types Description
x number The x coord
y number The y coord

# ...args(x, y)

Resets the vector coordinates

Parameters

Name Types Description
x number Array
y number The y coord

# add(vector)

Adds one vector to another.

Parameters

Name Types Description
vector Vec2 The vector to add to this one

Returns

Vec2

Returns itself, modified

# addNew(vector)

Clones the vector and adds the vector to it instead

Parameters

Name Types Description
vector Vec2 The vector to add to this one

Returns

Vec2

Returns the clone of itself, modified

# addScalar(scalar)

Adds a scalar to the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec2

Returns itself, modified

# addScalarNew(scalar)

Clones the vector and adds the scalar to it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec2

Returns the clone of itself, modified

# angle()

(getter/setter) The angle of the vector, in radians

# angleInDegrees()

(getter/setter) The angle of the vector, in radians

# area()

(getter) Vector area.

# array()

(getter) Returns the basic array representation of this vector.

# clone()

Clones the vector

Returns

Vector

The cloned vector

# cross(vector)

Calculates the cross product between this and the supplied vector.

Parameters

Name Types Description
vector Vec2 The vector object against which to calculate the cross product

Returns

number

The cross product of the two vectors

# distance(vector)

Calculates the distance between this and the supplied vector

Parameters

Name Types Description
vector Vec2 The vector to calculate the distance from

Returns

number

The distance between this and the supplied vector

# distanceX(vector)

Calculates the distance on the X axis between this and the supplied vector

Parameters

Name Types Description
vector Vec2 The vector to calculate the distance from

Returns

number

The distance, along the x axis, between this and the supplied vector

# distanceY(vector)

Calculated the distance on the Y axis between this and the supplied vector

Parameters

Name Types Description
vector Vec2 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# divide(vector)

Divides one vector by another.

Parameters

Name Types Description
vector Vec2 The vector to divide this by

Returns

Vec2

Returns itself, modified

# divideNew(vector)

Clones the vector and divides it by the vector instead

Parameters

Name Types Description
vector Vec2 The vector to divide the clone by

Returns

Vec2

Returns the clone of itself, modified

# divideScalar(scalar)

Divides the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec2

Returns itself, modified

# divideScalarNew(scalar)

Clones the vector and divides it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec2

Returns the clone of itself, modified

# dot(vector)

Calculates the dot product between this and a supplied vectorT

Parameters

Name Types Description
vector Vec2 The vector object against which to calculate the dot product

Returns

number

The dot product of the two vectors

# getAngle(a, b)

Finds the angle between 2 vectors.

Parameters

Name Types Description
a vec2 the first operand
b vec2 the second operand

# height()

(getter/setter) Vector height. Alias of {@link Vector#x x}

# interpolate(v)

Iterpolates a provided anonymous value into a vew Vec2

Parameters

Name Types Description
v Vec2 array

# inverse()

Inverses the vector.

Returns

Vec2

Returns itself, modified

# inverseNew()

Clones the vector and then inverses it.

Returns

Vec2

Returns itself, modified

# length()

(getter/setter) The length of the vector

# lengthSquared()

(getter/setter) The length of the vector presented as a square. If you're using length for comparison, this is quicker.

# lerp(v1, v2, d)

Performs a linear interpolation between two vec2's

Parameters

Name Types Description
v1 vec2 the first operand
v2 vec2 the second operand
d Number interpolation amount in the range of 0 - 1

# multiply(vector)

Multiplies one vector by another.

Parameters

Name Types Description
vector Vec2 The vector to multiply this by

Returns

Vec2

Returns itself, modified

# multiplyNew(vector)

Clones the vector and multiplies it by the vector instead

Parameters

Name Types Description
vector Vec2 The vector to multiply the clone by

Returns

Vec2

Returns the clone of itself, modified

# multiplyScalar(scalar)

Multiplies the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec2

Returns itself, modified

# multiplyScalarNew(scalar)

Clones the vector and multiplies it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec2

Returns the clone of itself, modified

# negate()

Negates the vector.

Returns

Vec2

Returns itself, modified

# negateNew()

Clones the vector and negates it.

Returns

Vec2

Returns itself, modified

# normalise()

Normalises the vector down to a length of 1 unit

Returns

Vec2

Returns itself, modified

# normaliseNew()

Clones the vector and normalises it

Returns

Vec2

Returns a clone of itself, modified

# resetToVector(v)

Resets the vector coordinates to another vector object

Parameters

Name Types Description
v Vector The vector object to use to reset the coordinates

# rotate(radian)

Rotates a vecor by a given amount, provided in radians.

Parameters

Name Types Description
radian number The angle, in radians, to rotate the vector by

Returns

Vec2

Returns itself, modified

# rotateBy()

Alias of {@link Vector#rotate__anchor rotate}

# rotateByNew()

Alias of {@link Vector#rotateNew__anchor rotateNew}

# rotateDeg(degrees)

Rotates a vecor by a given amount, provided in degrees. Converts the degree value to radians and runs the rotaet method.

Parameters

Name Types Description
degrees number The angle, in degrees, to rotate the vector by

Returns

Vec2

Returns itself, modified

# rotateDegBy()

Alias of {@link Vector#rotateDeg__anchor rotateDeg}

# rotateDegByNew()

Alias of {@link Vector#rotateDegNew__anchor rotateDegNew}

# rotateDegNew(degrees)

Clones the vector and rotates it by the supplied degree value

Parameters

Name Types Description
degrees number The angle, in degrees, to rotate the vector by

Returns

Vec2

Returns the clone of itself, modified

# rotateNew(radian)

Clones the vector and rotates it by the supplied radian value

Parameters

Name Types Description
radian number The angle, in radians, to rotate the vector by

Returns

Vec2

Returns the clone of itself, modified

# rotateTo(radian)

Rotates a vector to a specific angle

Parameters

Name Types Description
radian number The angle, in radians, to rotate the vector to

Returns

Vec2

Returns itself, modified

# rotateToDeg(degrees)

Rotates a vecor to a given amount, provided in degrees. Converts the degree value to radians and runs the rotateTo method.

Parameters

Name Types Description
degrees number The angle, in degrees, to rotate the vector to

Returns

Vec2

Returns itself, modified

# rotateToDegNew(degrees)

Clones the vector and rotates it to the supplied degree value

Parameters

Name Types Description
degrees number The angle, in degrees, to rotate the vector to

Returns

Vec2

Returns the clone of itself, modified

# rotateToNew(radian)

Clones the vector and rotates it to the supplied radian value

Parameters

Name Types Description
radian number The angle, in radians, to rotate the vector to

Returns

Vec2

Returns the clone of itself, modified

# scale()

Alias of {@link Vector#multiplyScalar__anchor multiplyScalar}

# scaleNew()

Alias of {@link Vector#multiplyScalarNew__anchor multiplyScalarNew}

# slope()

(getter/setter) Vector slope.

# subtract(vector)

Subtracts one vector from another.

Parameters

Name Types Description
vector Vec2 The vector to subtract from this one

Returns

Vec2

Returns itself, modified

# subtractNew(vector)

Clones the vector and subtracts the vector from it instead

Parameters

Name Types Description
vector Vec2 The vector to subtract from this one

Returns

Vec2

Returns the clone of itself, modified

# subtractScalar(scalar)

Subtracts a scalar from the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to subtract from the vector

Returns

Vec2

Returns itself, modified

# subtractScalarNew(scalar)

Clones the vector and subtracts the scalar from it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec2

Returns the clone of itself, modified

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# Vec2()

A basic 2D Vector class that provides simple algebraic functionality in the form of 2D Vectors. We use Getters/setters for both principle properties (x & y) as well as virtual properties (rotation, length etc.).

# width()

(getter/setter) Vector width. Alias of {@link Vector#x x}

# x()

(getter/setter) The x value of the vector.

# xx()

(getter/sette) Swizzle XX

# xy()

(getter/sette) Swizzle XY

# y()

(getter/setter) The y value of the vector.

# yx()

(getter/sette) Swizzle YX

# yy()

(getter/sette) Swizzle YY

# ...args(x, y, z)

The Vector Class constructor

Parameters

Name Types Description
x number The x coord
y number The y coord
z number The z coord

# ...args(x, y, z)

Resets the vector coordinates

Parameters

Name Types Description
x number The x coord
y number The y coord
z number The z coord

# add(vector)

Adds one vector to another.

Parameters

Name Types Description
vector Vec3 The vector to add to this one

Returns

Vec3

Returns itself, modified

# addNew(vector)

Clones the vector and adds the vector to it instead

Parameters

Name Types Description
vector Vec3 The vector to add to this one

Returns

Vec3

Returns the clone of itself, modified

# addScalar(scalar)

Adds a scalar to the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec3

Returns itself, modified

# addScalarNew(scalar)

Clones the vector and adds the scalar to it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec3

Returns the clone of itself, modified

# area()

(getter) Vector area.

# array()

(getter) Returns the basic array representation of this vector.

# clone()

Clones the vector

Returns

Vec3

The cloned vector

# cross(vector)

Calculates the cross product between this and the supplied vector.

Parameters

Name Types Description
vector Vec3 The vector object against which to calculate the cross product

Returns

Vec3

The cross product of the two vectors

# depth()

(getter/setter) Vector height. Alias of {@link Vector#x x}

# distance(vector)

Calculates the distance between this and the supplied vector

Parameters

Name Types Description
vector Vec3 The vector to calculate the distance from

Returns

number

The distance between this and the supplied vector

# distanceX(vector)

Calculates the distance on the X axis between this and the supplied vector

Parameters

Name Types Description
vector Vec3 The vector to calculate the distance from

Returns

number

The distance, along the x axis, between this and the supplied vector

# distanceY(vector)

Calculated the distance on the Y axis between this and the supplied vector

Parameters

Name Types Description
vector Vec3 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# distanceZ(vector)

Calculated the distance on the Z axis between this and the supplied vector

Parameters

Name Types Description
vector Vec3 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# divide(vector)

Divides one vector by another.

Parameters

Name Types Description
vector Vec3 The vector to divide this by

Returns

Vec3

Returns itself, modified

# divideNew(vector)

Clones the vector and divides it by the vector instead

Parameters

Name Types Description
vector Vec3 The vector to divide the clone by

Returns

Vec3

Returns the clone of itself, modified

# divideScalar(scalar)

Divides the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec3

Returns itself, modified

# divideScalarNew(scalar)

Clones the vector and divides it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec3

Returns the clone of itself, modified

# dot(vector)

Calculates the dot product between this and a supplied vector

Parameters

Name Types Description
vector Vec3 The vector object against which to calculate the dot product

Returns

number

The dot product of the two vectors

# height()

(getter/setter) Vector height. Alias of {@link Vector#x x}

# interpolate(v)

Iterpolates a provided anonymous value into a vew Vec3

Parameters

Name Types Description
v Vec3 array

# inverse()

Inverses the vector.

Returns

Vec3

Returns itself, modified

# inverseNew()

Clones the vector and then inverses it.

Returns

Vec3

Returns itself, modified

# length()

(getter/setter) The length of the vector

# lengthSquared()

(getter/setter) The length of the vector presented as a square. If you're using length for comparison, this is quicker.

# lerp(v1, v2, d)

Performs a linear interpolation between two Vec3's

Parameters

Name Types Description
v1 Vec3 the first operand
v2 Vec3 the second operand
d Number interpolation amount in the range of 0 - 1

# multiply(vector)

Multiplies one vector by another.

Parameters

Name Types Description
vector Vec3 The vector to multiply this by

Returns

Vec3

Returns itself, modified

# multiplyNew(vector)

Clones the vector and multiplies it by the vector instead

Parameters

Name Types Description
vector Vec3 The vector to multiply the clone by

Returns

Vec3

Returns the clone of itself, modified

# multiplyScalar(scalar)

Multiplies the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec3

Returns itself, modified

# multiplyScalarNew(scalar)

Clones the vector and multiplies it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec3

Returns the clone of itself, modified

# negate()

Negates the vector.

Returns

Vec3

Returns itself, modified

# negateNew()

Clones the vector and negates it.

Returns

Vec3

Returns itself, modified

# normalise()

Normalises the vector down to a length of 1 unit

Returns

Vec3

Returns itself, modified

# normaliseNew()

Clones the vector and normalises it

Returns

Vec3

Returns a clone of itself, modified

# phi()

(getter/setter) Spherical phi. For using a vec3 as spherical coordinates. Alias of {@link Vector#y y}

# radius()

(getter/setter) Spherical radius. For using a vec3 as spherical coordinates. Alias of {@link Vector#x x}

# resetToVector(v)

Resets the vector coordinates to another vector object

Parameters

Name Types Description
v Vec3 The vector object to use to reset the coordinates

# scale()

Alias of {@link Vector#multiplyScalar__anchor multiplyScalar}

# scaleNew()

Alias of {@link Vector#multiplyScalarNew__anchor multiplyScalarNew}

# subtract(vector)

Subtracts one vector from another.

Parameters

Name Types Description
vector Vec3 The vector to subtract from this one

Returns

Vec3

Returns itself, modified

# subtractNew(vector)

Clones the vector and subtracts the vector from it instead

Parameters

Name Types Description
vector Vec3 The vector to subtract from this one

Returns

Vec3

Returns the clone of itself, modified

# subtractScalar(scalar)

Subtracts a scalar from the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to subtract from the vector

Returns

Vec3

Returns itself, modified

# subtractScalarNew(scalar)

Clones the vector and subtracts the scalar from it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec3

Returns the clone of itself, modified

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# theta()

(getter/setter) Spherical theta. For using a vec3 as spherical coordinates. Alias of {@link Vector#z z}

# Vec3()

A basic 3D Vector class that provides simple algebraic functionality in the form of 3D Vectors. We use Getters/setters for both principle properties (x & y) as well as virtual properties (rotation, length etc.).

# width()

(getter/setter) Vector width. Alias of {@link Vector#x x}

# x()

(getter/setter) The x value of the vector.

# xx()

(getter/sette) Swizzle XX

# xy()

(getter/sette) Swizzle XY

# xyz()

(getter/sette) Swizzle XYZ

# y()

(getter/setter) The y value of the vector.

# yx()

(getter/sette) Swizzle YX

# yy()

(getter/sette) Swizzle YY

# yz()

(getter/sette) Swizzle YZ

# yzx()

(getter/sette) Swizzle YZX

# z()

(getter/setter) The y value of the vector.

# zx()

(getter/sette) Swizzle zx

# zxy()

(getter/sette) Swizzle ZXY

# zy()

(getter/sette) Swizzle ZY

# zz()

(getter/sette) Swizzle ZZ

# ...args(x, y)

The Vector Class constructor

Parameters

Name Types Description
x number The x coord
y number The y coord

# ...args(x, y, z, w)

Resets the vector coordinates

Parameters

Name Types Description
x number The x coord
y number The y coord
z number The z coord
w number The w coord

# _w()

(getter/setter) The y value of the vector.

# _x()

(getter/setter) The x value of the vector.

# _y()

(getter/setter) The y value of the vector.

# _z()

(getter/setter) The y value of the vector.

# add(vector)

Adds one vector to another.

Parameters

Name Types Description
vector Vec4 The vector to add to this one

Returns

Vec4

Returns itself, modified

# addNew(vector)

Clones the vector and adds the vector to it instead

Parameters

Name Types Description
vector Vec4 The vector to add to this one

Returns

Vec4

Returns the clone of itself, modified

# addScalar(scalar)

Adds a scalar to the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec4

Returns itself, modified

# addScalarNew(scalar)

Clones the vector and adds the scalar to it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec4

Returns the clone of itself, modified

# area()

(getter) Vector area.

# array()

(getter) Returns the basic array representation of this vector.

# clone()

Clones the vector

Returns

Vec4

The cloned vector

# cross(vector)

Calculates the cross product between this and two other supplied vectors

Parameters

Name Types Description
vector Vec4 The vector object against which to calculate the cross product

Returns

Vec4

The cross product of the two vectors

# depth()

(getter/setter) Vector height. Alias of {@link Vector#x x}

# distance(vector)

Calculates the distance between this and the supplied vector

Parameters

Name Types Description
vector Vec4 The vector to calculate the distance from

Returns

number

The distance between this and the supplied vector

# distanceW(vector)

Calculated the distance on the W axis between this and the supplied vector

Parameters

Name Types Description
vector Vec4 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# distanceX(vector)

Calculates the distance on the X axis between this and the supplied vector

Parameters

Name Types Description
vector Vec4 The vector to calculate the distance from

Returns

number

The distance, along the x axis, between this and the supplied vector

# distanceY(vector)

Calculated the distance on the Y axis between this and the supplied vector

Parameters

Name Types Description
vector Vec4 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# distanceZ(vector)

Calculated the distance on the Z axis between this and the supplied vector

Parameters

Name Types Description
vector Vec4 The vector to calculate the distance from

Returns

number

The distance, along the y axis, between this and the supplied vector

# divide(vector)

Divides one vector by another.

Parameters

Name Types Description
vector Vec4 The vector to divide this by

Returns

Vec4

Returns itself, modified

# divideNew(vector)

Clones the vector and divides it by the vector instead

Parameters

Name Types Description
vector Vec4 The vector to divide the clone by

Returns

Vec4

Returns the clone of itself, modified

# divideScalar(scalar)

Divides the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec4

Returns itself, modified

# divideScalarNew(scalar)

Clones the vector and divides it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to divide both x and y by

Returns

Vec4

Returns the clone of itself, modified

# dot(vector)

Calculates the dot product between this and a supplied vector

Parameters

Name Types Description
vector Vec4 The vector object against which to calculate the dot product

Returns

number

The dot product of the two vectors

# height()

(getter/setter) Vector height. Alias of {@link Vector#x x}

# interpolate(v)

Iterpolates a provided anonymous value into a vew Vec4

Parameters

Name Types Description
v Vec4 array

# inverse()

Inverses the vector.

Returns

Vec4

Returns itself, modified

# inverseNew()

Clones the vector and then inverses it.

Returns

Vec4

Returns itself, modified

# length()

(getter/setter) The length of the vector

# lengthSquared()

(getter/setter) The length of the vector presented as a square. If you're using length for comparison, this is quicker.

# lerp(v1, v2, d)

Performs a linear interpolation between two Vec4's

Parameters

Name Types Description
v1 Vec4 the first operand
v2 Vec4 the second operand
d Number interpolation amount in the range of 0 - 1

# multiply(vector)

Multiplies one vector by another.

Parameters

Name Types Description
vector Vec4 The vector to multiply this by

Returns

Vec4

Returns itself, modified

# multiplyNew(vector)

Clones the vector and multiplies it by the vector instead

Parameters

Name Types Description
vector Vec4 The vector to multiply the clone by

Returns

Vec4

Returns the clone of itself, modified

# multiplyScalar(scalar)

Multiplies the vector by a scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec4

Returns itself, modified

# multiplyScalarNew(scalar)

Clones the vector and multiplies it by the provided scalar.

Parameters

Name Types Description
scalar number The scalar to multiply both x and y by

Returns

Vec4

Returns the clone of itself, modified

# negate()

Negates the vector.

Returns

Vec4

Returns itself, modified

# negateNew()

Clones the vector and negates it.

Returns

Vec4

Returns itself, modified

# normalise()

Normalises the vector down to a length of 1 unit

Returns

Vec4

Returns itself, modified

# normaliseNew()

Clones the vector and normalises it

Returns

Vec4

Returns a clone of itself, modified

# resetToVector(v)

Resets the vector coordinates to another vector object

Parameters

Name Types Description
v Vec4 The vector object to use to reset the coordinates

# scale()

Alias of {@link Vector#multiplyScalar__anchor multiplyScalar}

# scaleNew()

Alias of {@link Vector#multiplyScalarNew__anchor multiplyScalarNew}

# subtract(vector)

Subtracts one vector from another.

Parameters

Name Types Description
vector Vec4 The vector to subtract from this one

Returns

Vec4

Returns itself, modified

# subtractNew(vector)

Clones the vector and subtracts the vector from it instead

Parameters

Name Types Description
vector Vec4 The vector to subtract from this one

Returns

Vec4

Returns the clone of itself, modified

# subtractScalar(scalar)

Subtracts a scalar from the vector, modifying both the x and y

Parameters

Name Types Description
scalar number The scalar to subtract from the vector

Returns

Vec4

Returns itself, modified

# subtractScalarNew(scalar)

Clones the vector and subtracts the scalar from it instead

Parameters

Name Types Description
scalar number The scalar to add to the vector

Returns

Vec4

Returns the clone of itself, modified

# Symbol.iterator()

Adds iteration to the object, allowing it to be destructured and iterated upon in various useful ways.

# Vec4()

A basic 3D Vector class that provides simple algebraic functionality in the form of 3D Vectors. We use Getters/setters for both principle properties (x & y) as well as virtual properties (rotation, length etc.).

# width()

(getter/setter) Vector width. Alias of {@link Vector#x x}

# ww()

(getter/sette) Swizzle WW

# wx()

(getter/sette) Swizzle wx

# wxyz()

(getter/sette) Swizzle XYZW

# wy()

(getter/sette) Swizzle WY

# wz()

(getter/sette) Swizzle WZ

# xw()

(getter/sette) Swizzle XY

# xx()

(getter/sette) Swizzle XX

# xy()

(getter/sette) Swizzle XY

# xyz()

(getter/sette) Swizzle YZX

# xyzw()

(getter/sette) Swizzle XYZW

# xz()

(getter/sette) Swizzle XY

# yw()

(getter/sette) Swizzle YZ

# yx()

(getter/sette) Swizzle YX

# yy()

(getter/sette) Swizzle YY

# yz()

(getter/sette) Swizzle YZ

# yzwx()

(getter/sette) Swizzle XYZW

# yzx()

(getter/sette) Swizzle YZX

# zw()

(getter/sette) Swizzle XY

# zwxy()

(getter/sette) Swizzle XYZW

# zx()

(getter/sette) Swizzle zx

# zxy()

(getter/sette) Swizzle ZXY

# zy()

(getter/sette) Swizzle ZY

# zz()

(getter/sette) Swizzle ZZ