H3DU.MathUtil

Back to documentation index.

### new H3DU.MathUtil()

A collection of math functions for working with vectors, matrices, quaternions, and other mathematical objects.

See the tutorial “H3DU’s Math Functions” for more information.

Members

Methods

### H3DU.MathUtil.GlobalPitchRollYaw (constant)

Indicates that a vector’s rotation occurs as a pitch, then roll, then yaw (each rotation around the original axes).

### H3DU.MathUtil.GlobalPitchYawRoll (constant)

Indicates that a vector’s rotation occurs as a pitch, then yaw, then roll (each rotation around the original axes), or in the reverse order around

### H3DU.MathUtil.GlobalRollPitchYaw (constant)

Indicates that a vector’s rotation occurs as a roll, then pitch, then yaw (each rotation around the original axes).

### H3DU.MathUtil.GlobalRollYawPitch (constant)

Indicates that a vector’s rotation occurs as a roll, then yaw, then pitch (each rotation around the original axes).

### H3DU.MathUtil.GlobalYawPitchRoll (constant)

Indicates that a vector’s rotation occurs as a yaw, then pitch, then roll (each rotation around the original axes).

### H3DU.MathUtil.GlobalYawRollPitch (constant)

Indicates that a vector’s rotation occurs as a yaw, then roll, then pitch (each rotation around the original axes).

### H3DU.MathUtil.HalfPi (constant)

Closest approximation to pi divided by 2, or a 90-degree turn in radians.

Default Value: 1.5707963267948966

### H3DU.MathUtil.LocalPitchRollYaw (constant)

Indicates that a vector’s rotation occurs as a pitch, then roll, then yaw, where the roll and yaw occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.LocalPitchYawRoll (constant)

Indicates that a vector’s rotation occurs as a pitch, then yaw, then roll, where the yaw and roll occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.LocalRollPitchYaw (constant)

Indicates that a vector’s rotation occurs as a roll, then pitch, then yaw, where the pitch and yaw occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.LocalRollYawPitch (constant)

Indicates that a vector’s rotation occurs as a roll, then yaw, then pitch, where the yaw and pitch occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.LocalYawPitchRoll (constant)

Indicates that a vector’s rotation occurs as a yaw, then pitch, then roll, where the pitch and roll occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.LocalYawRollPitch (constant)

Indicates that a vector’s rotation occurs as a yaw, then roll, then pitch, where the roll and pitch occur around the rotated object’s new axes and not necessarily the original axes.

### H3DU.MathUtil.Num180DividedByPi (constant)

Closest approximation to 180 divided by pi, or the number of degrees in a radian. Multiply by this number to convert radians to degrees.

Default Value: 57.29577951308232

### H3DU.MathUtil.PiDividedBy180 (constant)

Closest approximation to pi divided by 180, or the number of radians in a degree. Multiply by this number to convert degrees to radians.

Default Value: 0.017453292519943295

### H3DU.MathUtil.PiTimes2 (constant)

Closest approximation to pi times 2, or a 360-degree turn in radians.

Default Value: 6.283185307179586

### H3DU.MathUtil.ToDegrees (constant)

Closest approximation to 180 divided by pi, or the number of degrees in a radian. Multiply by this number to convert radians to degrees.

### H3DU.MathUtil.ToRadians (constant)

Closest approximation to pi divided by 180, or the number of radians in a degree. Multiply by this number to convert degrees to radians.

### (static) H3DU.MathUtil.boxCenter(box)

Finds the center of a 3D bounding box.

Parameters

Return Value

A 3-element array containing the X, Y, and Z coordinates, respectively, of the bounding box’s center. (Type: Array.<number>)

### (static) H3DU.MathUtil.boxDimensions(box)

Finds the dimensions of a 3D bounding box. This is done by subtracting the first three values of the given array with its last three values.

Parameters

Return Value

A 3-element array containing the width, height, and depth of the bounding box, respectively. If at least one of the minimum coordinates is greater than its corresponding maximum coordinate, the array can contain negative values. (Type: Array.<number>)

### (static) H3DU.MathUtil.boxIsEmpty(box)

Determines whether a 3D bounding box is empty. This is determined if the minimum coordinate is larger than the corresponding maximum coordinate.

Parameters

Return Value

true if at least one of the minimum coordinates is greater than its corresponding maximum coordinate; otherwise, false. (Type: boolean)

### (static) H3DU.MathUtil.colorToLinear(srgb)

Converts a color from encoded sRGB to linear sRGB using the sRGB transfer function, and returns a new vector with the result.

Linear RGB is linear because of its linear relationship of light emitted by a surface of the given color.

Parameters

Return Value

A three-element vector giving the red, green, and blue components, in that order, of the given color in linear sRGB. The alpha component will be as specified in the “srgb” parameter. (Type: Array.<number>)

### (static) H3DU.MathUtil.colorTosRGB(lin)

Converts a color from linear sRGB to encoded sRGB using the sRGB transfer function, and returns a new vector with the result.

Linear RGB is linear because of its linear relationship of light emitted by a surface of the given color.

Parameters

Return Value

lin A four-element vector giving the red, green, blue, and alpha components, in that order, of the given color in encoded sRGB. The alpha component will be as specified in the “lin” parameter. (Type: Array.<number>)

### (static) H3DU.MathUtil.frustumHasBox(frustum, box)

Determines whether an axis-aligned bounding box is at least partially inside a view frustum.

Parameters

Return Value

true if the box may be partially or totally inside the frustum; false if the box is definitely outside the frustum, or if the box is empty (see “boxIsEmpty”). (Type: boolean)

### (static) H3DU.MathUtil.frustumHasPoint(frustum, x, y, z)

Determines whether a point is outside or inside a view frustum.

Parameters

Return Value

true if the point is inside; otherwise false; (Type: boolean)

### (static) H3DU.MathUtil.frustumHasSphere(frustum, x, y, z, radius)

Determines whether a sphere is at least partially inside a view frustum.

Parameters

Return Value

true if the sphere is partially or totally inside the frustum; false otherwise. (Type: boolean)

### (static) H3DU.MathUtil.interpCubicBezier(a, b, c, d, t)

An interpolation timing function based on the path of a cubic Bézier curve with end points (0, 0) and (1, 1) and with two configurable control points. The X coordinates of the curve indicate time, and the Y coordinates of the curve indicate how far the interpolation has reached.

