API Docs for: 1.0.0

xeogl.math.math

Defined in: src/math/math.js:12
Module: math
Parent Module: xeogl

This utility object provides math functions that are used within xeogl. These functions are also part of xeogl's public API and are therefore available for you to use within your application code.

Index

Methods

Properties

Methods

addMat4

() static

Adds the given 4x4 matrices together.

addMat4Scalar

() static

Adds the given scalar to each element of the given 4x4 matrix.

addScalarMat4

() static

Adds the given scalar to each element of the given 4x4 matrix.

addVec3

(
  • u
  • v
  • [dest]
)
Array(Number) static

Adds one three-element vector to another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

addVec4

(
  • u
  • v
  • [dest]
)
Array(Number) static

Adds one four-element vector to another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

addVec4Scalar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Adds a scalar value to each element of a three-element vector.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

addVec4Scalar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Adds a scalar value to each element of a four-element vector.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

angleVec3

(
  • v
  • w
)
Number

Gets the angle between two vectors

Parameters:

  • v Object
  • w Object

Returns:

Number:

createUUID

() static

Returns a new UUID.

Returns:

string The new UUID

cross3Vec3

(
  • u
  • v
)
static

Returns the cross product of two three-element vectors.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

Returns:

The cross product

cross3Vec4

(
  • u
  • v
)
static

Returns the cross product of two four-element vectors.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

Returns:

The cross product

determinantMat4

() static

Returns the determinant of the given 4x4 matrix.

diagonalMat4c

() static

Returns a 4x4 matrix with diagonal elements set to the given vector.

diagonalMat4s

() static

Returns a 4x4 matrix with diagonal elements set to the given scalar.

divScalarVec3

(
  • v
  • s
  • dest
)
static

Divides a scalar by a three-element vector, returning a new vector.

Parameters:

  • v Object

    vec3

  • s Object

    scalar

  • dest Object

    vec3 - optional destination

Returns:

[] dest if specified, v otherwise

divScalarVec4

(
  • s
  • v
  • dest
)
static

Divides a scalar by a four-element vector, returning a new vector.

Parameters:

  • s Object

    scalar

  • v Object

    vec4

  • dest Object

    vec4 - optional destination

Returns:

[] dest if specified, v otherwise

divVec3

(
  • u
  • v
  • [dest]
)
Array(Number) static

Divides one three-element vector by another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

divVec3Scalar

(
  • v
  • s
  • dest
)
static

Divides a three-element vector by a scalar.

Parameters:

  • v Object

    vec3

  • s Object

    scalar

  • dest Object

    vec3 - optional destination

Returns:

[] dest if specified, v otherwise

divVec4

(
  • u
  • v
  • [dest]
)
Array(Number) static

Divides one four-element vector by another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

divVec4Scalar

(
  • v
  • s
  • dest
)
static

Divides a four-element vector by a scalar.

Parameters:

  • v Object

    vec4

  • s Object

    scalar

  • dest Object

    vec4 - optional destination

Returns:

[] dest if specified, v otherwise

dotVec4

(
  • u
  • v
)
static

Returns the dot product of two four-element vectors.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

Returns:

The dot product

dotVec4

(
  • u
  • v
)
static

Returns the dot product of two two-element vectors.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

Returns:

The dot product

dotVec4

(
  • u
  • v
)
static

Returns the dot product of two three-element vectors.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

Returns:

The dot product

dupMat4

() static

Duplicates a 4x4 identity matrix.

flatten

(
  • a
)
static

Flattens a two-dimensional array into a one-dimensional array.

Parameters:

  • a Array of Arrays

    A 2D array

Returns:

Flattened 1D array

fmod

(
  • a
  • b
)
static

Floating-point modulus

Parameters:

  • a Number
  • b Number

Returns:

:

frustumMat4v

() static

Returns a 4x4 perspective projection matrix.

frustumMat4v

() static

Returns a 4x4 perspective projection matrix.

identityMat4

() static

Returns a 4x4 identity matrix.

inverseMat4

() static

Returns the inverse of the given 4x4 matrix.

isIdentityMat4

() static

Tests if the given 4x4 matrix is the identity matrix.

lenVec2

(
  • v
)
static

Returns the length of a two-element vector.

Parameters:

  • v Array(Number)

    The vector

Returns:

The length

lenVec3

(
  • v
)
static

Returns the length of a three-element vector.

Parameters:

  • v Array(Number)

    The vector

Returns:

The length

