Provides vector and matrix operations for quick and easy use.
Compatibility with MathDevice objects
All of the VMath functions are completely compatible with the MathDevice objects. However, the native MathDevice objects will be converted into JavaScript arrays when you do this. This conversion is a slow operation and should be avoided wherever possible.
Note that although the MathDevice objects can be used with the VMath functions the reverse is not true. The MathDevice functions only support MathDevice objects as arguments. To convert between VMath and MathDevice objects see MathDeviceConvert.
VMath vector and matrix data representations
The VMath objects are all stored as JavaScript arrays. So for example a VMath.v3Add(a, b) takes two JavaScript arrays of length 3 and returns another JavaScript array of length three. The sizes and formats of each of the types are as follows
So cell with row 1 and column 2 in an m33 matrix is at index 1 in the array (row 1 column 1 is index 0).
The MathDevice uses arrays of single-precision floats for all of its internal objects. On the other hand the JavaScript representation of numbers uses double-precision floats for all of its number objects. Subsequently, there is a loss of precision between JavaScript values and the MathDevice objects to be aware of.
Extents
extents are widely used throughout the JavaScript library. Extents are implemented as a JavaScript array of 6 numbers that define the minimum coordinate, index 0-2, and maximum coordinate, index 3-5 of an object.
Additional functions on the VMath object (these functions are not on the MathDevice)
Mask functions
The mask functions perform a per-component arithmetic or logic. For example the v3MaskLess function:
Syntax
v3MaskLess : function v3MaskLessFn(a, b)
{
return [(a[0] < b[0]),
(a[1] < b[1]),
(a[2] < b[2])];
}
Sets each result component to a less than comparison between the equivalent components on a and b.
Required scripts
The VMath object requires:
/*{{ javascript("jslib/vmath.js") }}*/
The VMath object is a singleton.
Summary
Returns a JavaScript array of length 2, initialized to the mask equality of the first vector parameter to the second vector parameter. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
maskEqual = VMath.v2MaskEqual(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask LESS THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskLess = VMath.v2MaskLess(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask GREATER THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskGreater = VMath.v2MaskGreater(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask GREATER THAN OR EQUAL to operator of the first vector parameter to the second vector parameter.
Syntax
maskGreaterEq = VMath.v2MaskGreaterEq(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask NOT operator of the first vector parameter to the second vector parameter.
Syntax
maskNot = VMath.v2MaskNot(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask OR operator of the first vector parameter to the second vector parameter.
Syntax
maskOr = VMath.v2MaskOr(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask AND operator of the first vector parameter to the second vector parameter.
Syntax
maskAnd = VMath.v2MaskAnd(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask SELECT operator of the first vector parameter to the second vector parameter.
Syntax
maskSelect = VMath.v2MaskSelect(vectorA, vectorB);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the maximum of the first vector parameter to the second scalar one.
Syntax
scalarMax = VMath.v2ScalarMax(vector, scalar);
Returns a JavaScript array object of length 2.
Summary
Returns a JavaScript array of length 2, initialized to the minimum of the first vector parameter to the second scalar one.
Syntax
scalarMin = VMath.v2ScalarMin(vector, scalar);
Returns a JavaScript array object of length 2.
Summary
Returns a JavaScript array of length 2, initialized to the minimum of the first vector parameter to the second scalar one. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
equalScalarMask = VMath.v2EqualScalarMask(vector, scalar);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask LESS THAN operator of the first vector parameter to the second scalar parameter.
Syntax
lessScalarMask = VMath.v2LessScalarMask(vector, scalar);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask GREATER THAN operator of the first vector parameter to the second scalar parameter.
Syntax
greaterScalarMask = VMath.v2GreaterScalarMask(vector, scalar);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 2, initialized to the mask GREATER THAN OR EQUAL operator of the first vector parameter to the second scalar parameter.
Syntax
greaterEqScalarMask = VMath.v2GreaterEqScalarMask(vector, scalar);
Returns a JavaScript array object of length 2 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask equality of the first vector parameter to the second vector parameter. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
maskEqual = VMath.v3MaskEqual(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask LESS THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskLess = VMath.v3MaskLess(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask GREATER THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskGreater = VMath.v3MaskGreater(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask GREATER THAN OR EQUAL to operator of the first vector parameter to the second vector parameter.
Syntax
maskGreaterEq = VMath.v3MaskGreaterEq(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask NOT operator of the first vector parameter to the second vector parameter.
Syntax
maskNot = VMath.v3MaskNot(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask OR operator of the first vector parameter to the second vector parameter.
Syntax
maskOr = VMath.v3MaskOr(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask AND operator of the first vector parameter to the second vector parameter.
Syntax
maskAnd = VMath.v3MaskAnd(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask SELECT operator of the first vector parameter to the second vector parameter.
Syntax
maskSelect = VMath.v3MaskSelect(vectorA, vectorB);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the maximum of the first vector parameter to the second scalar one.
Syntax
scalarMax = VMath.v3ScalarMax(vector, scalar);
Returns a JavaScript array object of length 3.
Summary
Returns a JavaScript array of length 3, initialized to the minimum of the first vector parameter to the second scalar one.
Syntax
scalarMin = VMath.v3ScalarMin(vector, scalar);
Returns a JavaScript array object of length 3.
Summary
Returns a JavaScript array of length 3, initialized to the minimum of the first vector parameter to the second scalar one. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
equalScalarMask = VMath.v3EqualScalarMask(vector, scalar);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask LESS THAN operator of the first vector parameter to the second scalar parameter.
Syntax
lessScalarMask = VMath.v3LessScalarMask(vector, scalar);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask GREATER THAN operator of the first vector parameter to the second scalar parameter.
Syntax
greaterScalarMask = VMath.v3GreaterScalarMask(vector, scalar);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 3, initialized to the mask GREATER THAN OR EQUAL operator of the first vector parameter to the second scalar parameter.
Syntax
greaterEqScalarMask = VMath.v3GreaterEqScalarMask(vector, scalar);
Returns a JavaScript array object of length 3 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask equality of the first vector parameter to the second vector parameter. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
maskEqual = VMath.v4MaskEqual(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask LESS THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskLess = VMath.v4MaskLess(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask GREATER THAN operator of the first vector parameter to the second vector parameter.
Syntax
maskGreater = VMath.v4MaskGreater(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask GREATER THAN OR EQUAL to operator of the first vector parameter to the second vector parameter.
Syntax
maskGreaterEq = VMath.v4MaskGreaterEq(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask NOT operator of the first vector parameter to the second vector parameter.
Syntax
maskNot = VMath.v4MaskNot(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask OR operator of the first vector parameter to the second vector parameter.
Syntax
maskOr = VMath.v4MaskOr(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask AND operator of the first vector parameter to the second vector parameter.
Syntax
maskAnd = VMath.v4MaskAnd(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask SELECT operator of the first vector parameter to the second vector parameter.
Syntax
maskSelect = VMath.v4MaskSelect(vectorA, vectorB);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the maximum of the first vector parameter to the second scalar one.
Syntax
scalarMax = VMath.v4ScalarMax(vector, scalar);
Returns a JavaScript array object of length 4.
Summary
Returns a JavaScript array of length 4, initialized to the minimum of the first vector parameter to the second scalar one.
Syntax
scalarMin = VMath.v4ScalarMin(vector, scalar);
Returns a JavaScript array object of length 4.
Summary
Returns a JavaScript array of length 4, initialized to the minimum of the first vector parameter to the second scalar one. The VMath library specifies the precision of the comparison with a default of 1E-06.
Syntax
equalScalarMask = VMath.v4EqualScalarMask(vector, scalar);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask LESS THAN operator of the first vector parameter to the second scalar parameter.
Syntax
lessScalarMask = VMath.v4LessScalarMask(vector, scalar);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask GREATER THAN operator of the first vector parameter to the second scalar parameter.
Syntax
greaterScalarMask = VMath.v4GreaterScalarMask(vector, scalar);
Returns a JavaScript array object of length 4 containing either true or false.
Summary
Returns a JavaScript array of length 4, initialized to the mask GREATER THAN OR EQUAL operator of the first vector parameter to the second scalar parameter.
Syntax
greaterEqScalarMask = VMath.v4GreaterEqScalarMask(vector, scalar);
Returns a JavaScript array object of length 4 containing either true or false.