Parameters

Return Value

Number ranging from 0 through 1 that indicates how far the interpolation has reached. Returns 0 if t is 0 or less, and 1 if t is 1 or greater. (Type: number)

### (static) H3DU.MathUtil.mat3copy(mat)

Returns a copy of a 3x3 matrix.

Parameters

Return Value

Return value. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3identity()

Returns the identity 3x3 matrix (a matrix that keeps vectors unchanged when they are transformed with this matrix).

Return Value

Return value. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3invert(m)

Finds the inverse of a 3x3 matrix, describing a transformation that undoes the given transformation.

Parameters

Return Value

The resulting 3x3 matrix. Returns the identity matrix if this matrix’s determinant, or overall scaling factor, is 0 or extremely close to 0. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3multiply(a, b)

Multiplies two 3x3 matrices. A new matrix is returned. The matrices are multiplied such that the transformations they describe happen in reverse order. For example, if the first matrix (input matrix) describes a translation and the second matrix describes a scaling, the multiplied matrix will describe the effect of scaling then translation.

The matrix multiplication is effectively done by breaking up matrix b into three 3-element vectors (the first 3 elements make up the first vector, and so on), transforming each vector with matrix a, and putting the vectors back together into a new matrix.

Parameters

Return Value

The resulting 3x3 matrix. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3transform(mat, v, [vy], [vz])

Transforms a 3-element vector with a 3x3 matrix and returns the transformed vector.

Transforming a vector (v) with a matrix (mat) is effectively done by breaking up mat into three 3-element vectors (the first 3 elements make up the first vector, and so on), multiplying each vector in mat by the corresponding component in v, and adding up the resulting vectors (except v) to get the transformed vector.

Parameters

Return Value

The transformed vector. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3transpose(m3)

Returns the transpose of a 3x3 matrix. (A transpose is a matrix whose rows are converted to columns and vice versa.)

Parameters

Return Value

The resulting 3x3 matrix. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat3transposeInPlace(mat)

Transposes a 3x3 matrix in place without creating a new matrix. (A transpose is a matrix whose rows are converted to columns and vice versa.)

Parameters

Return Value

The parameter “mat”. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4copy(mat)

Returns a copy of a 4x4 matrix.

Parameters

Return Value

Return value. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4frustum(l, r, b, t, near, far)

Returns a 4x4 matrix representing a perspective projection in the form of a view frustum, or the limits in the “camera”’s view.

When just this matrix is used to transform vertices, the X, Y, and Z coordinates within the view volume (as is the case in WebGL) will range from -W to W (where W is the fourth component of the transformed vertex). For a matrix in which Z coordinates range from 0 to W, divide the 15th element of the result (zero-based index 14) by 2.

This method is designed for enabling a right-handed coordinate system. To adjust the result of this method for a left-handed system, reverse the sign of the 9th, 10th, 11th, and 12th elements of the result (zero-based indices 8, 9, 10, and 11).

Parameters

This value should be greater than 0, and should be set to the highest distance from the “camera” that the application can afford to clip out for being too close, for example, 0.5, 1, or higher. * far (Type: number)
The distance, in eye space, from the “camera” to the far clipping plane. Objects farther than this distance won’t be seen.
This value should be greater than 0 and should be set so that the absolute ratio of “far” to “near” is as small as the application can accept. (“near” is usually less than “far”, so that Z coordinates increase from near to far in the direction from the back to the front of the “eye”, as they do in WebGL when just this matrix is used to transform vertices. If “near” is greater than “far”, Z coordinates increase in the opposite direction.)
In the usual case that “far” is greater than “near”, depth buffer values will be more concentrated around the near plane than around the far plane due to the perspective projection. The greater the ratio of “far” to “near”, the more concentrated the values will be around the near plane, and the more likely two objects close to the far plane will have identical depth values. (Most WebGL implementations support 24-bit depth buffers, meaning they support 16,777,216 possible values per pixel.)

Return Value

The resulting 4x4 matrix. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4identity()

Returns the identity 4x4 matrix (a matrix that keeps vectors unchanged when they are transformed with this matrix).

Return Value

Return value. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4inverseTranspose3(m4)

Returns the transposed result of the inverted 3x3 upper left corner of the given 4x4 matrix.

This is usually used to convert a model-view matrix (view matrix multiplied by model or world matrix) to a matrix for transforming surface normals in order to keep them perpendicular to a surface transformed by the model-view matrix. Normals are then transformed by this matrix and then converted to unit vectors. But if the input matrix uses only rotations, translations, and/or uniform scaling (same scaling in X, Y, and Z), the 3x3 upper left of the input matrix can be used instead of the inverse-transpose matrix to transform the normals.

Parameters

Return Value

The resulting 3x3 matrix. If the matrix can’t be inverted, returns the identity 3x3 matrix. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4invert(m)

Finds the inverse of a 4x4 matrix, describing a transformation that undoes the given transformation.

Parameters

Return Value

The resulting 4x4 matrix. Returns the identity matrix if this matrix’s determinant, or overall scaling factor, is 0 or extremely close to 0. (Type: Array.<number>)

### (static) H3DU.MathUtil.mat4isIdentity(mat)

Returns whether a 4x4 matrix is the identity matrix.

Parameters

Return Value

Return value. (Type: boolean)

### (static) H3DU.MathUtil.mat4lookat(viewerPos, [lookingAt], [up])