lenVec4

(
  • v
)
static

Returns the length of a four-element vector.

Parameters:

  • v Array(Number)

    The vector

Returns:

The length

lerpVec3

() static

Linearly interpolates between two 3D vectors.

lookAtMat4c

() static

Returns a 4x4 'lookat' viewing transform matrix.

lookAtMat4v

(
  • pos
  • target
  • up
  • dest
)
Mat4

Returns a 4x4 'lookat' viewing transform matrix.

Parameters:

  • pos Object

    vec3 position of the viewer

  • target Object

    vec3 point the viewer is looking at

  • up Object

    vec3 pointing "up"

  • dest Object

    mat4 Optional, mat4 matrix will be written into

Returns:

Mat4:

dest if specified, a new mat4 otherwise

m4s

() static

Returns a 4x4 matrix with each element set to the given scalar value.

mat3

(
  • [values]
)
Float32Array static

Defined in src/math/math.js:65

Returns a new, uninitialized 3x3 matrix.

Parameters:

  • [values] Object optional

    Initial values.

Returns:

Float32Array:

mat3ToMat4

(
  • mat3
  • mat4
)
Float32Array static

Defined in src/math/math.js:76

Converts a 3x3 matrix to 4x4

Parameters:

  • mat3 Object

    3x3 matrix.

  • mat4 Object

    4x4 matrix

Returns:

Float32Array:

mat4

(
  • [values]
)
Float32Array static

Defined in src/math/math.js:88

Returns a new, uninitialized 4x4 matrix.

Parameters:

  • [values] Object optional

    Initial values.

Returns:

Float32Array:

mat4To3

() static

Extracts a 3x3 matrix from a 4x4 matrix.

mat4ToMat3

(
  • mat4
  • mat3
)
Float32Array static

Defined in src/math/math.js:99

Converts a 4x4 matrix to 3x3

Parameters:

  • mat4 Object

    4x4 matrix.

  • mat3 Object

    3x3 matrix

Returns:

Float32Array:

mulMat4

() static

Multiplies the two given 4x4 matrix by each other.

mulMat4Scalar

() static

Multiplies each element of the given 4x4 matrix by the given scalar.

mulMat4v4

() static

Multiplies the given 4x4 matrix by the given four-element vector.

mulVec2Scalar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Multiplies each element of a two-element vector by a scalar.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

mulVec3

(
  • u
  • v
  • [dest]
)
Array(Number) static

Multiplies one three-element vector by another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Second vector

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

mulVec34calar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Multiplies each element of a four-element vector by a scalar.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

mulVec3Scalar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Multiplies each element of a three-element vector by a scalar.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

negateMat4

() static

Negates the given 4x4 matrix.

negateVec4

(
  • v
  • [dest]
)
Array(Number) static

Negates a four-element vector.

Parameters:

  • v Array(Number)

    Vector to negate

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

normalizeVec2

() static

Normalizes a two-element vector

normalizeVec4

() static

Normalizes a three-element vector

normalizeVec4

(
  • v
  • dest
)
static

Normalizes a four-element vector

Parameters:

  • v Object

    vec4

  • dest Object

    vec4 - optional destination

Returns:

[] dest if specified, v otherwise

orthoMat4c

() static

Returns a 4x4 orthographic projection matrix.

perspectiveMat4v

() static

Returns a 4x4 perspective projection matrix.

projectVec4

(
  • p
  • q
)
Float32Array static

Transforms a four-element vector by a 4x4 projection matrix.

Parameters:

  • p Float32Array

    3D View-space coordinate

  • q Float32Array

    2D Projected coordinate

Returns:

Float32Array:

2D Projected coordinate

rcpVec3

(
  • v
  • dest
)
static

Parameters:

  • v Object

    vec3

  • dest Object

    vec3 - optional destination

Returns:

[] dest if specified, v otherwise

rotateVec3X

(
  • a
  • b
  • c
  • dest
)
Float32Array static

Rotate a 3D vector around the x-axis

Parameters:

  • a Float32Array

    The vec3 point to rotate

  • b Float32Array

    The origin of the rotation

  • c Number

    The angle of rotation

  • dest Float32Array

    The receiving vec3

Returns:

Float32Array:

dest

rotateVec3Y

(
  • a
  • b
  • c
  • dest
)
Float32Array static

Rotate a 3D vector around the y-axis

Parameters:

  • a Float32Array

    The vec3 point to rotate

  • b Float32Array

    The origin of the rotation

  • c Number

    The angle of rotation

  • dest Float32Array

    The receiving vec3

Returns:

Float32Array:

dest

rotateVec3Z

(
  • a
  • b
  • c
  • dest
)
Float32Array static

Rotate a 3D vector around the z-axis

Parameters:

  • a Float32Array

    The vec3 point to rotate

  • b Float32Array

    The origin of the rotation

  • c Number

    The angle of rotation

  • dest Float32Array

    The receiving vec3

Returns:

Float32Array:

dest

rotationMat4c

() static

Returns 4x4 rotation matrix.

rotationMat4v

() static

Returns 4x4 rotation matrix.

scaleMat4c

(
  • xyz
  • m
)

Efficiently post-concatenates a scaling to the given matrix.

Parameters:

  • xyz Object
  • m Object

scaleMat4c

(
  • x
  • y
  • z
  • m
)

Efficiently post-concatenates a scaling to the given matrix.

Parameters:

  • x Object
  • y Object
  • z Object
  • m Object

scalingMat4c

() static

Returns 4x4 scale matrix.

scalingMat4s

() static

Returns 4x4 scale matrix.

scalingMat4v

() static

Returns 4x4 scale matrix.

setMat4ToOnes

() static

Returns a 4x4 matrix with each element set to 1.0.

setMat4ToOnes

() static

Returns a 4x4 matrix with each element set to 1.0.

setMat4ToZeroes

() static

Returns a 4x4 matrix with each element set to zero.

subMat4

() static

Subtracts the second 4x4 matrix from the first.

subMat4Scalar

() static

Subtracts the given scalar from each element of the given 4x4 matrix.

subScalarMat4

() static

Subtracts the given scalar from each element of the given 4x4 matrix.

subScalarVec4

(
  • v
  • s
  • [dest]
)
Array(Number) static

Sets each element of a 4-element vector to a scalar value minus the value of that element.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

subVec2

(
  • u
  • v
  • [dest]
)
Array(Number) static

Subtracts one two-element vector from another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Vector to subtract

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

subVec3

(
  • u
  • v
  • [dest]
)
Array(Number) static

Subtracts one three-element vector from another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Vector to subtract

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

subVec4

(
  • u
  • v
  • [dest]
)
Array(Number) static

Subtracts one four-element vector from another.

Parameters:

  • u Array(Number)

    First vector

  • v Array(Number)

    Vector to subtract

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, u otherwise

subVec4Scalar

(
  • v
  • s
  • [dest]
)
Array(Number) static

Subtracts a scalar value from each element of a four-element vector.

Parameters:

  • v Array(Number)

    The vector

  • s Number

    The scalar

  • [dest] Array(Number) optional

    Destination vector

Returns:

Array(Number):

dest if specified, v otherwise

traceMat4

() static

Returns the trace of the given 4x4 matrix.

transformPoint3

() static

Transforms a three-element position by a 4x4 matrix.

transformPoint3

() static

Transforms a homogeneous coordinate by a 4x4 matrix.

transformPoints3

() static

Transforms an array of three-element positions by a 4x4 matrix.

transformPositions3

() static

Transforms an array of positions by a 4x4 matrix.

transformPositions4

() static

Transforms an array of positions by a 4x4 matrix.

transformVec3

() static

Transforms a three-element vector by a 4x4 matrix.

transformVec4

() static

Transforms a four-element vector by a 4x4 matrix.

translationMat4

() static

Returns 4x4 translation matrix.

translationMat4c

() static

Returns 4x4 translation matrix.

translationMat4s

() static

Returns 4x4 translation matrix.

transposeMat4

() static

Transposes the given 4x4 matrix.

vec2

(
  • [values]
)
Float32Array static

Defined in src/math/math.js:32

Returns a new, uninitialized two-element vector.

Parameters:

  • [values] Object optional

    Initial values.

Returns:

Float32Array:

vec3

(
  • [values]
)
Float32Array static

Defined in src/math/math.js:43

Returns a new, uninitialized three-element vector.

Parameters:

  • [values] Object optional

    Initial values.

Returns:

Float32Array:

vec4

(
  • [values]
)
Float32Array static

Defined in src/math/math.js:54

Returns a new, uninitialized four-element vector.

Parameters:

  • [values] Object optional

    Initial values.

Returns:

Float32Array:

Properties

DEGTORAD

Number

Defined in src/math/math.js:24

The number of radiians in a degree (0.0174532925).