Returns a 4x4 matrix that represents a camera view, transforming world space coordinates, shared by every object in a scene, to coordinates in eye space (also called camera space or view space). This essentially rotates a “camera” and moves it to somewhere in the scene. In eye space:<ul>

  • The "camera" is located at the origin (0,0,0), or at viewerPos in world space, and points away from the viewer toward the lookingAt position in world space. This generally puts lookingAt at the center of the view.
  • The X axis points rightward from the "camera"'s viewpoint.
  • The Y axis points upward from the center of the "camera" to its top. The up vector guides this direction.
  • The Z axis is parallel to the direction from the "camera" to the lookingAt point.</ul> This method is designed for use in a right-handed coordinate system (the Z axis's direction will be from the "camera" to the point looked at). To adjust the result of this method for a left-handed system, reverse the sign of the 1st, 3rd, 5th, 7th, 9th, 11th, 13th, and 15th elements of the result (zero-based indices 0, 2, 4, 6, 8, 10, 12, and 14); the Z axis's direction will thus be from the point looked at to the "camera". #### Parameters * `viewerPos` (Type: Array.<number>)
    A 3-element vector specifying the "camera" position in world space.
    When used in conjunction with an orthographic projection, set this parameter to the value of lookingAt plus a unit vector (for example, using MathUtil.vec3add) to form an axonometric projection (if the unit vector is [sqrt(1/3),sqrt(1/3),sqrt(1/3)], the result is an isometric projection). See the examples below. * `lookingAt` (Type: Array.<number>) (optional)
    A 3-element vector specifying the point in world space that the "camera" is looking at. May be null or omitted, in which case the default is the coordinates (0,0,0). * `up` (Type: Array.<number>) (optional)
    A 3-element vector specifying the direction from the center of the "camera" to its top. This parameter may be null or omitted, in which case the default is the vector (0, 1, 0), the vector that results when the "camera" is held upright.
    This vector must not be parallel to the view direction (the direction from "viewerPos" to "lookingAt"). (See the example for one way to ensure this.)
    #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) #### Examples The following example calls this method with an up vector of (0, 1, 0) except if the view direction is parallel to that vector or nearly so. var upVector=[0,1,0]; // Y axis var viewdir=MathUtil.vec3sub(lookingAt, viewerPos); var par=MathUtil.vec3length(MathUtil.vec3cross(viewdir,upVector)); if(par<0.00001)upVector=[0,0,1]; // view is almost parallel, so use Z axis var matrix=MathUtil.mat4lookat(viewerPos,lookingAt,upVector); The following example creates an isometric projection for a right-handed coordinate system. The Y axis will point up, the Z axis toward the bottom left, and the X axis toward the bottom right. // Assumes an orthographic projection matrix is used. Example: // var projectionMatrix=MathUtil.mat4ortho(-10,10,-10,10,-50,50); // Camera will be at (1,1,1) -- actually (sqrt(1/3),sqrt(1/3),sqrt(1/3)) -- // and point toward [0,0,0] var lookPoint=[0,0,0]; var cameraPoint=MathUtil.vec3normalize([1,1,1]); cameraPoint=MathUtil.vec3add(cameraPoint,lookPoint); var matrix=MathUtil.mat4lookat(cameraPoint,lookPoint); The following example is like the previous example, but with the Z axis pointing up. var lookPoint=[0,0,0]; var cameraPoint=MathUtil.vec3normalize([1,1,1]); cameraPoint=MathUtil.vec3add(cameraPoint,lookPoint); // Positive Z axis is the up vector var matrix=MathUtil.mat4lookat(cameraPoint,lookPoint,[0,0,1]); The following example creates a camera view matrix using the viewer position, the viewing direction, and the up vector (a "look-to" matrix): var viewDirection=[0,0,1] var viewerPos=[0,0,0] var upVector=[0,1,0] var lookingAt=MathUtil.vec3add(viewerPos,viewDirection); var matrix=MathUtil.mat4lookat(viewerPos,lookingAt,upVector); ### (static) H3DU.MathUtil.mat4multiply(a, b) Multiplies two 4x4 matrices. A new matrix is returned. The matrices are multiplied such that the transformations they describe happen in reverse order. For example, if the first matrix (input matrix) describes a translation and the second matrix describes a scaling, the multiplied matrix will describe the effect of scaling then translation. The matrix multiplication is effectively done by breaking up matrix b into four 4-element vectors (the first 4 elements make up the first vector, and so on), transforming each vector with matrix a, and putting the vectors back together into a new matrix. #### Parameters * `a` (Type: Array.<number>)
    The first matrix. * `b` (Type: Array.<number>)
    The second matrix. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4oblique(alpha, phi) Returns a 4x4 view matrix representing an oblique projection, when used in conjunction with an orthographic projection. This method works the same way in right-handed and left-handed coordinate systems. #### Parameters * `alpha` (Type: number)
    Controls how much the Z axis is stretched. In degrees. A value of 45 (arctan(1)) indicates a cabinet projection, and a value of 63.435 (arctan(2)) indicates a cavalier projection. * `phi` (Type: number)
    Controls the apparent angle of the negative Z axis in relation to the positive X axis. In degrees. 0 means the negative Z axis appears to point in the same direction as the positive X axis, and 90, in the same direction as the positive Y axis. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4ortho(l, r, b, t, n, f) Returns a 4x4 matrix representing an orthographic projection. In this projection, the left clipping plane is parallel to the right clipping plane and the top to the bottom. The projection returned by this method only scales and/or shifts the view, so that objects with the same size won't appear smaller as they get more distant from the "camera". When just this matrix is used to transform vertices, the X, Y, and Z coordinates within the view volume (as is the case in WebGL) will range from -1 to 1. For a matrix in which Z coordinates range from 0 to 1, divide the 11th and 15th elements of the result (zero-based indices 10 and 14) by 2, then add 0.5 to the 15th element. This method is designed for enabling a right-handed coordinate system. To adjust the result of this method for a left-handed system, reverse the sign of the 11th element of the result (zero-based index 10). #### Parameters * `l` (Type: number)
    Leftmost coordinate of the orthographic view. * `r` (Type: number)
    Rightmost coordinate of the orthographic view. ("l" is usually less than "r", so that X coordinates increase from left to right. If "l" is greater than "r", X coordinates increase in the opposite direction.) * `b` (Type: number)
    Bottommost coordinate of the orthographic view. * `t` (Type: number)
    Topmost coordinate of the orthographic view. ("b" is usually less than "t", so that Y coordinates increase upward, as they do in WebGL when just this matrix is used to transform vertices. If "b" is greater than "t", Y coordinates increase in the opposite direction.) * `n` (Type: number)
    Distance from the "camera" to the near clipping plane. A positive value means the plane is in front of the viewer. * `f` (Type: number)
    Distance from the "camera" to the far clipping plane. A positive value means the plane is in front of the viewer. ("n" is usually less than "f", so that Z coordinates increase from near to far in the direction from the back to the front of the "eye", as they do in WebGL when just this matrix is used to transform vertices. If "n" is greater than "f", Z coordinates increase in the opposite direction.) The absolute difference between n and f should be as small as the application can accept. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4ortho2d(l, r, b, t) Returns a 4x4 matrix representing a 2D orthographic projection. This is the same as mat4ortho() with the near clipping plane set to -1 and the far clipping plane set to 1. This method is designed for enabling a right-handed coordinate system. See mat4ortho() for information on the meaning of coordinates when using this matrix and on adjusting the matrix for other conventions. #### Parameters * `l` (Type: number)
    Leftmost coordinate of the orthographic view. * `r` (Type: number)
    Rightmost coordinate of the orthographic view. ("l" is usually less than "r", so that X coordinates increase from left to right. If "l" is greater than "r", X coordinates increase in the opposite direction.) * `b` (Type: number)
    Bottommost coordinate of the orthographic view. * `t` (Type: number)
    Topmost coordinate of the orthographic view. ("b" is usually less than "t", so that Y coordinates increase upward, as they do in WebGL when just this matrix is used to transform vertices. If "b" is greater than "t", Y coordinates increase in the opposite direction.) #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4ortho2dAspect(l, r, b, t, aspect) Returns a 4x4 matrix representing a 2D orthographic projection, retaining the view rectangle's aspect ratio. If the view rectangle's aspect ratio doesn't match the desired aspect ratio, the view rectangle will be centered on the viewport or otherwise moved and scaled so as to keep the entire view rectangle visible without stretching or squishing it. This is the same as mat4orthoAspect() with the near clipping plane set to -1 and the far clipping plane set to 1. This method is designed for enabling a right-handed coordinate system. See mat4ortho() for information on the meaning of coordinates when using this matrix and on adjusting the matrix for other conventions. #### Parameters * `l` (Type: number)
    Leftmost coordinate of the view rectangle. * `r` (Type: number)
    Rightmost coordinate of the orthographic view. ("l" is usually less than "r", so that X coordinates increase from left to right. If "l" is greater than "r", X coordinates increase in the opposite direction.) * `b` (Type: number)
    Bottommost coordinate of the orthographic view. * `t` (Type: number)
    Topmost coordinate of the orthographic view. ("b" is usually less than "t", so that Y coordinates increase upward, as they do in WebGL when just this matrix is used to transform vertices. If "b" is greater than "t", Y coordinates increase in the opposite direction.) * `aspect` (Type: number)
    The ratio of width to height of the viewport, usually the scene's aspect ratio. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4orthoAspect(l, r, b, t, n, f, aspect) Returns a 4x4 matrix representing an orthographic projection, retaining the view rectangle's aspect ratio. If the view rectangle's aspect ratio doesn't match the desired aspect ratio, the view rectangle will be centered on the viewport or otherwise moved and scaled so as to keep the entire view rectangle visible without stretching or squishing it. The projection returned by this method only scales and/or shifts the view, so that objects with the same size won't appear smaller as they get more distant from the "camera". This method is designed for enabling a right-handed coordinate system. See mat4ortho() for information on the meaning of coordinates when using this matrix and on adjusting the matrix for other conventions. #### Parameters * `l` (Type: number)
    Leftmost coordinate of the view rectangle. * `r` (Type: number)
    Rightmost coordinate of the orthographic view. ("l" is usually less than "r", so that X coordinates increase from left to right. If "l" is greater than "r", X coordinates increase in the opposite direction.) * `b` (Type: number)
    Bottommost coordinate of the orthographic view. * `t` (Type: number)
    Topmost coordinate of the orthographic view. ("b" is usually less than "t", so that Y coordinates increase upward, as they do in WebGL when just this matrix is used to transform vertices. If "b" is greater than "t", Y coordinates increase in the opposite direction.) * `n` (Type: number)
    Distance from the "camera" to the near clipping plane. A positive value means the plane is in front of the viewer. * `f` (Type: number)
    Distance from the "camera" to the far clipping plane. A positive value means the plane is in front of the viewer. ("n" is usually less than "f", so that Z coordinates increase from near to far in the direction from the back to the front of the "eye", as they do in WebGL when just this matrix is used to transform vertices. If "n" is greater than "f", Z coordinates increase in the opposite direction.) The absolute difference between n and f should be as small as the application can accept. * `aspect` (Type: number)
    The ratio of width to height of the viewport, usually the scene's aspect ratio. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4perspective(fovY, aspectRatio, near, far) Returns a 4x4 matrix representing a perspective projection. When just this matrix is used to transform vertices, the X, Y, and Z coordinates within the view volume (as is the case in WebGL) will range from -W to W (where W is the fourth component of the transformed vertex) and increase from left to right and bottom to top. For a matrix in which Z coordinates range from 0 to W, divide the 15th element of the result (zero-based index 14) by 2. This method is designed for enabling a right-handed coordinate system. To adjust the result of this method for a left-handed system, reverse the sign of the 9th, 10th, 11th, and 12th elements of the result (zero-based indices 8, 9, 10, and 11). #### Parameters * `fovY` (Type: number)
    Y axis field of view, in degrees, that is, the shortest angle between the top and bottom clipping planes. Should be less than 180 degrees. (The smaller this number, the bigger close objects appear to be. As a result, zooming out can be implemented by raising this value, and zooming in by lowering it.) * `aspectRatio` (Type: number)
    The ratio of width to height of the viewport, usually the scene's aspect ratio. * `near` (Type: number)
    The distance, in eye space, from the "camera" to the near clipping plane. Objects closer than this distance won't be seen. This value should be greater than 0, and should be set to the highest distance from the "camera" that the application can afford to clip out for being too close, for example, 0.5, 1, or higher. * `far` (Type: number)
    The distance, in eye space, from the "camera" to the far clipping plane. Objects farther than this distance won't be seen.
    This value should be greater than 0 and should be set so that the absolute ratio of "far" to "near" is as small as the application can accept. ("near" is usually less than "far", so that Z coordinates increase from near to far in the direction from the back to the front of the "eye", as they do in WebGL when just this matrix is used to transform vertices. If "near" is greater than "far", Z coordinates increase in the opposite direction.)
    In the usual case that "far" is greater than "near", depth buffer values will be more concentrated around the near plane than around the far plane due to the perspective projection. The greater the ratio of "far" to "near", the more concentrated the values will be around the near plane, and the more likely two objects close to the far plane will have identical depth values. (Most WebGL implementations support 24-bit depth buffers, meaning they support 16,777,216 possible values per pixel.) #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4perspectiveHorizontal(fovX, aspectRatio, near, far) Returns a 4x4 matrix representing a perspective projection, given an X axis field of view. When just this matrix is used to transform vertices, the X, Y, and Z coordinates within the view volume (as is the case in WebGL) will range from -W to W (where W is the fourth component of the transformed vertex) and increase from left to right and bottom to top. For a matrix in which Z coordinates range from 0 to W, divide the 15th element of the result (zero-based index 14) by 2. This method is designed for enabling a right-handed coordinate system. To adjust the result of this method for a left-handed system, reverse the sign of the 9th, 10th, 11th, and 12th elements of the result (zero-based indices 8, 9, 10, and 11). #### Parameters * `fovX` (Type: number)
    X axis field of view, in degrees, that is, the shortest angle between the left and right clipping planes. Should be less than 180 degrees. (The smaller this number, the bigger close objects appear to be. As a result, zooming out can be implemented by raising this value, and zooming in by lowering it.) * `aspectRatio` (Type: number)
    The ratio of width to height of the viewport, usually the scene's aspect ratio. * `near` (Type: number)
    The distance, in eye space, from the "camera" to the near clipping plane. Objects closer than this distance won't be seen. This value should be greater than 0, and should be set to the highest distance from the "camera" that the application can afford to clip out for being too close, for example, 0.5, 1, or higher. * `far` (Type: number)
    The distance, in eye space, from the "camera" to the far clipping plane. Objects farther than this distance won't be seen.
    This value should be greater than 0 and should be set so that the absolute ratio of "far" to "near" is as small as the application can accept. ("near" is usually less than "far", so that Z coordinates increase from near to far in the direction from the back to the front of the "eye", as they do in WebGL when just this matrix is used to transform vertices. If "near" is greater than "far", Z coordinates increase in the opposite direction.)
    In the usual case that "far" is greater than "near", depth buffer values will be more concentrated around the near plane than around the far plane due to the perspective projection. The greater the ratio of "far" to "near", the more concentrated the values will be around the near plane, and the more likely two objects close to the far plane will have identical depth values. (Most WebGL implementations support 24-bit depth buffers, meaning they support 16,777,216 possible values per pixel.) #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4projectVec3(mat, v, [vy], [vz]) Transforms a 3-element vector with a 4x4 matrix and returns a perspective-correct version of the vector as a 3D point. The transformation involves transforming a 4-element vector with the same X, Y, and Z coordinates, but with a W coordinate equal to 1, with the 4x4 matrix, and then dividing X, Y, and Z of the transformed 4-element vector by that vector's W (a perspective divide), then returning that vector's new X, Y, and Z. #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix to use to transform the vector. This will generally be a projection-view matrix (projection matrix multiplied by the view matrix, in that order), if the vector to transform is in world space, or a model-view-projection matrix, that is, (projection-view matrix multiplied by the model [world] matrix, in that order), if the vector is in model (object) space.
    If the matrix includes a projection transform returned by MathUtil.mat4ortho, MathUtil.mat4perspective, or similar Math methods, the X, Y, and Z coordinates within the view volume (as is the case in WebGL) will range from -1 to 1 and increase from left to right, front to back, and bottom to top, unless otherwise specified in those methods' documentation. * `v` (Type: Array.<number> | number)
    X coordinate of a 3D point to transform. If "vy" and "vz" are omitted, this value can instead be a 3-element array giving the X, Y, and Z coordinates. * `vy` (Type: number) (optional)
    Y coordinate. * `vz` (Type: number) (optional)
    Z coordinate. To transform a 2D point, set Z to 0. #### Return Value The transformed 3-element vector. The elements, in order, are the transformed vector's X, Y, and Z coordinates. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4rotate(mat, angle, v, vy, vz) Multiplies a 4x4 matrix by a rotation transformation that rotates vectors by the given rotation angle and around the given axis of rotation, and returns a new matrix. The effect will be that the rotation transformation will happen before the transformation described in the given matrix, when applied in the global coordinate frame. #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix to multiply. * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. If "v", "vy", and "vz" are omitted, this can instead be a 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4rotated(angle, v, vy, vz) Returns a 4x4 matrix representing a rotation transformation that rotates vectors by the given rotation angle and around the given axis of rotation. #### Parameters * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. If "v", "vy", and "vz" are omitted, this can instead be a 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) #### Examples The following example rotates a vector, "vec", about the Z axis by the given angle, "angle". var newVector H3DU.MathUtil.mat4projectVec3( H3DU.MathUtil.mat4rotated(angle, 0, 0, 1), vec); ### (static) H3DU.MathUtil.mat4scale(mat, v3, v3y, v3z) Multiplies a 4x4 matrix by a scaling transformation. #### Parameters * `mat` (Type: Array.<number>)
    4x4 matrix to multiply. * `v3` (Type: Array.<number> | number)
    Scale factor along the X axis. A scale factor can be negative, in which case the transformation also causes reflection about the corresponding axis. If "v3y" and "v3z" are omitted, this value can instead be a 3-element array giving the scale factors along the X, Y, and Z axes. * `v3y` (Type: number)
    Scale factor along the Y axis. * `v3z` (Type: number)
    Scale factor along the Z axis. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4scaleInPlace(mat, v3, [v3y], [v3z]) Modifies a 4x4 matrix by multiplying it by a scaling transformation. #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix. * `v3` (Type: Array.<number> | number)
    Scale factor along the X axis. A scale factor can be negative, in which case the transformation also causes reflection about the corresponding axis. If "v3y" and "v3z" are omitted, this value can instead be a 3-element array giving the scale factors along the X, Y, and Z axes. * `v3y` (Type: number) (optional)
    Scale factor along the Y axis. * `v3z` (Type: number) (optional)
    Scale factor along the Z axis. #### Return Value The same parameter as "mat". (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4scaled(v3, v3y, v3z) Returns a 4x4 matrix representing a scaling transformation. #### Parameters * `v3` (Type: Array.<number> | number)
    Scale factor along the X axis. A scale factor can be negative, in which case the transformation also causes reflection about the corresponding axis. If "v3y" and "v3z" are omitted, this value can instead be a 3-element array giving the scale factors along the X, Y, and Z axes. * `v3y` (Type: number)
    Scale factor along the Y axis. * `v3z` (Type: number)
    Scale factor along the Z axis. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4toFrustumPlanes(matrix) Finds the six clipping planes of a view frustum defined by a 4x4 matrix. These six planes together form the shape of a "chopped-off" pyramid (or frustum). In this model, the eye, or camera, is placed at the top of the pyramid (before being chopped off), four planes are placed at the pyramid's sides, one plane (the far plane) forms its base, and a final plane (the near plane) is the pyramid's chopped off top. #### Parameters * `matrix` (Type: Array.<number>)
    A 4x4 matrix. This will usually be a projection-view matrix (projection matrix multiplied by view matrix, in that order). #### Return Value An array of six 4-element arrays representing the six clipping planes of the view frustum. In order, they are the left, right, top, bottom, near, and far clipping planes. All six planes will be normalized (see MathUtil.planeNormalizeInPlace). (Type: Array.<Array.<number>>) ### (static) H3DU.MathUtil.mat4toMat3(m4) Returns the upper-left part of a 4x4 matrix as a new 3x3 matrix. #### Parameters * `m4` (Type: Array.<number>)
    A 4x4 matrix. #### Return Value The resulting 3x3 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4transform(mat, v, [vy], [vz], [vw]) Transforms a 4-element vector with a 4x4 matrix and returns the transformed vector. Transforming a vector (v) with a matrix (mat) is effectively done by breaking up mat into four 4-element vectors (the first 4 elements make up the first vector, and so on), multiplying each vector in mat by the corresponding component in v, and adding up the resulting vectors (except v) to get the transformed vector. #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix. * `v` (Type: Array.<number> | number)
    X coordinate. If "vy", "vz", and "vw" are omitted, this value can instead be a 4-element array giving the X, Y, Z, and W coordinates. * `vy` (Type: number) (optional)
    Y coordinate. * `vz` (Type: number) (optional)
    Z coordinate. * `vw` (Type: number) (optional)
    W coordinate. To transform a 3D point, set W to 1 and divide the result's X, Y, and Z by the result's W. To transform a 2D point, set Z to 0 and W to 1 and divide the result's X and Y by the result's W. #### Return Value The transformed vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4transformVec3(mat, v, [vy], [vz]) Transforms a 3-element vector with a 4x4 matrix as though it were an affine transformation matrix (without perspective) and returns the transformed vector. The effect is as though elements 3, 7, 11, and 15 (counting from 0) of the matrix were assumed to be (0, 0, 0, 1) instead of their actual values and as though the 3-element vector had a fourth element valued at 1. For most purposes, use the MathUtil.mat4projectVec3 method instead, which supports 4x4 matrices that may be in a perspective projection (whose last row is not necessarily (0, 0, 0, 1)). #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix. * `v` (Type: Array.<number> | number)
    X coordinate. If "vy" and "vz" are omitted, this value can instead be a 4-element array giving the X, Y, and Z coordinates. * `vy` (Type: number) (optional)
    Y coordinate. * `vz` (Type: number) (optional)
    Z coordinate. To transform a 2D point, set Z to 0. #### Return Value The transformed 3-element vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4translate(mat, v3, v3y, v3z) Multiplies a 4x4 matrix by a translation transformation. #### Parameters * `mat` (Type: Array.<number>)
    The matrix to multiply. * `v3` (Type: Array.<number> | number)
    Translation along the X axis. If "v3y" and "v3z" are omitted, this value can instead be a 3-element array giving the translations along the X, Y, and Z axes. * `v3y` (Type: number)
    Translation along the Y axis. * `v3z` (Type: number)
    Translation along the Z axis. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4translated(v3, v3y, v3z) Returns a 4x4 matrix representing a translation. #### Parameters * `v3` (Type: Array.<number> | number)
    Translation along the X axis. If "v3y" and "v3z" are omitted, this value can instead be a 3-element array giving the translations along the X, Y, and Z axes. * `v3y` (Type: number)
    Translation along the Y axis. * `v3z` (Type: number)
    Translation along the Z axis. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4transpose(m4) Returns the transpose of a 4x4 matrix. (A transpose is a matrix whose rows are converted to columns and vice versa.) #### Parameters * `m4` (Type: Array.<number>)
    A 4x4 matrix. #### Return Value The resulting 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.mat4transposeInPlace(mat) Transposes a 4x4 matrix in place without creating a new matrix. (A transpose is a matrix whose rows are converted to columns and vice versa.) #### Parameters * `mat` (Type: Array.<number>)
    A 4x4 matrix. #### Return Value The parameter "mat". (Type: Array.<number>) ### (static) H3DU.MathUtil.planeFromNormalAndPoint(normal, point) Creates a plane from a normal vector and a point on the plane. #### Parameters * `normal` (Type: Array.<number>)
    A three-element array identifying the plane's normal vector. * `point` (Type: Array.<number>)
    A three-element array identifying a point on the plane. #### Return Value A four-element array describing the plane. (Type: Array.<number>) ### (static) H3DU.MathUtil.planeNormalize(plane) Normalizes this plane so that its normal is a unit vector, unless all the normal's components are 0, and returns a new plane with the result. The plane's distance will be divided by the normal's length. Returns a new plane. #### Parameters * `plane` (Type: Array.<number>)
    A four-element array defining the plane. The first three elements of the array are the X, Y, and Z components of the plane's normal vector, and the fourth element is the shortest distance from the plane to the origin, or if negative, from the origin to the plane, divided by the normal's length. #### Return Value A normalized version of the plane. Note that due to rounding error, the length of the plane's normal might not be exactly equal to 1, and that the vector will remain unchanged if its length is 0 or extremely close to 0. (Type: Array.<number>) ### (static) H3DU.MathUtil.planeNormalizeInPlace(plane) Normalizes this plane so that its normal is a unit vector, unless all the normal's components are 0, and sets this plane to the result. The plane's distance will be divided by the current normal's length. #### Parameters * `plane` (Type: Array.<number>)
    A four-element array defining the plane. The first three elements of the array are the X, Y, and Z components of the plane's normal vector, and the fourth element is the shortest distance from the plane to the origin, or if negative, from the origin to the plane, divided by the normal's length. #### Return Value The parameter "plane". (Type: Array.<number>) ### (static) H3DU.MathUtil.quatConjugate(quat) Returns a quaternion that describes a rotation that undoes the given rotation (an "inverted" rotation); this is done by reversing the sign of the X, Y, and Z components (which describe the quaternion's axis of rotation). The return value won't necessarily be a unit vector. #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value Return value. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatCopy(a) Returns a copy of a quaternion. #### Parameters * `a` (Type: Array.<number>)
    A quaternion. #### Return Value Return value. (Type: Array.<number>) #### See Also MathUtil.vec4copy ### (static) H3DU.MathUtil.quatDot(a, b) Finds the dot product of two quaternions. It's equal to the sum of the products of their components (for example, a's X times b's X). #### Parameters * `a` (Type: Array.<number>)
    The first quaternion. * `b` (Type: Array.<number>)
    The second quaternion. #### Return Value Return value. (Type: number) #### See Also MathUtil.vec4dot ### (static) H3DU.MathUtil.quatFromAxisAngle(angle, v, vy, vz) Generates a quaternion from a rotation transformation that rotates vectors by the given rotation angle and around the given axis of rotation, #### Parameters * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. If "v", "vy", and "vz" are omitted, this can instead be a 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### Return Value The generated quaternion. A quaternion's first three elements (X, Y, Z) describe an axis of rotation whose length is the sine of half of "angle", and its fourth element (W) is the cosine of half of "angle". (Type: Array.<number>) ### (static) H3DU.MathUtil.quatFromMat4(m) Generates a quaternion from the vector rotation described in a 4x4 matrix. The upper 3x3 portion of the matrix is used for this calculation. The results are undefined if the matrix includes any transformation other than rotation. #### Parameters * `m` (Type: Array.<number>)
    A 4x4 matrix. #### Return Value The resulting quaternion. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatFromTaitBryan(pitchDegrees, yawDegrees, rollDegrees, [mode]) Generates a quaternion from pitch, yaw and roll angles (or Tait–Bryan angles). See "Axis of Rotation" in "H3DU's Math Functions" for the meaning of each angle. #### Parameters * `pitchDegrees` (Type: number)
    Vector rotation about the X axis (upward or downward turn), in degrees. This can instead be a 3-element array giving the rotation about the X axis, Y axis, and Z axis, respectively. * `yawDegrees` (Type: number)
    Vector rotation about the Y axis (left or right turn), in degrees. May be null or omitted if "pitchDegrees" is an array. * `rollDegrees` (Type: number)
    Vector rotation about the Z axis (swaying side by side), in degrees. May be null or omitted if "pitchDegrees" is an array. * `mode` (Type: number) (optional)
    Specifies the order in which the rotations will occur (in terms of their effect). This is one of the Math constants such as MathUtil.LocalPitchYawRoll and MathUtil.GlobalYawRollPitch. If null, undefined, or omitted, the default is MathUtil.GlobalRollPitchYaw. The constants starting with Global describe a vector rotation in the order given, each about the original axes (these angles are also called extrinsic angles). The constants starting with Local describe a vector rotation in the order given, where the second and third rotations occur around the rotated object's new axes and not necessarily the original axes (these angles are also called intrinsic angles). The order of Local rotations has the same result as the reversed order of Global rotations and vice versa. #### Return Value The generated quaternion. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatFromVectors(vec1, vec2) Generates a quaternion describing a rotation between two 3-element vectors. The quaternion will describe the rotation required to rotate the ray described in the first vector toward the ray described in the second vector. The vectors need not be unit vectors. #### Parameters * `vec1` (Type: Array.<number>)
    The first 3-element vector. * `vec2` (Type: Array.<number>)
    The second 3-element vector. #### Return Value The generated quaternion, which will be a unit vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatIdentity() Returns the identity quaternion of multiplication, (0, 0, 0, 1). #### Return Value Return value. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatInvert(quat) Returns a quaternion that describes a rotation that undoes the given rotation (an "inverted" rotation) and is converted to a unit vector. #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value Return value. (Type: Array.<number>) #### See Also MathUtil.quatConjugate ### (static) H3DU.MathUtil.quatIsIdentity(quat) Returns whether this quaternion is the identity quaternion, (0, 0, 0, 1). #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value Return value. (Type: boolean) ### (static) H3DU.MathUtil.quatLength(quat) Returns the distance of this quaternion from the origin. It's the same as the square root of the sum of the squares of its components. #### Parameters * `quat` (Type: Array.<number>)
    The quaternion. #### Return Value Return value. (Type: number) #### See Also MathUtil.vec4length ### (static) H3DU.MathUtil.quatMultiply(a, b) Multiplies two quaternions, creating a composite rotation. The quaternions are multiplied such that the second quaternion's rotation happens before the first quaternion's rotation when applied in the global coordinate frame. If both quaternions are unit vectors, the resulting quaternion will also be a unit vector. However, for best results, you should normalize the quaternions every few multiplications (using MathUtil.quatNormalize or MathUtil.quatNormalizeInPlace), since successive multiplications can cause rounding errors. Quaternion multiplication is not commutative except in the last component of the resulting quaternion, since the definition of quaternion multiplication includes taking a cross product of a's and b's first three components, in that order, and the cross product is not commutative (see also MathUtil.vec3cross). #### Parameters * `a` (Type: Array.<number>)
    The first quaternion. * `b` (Type: Array.<number>)
    The second quaternion. #### Return Value The resulting quaternion. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatNlerp(q1, q2, factor) Returns a quaternion that lies along the shortest path between the given two quaternion rotations, using a linear interpolation function, and converts it to a unit vector. This is called a normalized linear interpolation, or "nlerp". Because the shortest path is curved, not straight, this method will generally not interpolate at constant velocity; however, the difference in this velocity when interpolating is rarely noticeable and this method is generally faster than the MathUtil.quatSlerp method. #### Parameters * `q1` (Type: Array.<number>)
    The first quaternion. Must be a unit vector. * `q2` (Type: Array.<number>)
    The second quaternion. Must be a unit vector. * `factor` (Type: number)
    A value that usually ranges from 0 through 1. Closer to 0 means closer to q1, and closer to 1 means closer to q2. #### Return Value The interpolated quaternion, which will be a unit vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatNormalize(quat) Converts a quaternion to a unit vector; returns a new quaternion. When a quaternion is normalized, the distance from the origin to that quaternion becomes 1 (unless all its components are 0). A quaternion is normalized by dividing each of its components by its length. #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value The normalized quaternion. Note that due to rounding error, the vector's length might not be exactly equal to 1, and that the vector will remain unchanged if its length is 0 or extremely close to 0. (Type: Array.<number>) #### See Also MathUtil.vec4normalize ### (static) H3DU.MathUtil.quatNormalizeInPlace(quat) Converts a quaternion to a unit vector. When a quaternion is normalized, it describes the same rotation but the distance from the origin to that quaternion becomes 1 (unless all its components are 0). A quaternion is normalized by dividing each of its components by its length. #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value The parameter "quat". Note that due to rounding error, the vector's length might not be exactly equal to 1, and that the vector will remain unchanged if its length is 0 or extremely close to 0. (Type: Array.<number>) #### See Also MathUtil.vec4normalizeInPlace ### (static) H3DU.MathUtil.quatRotate(quat, angle, v, vy, vz) Multiplies a quaternion by a rotation transformation that rotates vectors by the given rotation angle and around the given axis of rotation. The result is such that the angle-axis rotation happens before the quaternion's rotation when applied in the global coordinate frame. This method is equivalent to the following (see also MathUtil.quatMultiply): return quatMultiply(quat,quatFromAxisAngle(angle,v,vy,vz)); #### Parameters * `quat` (Type: Array.<number>)
    Quaternion to rotate. * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. If "v", "vy", and "vz" are omitted, this can instead be a 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### Return Value The resulting quaternion. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatScale(a, scalar) Multiplies each element of a quaternion by a factor and returns the result as a new quaternion. #### Parameters * `a` (Type: Array.<number>)
    A quaternion. * `scalar` (Type: number)
    A factor to multiply. #### Return Value The resulting quaternion. (Type: Array.<number>) #### See Also MathUtil.vec4scaleInPlace ### (static) H3DU.MathUtil.quatScaleInPlace(a, scalar) Multiplies each element of a quaternion by a factor and stores the result in that quaternion. #### Parameters * `a` (Type: Array.<number>)
    A quaternion. * `scalar` (Type: number)
    A factor to multiply. #### Return Value The parameter "a". (Type: Array.<number>) #### See Also MathUtil.vec4scaleInPlace ### (static) H3DU.MathUtil.quatSlerp(q1, q2, factor) Returns a quaternion that lies along the shortest path between the given two quaternion rotations, using a spherical interpolation function. This is called spherical linear interpolation, or "slerp". (A spherical interpolation finds the shortest angle between the two quaternions -- which are treated as 4D vectors -- and then finds a vector with a smaller angle between it and the first quaternion. The "factor" parameter specifies how small the new angle will be relative to the original angle.) This method will generally interpolate at constant velocity; however, this method is not commutative (that is, the order in which the quaternions are given matters), unlike quatNlerp, making it unsuitable for blending multiple quaternion rotations, and this method is generally more computationally expensive than the quatNlerp method. #### Parameters * `q1` (Type: Array.<number>)
    The first quaternion. Must be a unit vector. * `q2` (Type: Array.<number>)
    The second quaternion. Must be a unit vector. * `factor` (Type: number)
    A value that usually ranges from 0 through 1. Closer to 0 means closer to q1, and closer to 1 means closer to q2. #### Return Value The interpolated quaternion. (Type: Array.<number>) #### See Also ["Understanding Slerp, Then Not Using It", Jonathan Blow](http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/), for additional background ### (static) H3DU.MathUtil.quatToAxisAngle(a) Calculates the vector rotation for this quaternion in the form of the angle to rotate the vector by and an axis of rotation to rotate that vector around. #### Parameters * `a` (Type: Array.<number>)
    A quaternion. Must be a unit vector. #### Return Value A 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. If "a" is a unit vector, the axis of rotation will be a unit vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatToMat4(quat) Generates a 4x4 matrix describing the rotation described by this quaternion. #### Parameters * `quat` (Type: Array.<number>)
    A quaternion, containing four elements. #### Return Value The generated 4x4 matrix. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatToTaitBryan(a, [mode]) Converts this quaternion to the same version of the rotation in the form of pitch, yaw, and roll angles (or Tait–Bryan angles). #### Parameters * `a` (Type: Array.<number>)
    A quaternion. Should be a unit vector. * `mode` (Type: number) (optional)
    Specifies the order in which the rotations will occur (in terms of their effect, not in terms of how they will be returned by this method). This is one of the Math constants such as MathUtil.LocalPitchYawRoll and MathUtil.GlobalYawRollPitch. If null, undefined, or omitted, the default is MathUtil.GlobalRollPitchYaw. The constants starting with Global describe a vector rotation in the order given, each about the original axes (these angles are also called extrinsic angles). The constants starting with Local describe a vector rotation in the order given, where the second and third rotations occur around the rotated object's new axes and not necessarily the original axes (these angles are also called intrinsic angles). The order of Local rotations has the same result as the reversed order of Global rotations and vice versa. #### Return Value A 3-element array containing the pitch, yaw, and roll angles (X, Y, and Z axis angles), in that order and in degrees, by which to rotate vectors. See "Axis of Rotation" in "H3DU's Math Functions" for the meaning of each angle. (Type: Array.<number>) ### (static) H3DU.MathUtil.quatTransform(q, v) Transforms a 3- or 4-element vector using a quaternion's vector rotation. #### Parameters * `q` (Type: Array.<number>)
    A quaternion describing the rotation. * `v` (Type: Array.<number>)
    A 3- or 4-element vector to transform. The fourth element, if any, is ignored. #### Return Value A 4-element vector representing the transformed vector. The fourth element will be 1.0. If the input vector has 3 elements, a 3-element vector will be returned instead. (Type: Array.<number>) ### (static) H3DU.MathUtil.vec2abs(a) Returns a new 2-element vector with the absolute value of each of its components. #### Parameters * `a` (Type: Array.<number>)
    A 2-element vector. #### Return Value The resulting 2-element vector. (Type: Array.<number>) ### (static) H3DU.MathUtil.vec2absInPlace(a) Sets each component of the given 2-element vector to its absolute value. #### Parameters * `a` (Type: Array.<number>)
    A 2-element vector. #### Return Value The vector "a". (Type: Array.<number>) ### (static) H3DU.MathUtil.vec2add(a, b) Adds two 2-element vectors and returns a new vector with the result. Adding two vectors is the same as adding each of their components. The resulting vector: