math.js
Additional mathematical functions.

File Location

math/math.js


Public Protected Private

Global Functions

goog.math.angle(x1y1x2y2)
Computes the angle between two points (x1,y1) and (x2,y2). Angle zero points in the +X direction, 90 degrees points in the +Y direction (down) and from there we grow clockwise towards 360 degrees.
Arguments:
x1 :
x of first point.
y1 :
y of first point.
x2 :
x of second point.
y2 :
y of second point.
Returns:   Standardized angle in degrees of the vector from x1,y1 to x2,y2.
code »
goog.math.angleDifference(startAngleendAngle)
Computes the difference between startAngle and endAngle (angles in degrees).
Arguments:
startAngle :
Start angle in degrees.
endAngle :
End angle in degrees.
Returns:   The number of degrees that when added to startAngle will result in endAngle. Positive numbers mean that the direction is clockwise. Negative numbers indicate a counter-clockwise direction. The shortest route (clockwise vs counter-clockwise) between the angles is used. When the difference is 180 degrees, the function returns 180 (not -180) angleDifference(30, 40) is 10, and angleDifference(40, 30) is -10. angleDifference(350, 10) is 20, and angleDifference(10, 350) is -20.
code »
goog.math.angleDx(degreesradius)
For a given angle and radius, finds the X portion of the offset.
Arguments:
degrees :
Angle in degrees (zero points in +X direction).
radius :
Radius.
Returns:   The x-distance for the angle and radius.
code »
goog.math.angleDy(degreesradius)
For a given angle and radius, finds the Y portion of the offset.
Arguments:
degrees :
Angle in degrees (zero points in +X direction).
radius :
Radius.
Returns:   The y-distance for the angle and radius.
code »
goog.math.average(var_args)
Returns the arithmetic mean of the arguments.
Arguments:
var_args :
Numbers to average.
Returns:   The average of the arguments ({@code NaN} if no arguments were provided or any of the arguments is not a valid number).
code »
goog.math.clamp(valueminmax)
Takes a number and clamps it to within the provided bounds.
Arguments:
value :
The input number.
min :
The minimum value to return.
max :
The maximum value to return.
Returns:   The input number if it is within bounds, or the nearest number within the bounds.
code »
goog.math.isFiniteNumber(num)
Returns whether the supplied number is finite and not NaN.
Arguments:
num :
The number to test.
Returns:   Whether {@code num} is a finite number.
code »
goog.math.isInt(num)
Returns whether the supplied number represents an integer, i.e. that is has no fractional component. No range-checking is performed on the number.
Arguments:
num :
The number to test.
Returns:   Whether {@code num} is an integer.
code »
goog.math.lerp(abx)
Performs linear interpolation between values a and b. Returns the value between a and b proportional to x (when x is between 0 and 1. When x is outside this range, the return value is a linear extrapolation).
Arguments:
a :
A number.
b :
A number.
x :
The proportion between a and b.
Returns:   The interpolated value between a and b.
code »
goog.math.longestCommonSubsequence(array1array2opt_compareFnopt_collectorFn)
JavaScript implementation of Longest Common Subsequence problem. http://en.wikipedia.org/wiki/Longest_common_subsequence Returns the longest possible array that is subarray of both of given arrays.
Arguments:
array1 :
First array of objects.
array2 :
Second array of objects.
opt_compareFn :
Function that acts as a custom comparator for the array ojects. Function should return true if objects are equal, otherwise false.
opt_collectorFn :
Function used to decide what to return as a result subsequence. It accepts 2 arguments: index of common element in the first array and index in the second. The default function returns element from the first array.
Returns:   A list of objects that are common to both arrays such that there is no common subsequence with size greater than the length of the list.
code »
goog.math.modulo(ab)
The % operator in JavaScript returns the remainder of a / b, but differs from some other languages in that the result will have the same sign as the dividend. For example, -1 % 8 == -1, whereas in some other languages (such as Python) the result would be 7. This function emulates the more correct modulo behavior, which is useful for certain applications such as calculating an offset index in a circular list.
Arguments:
a :
The dividend.
b :
The divisor.
Returns:   a % b where the result is between 0 and b (either 0 <= x < b or b < x <= 0, depending on the sign of b).
code »
goog.math.nearlyEquals(abopt_tolerance)
Tests whether the two values are equal to each other, within a certain tolerance to adjust for floating pount errors.
Arguments:
a :
A number.
b :
A number.
opt_tolerance :
Optional tolerance range. Defaults to 0.000001. If specified, should be greater than 0.
Returns:   Whether {@code a} and {@code b} are nearly equal.
code »
goog.math.randomInt(a)
Returns a random integer greater than or equal to 0 and less than {@code a}.
Arguments:
a :
The upper bound for the random integer (exclusive).
Returns:   A random integer N such that 0 <= N < a.
code »
goog.math.sign(x)
Returns the sign of a number as per the "sign" or "signum" function.
Arguments:
x :
The number to take the sign of.
Returns:   -1 when negative, 1 when positive, 0 when 0.
code »
goog.math.standardAngle(angle)
Standardizes an angle to be in range [0-360). Negative angles become positive, and values greater than 360 are returned modulo 360.
Arguments:
angle :
Angle in degrees.
Returns:   Standardized angle.
code »
goog.math.standardDeviation(var_args)
Returns the sample standard deviation of the arguments. For a definition of sample standard deviation, see e.g. http://en.wikipedia.org/wiki/Standard_deviation
Arguments:
var_args :
Number samples to analyze.
Returns:   The sample standard deviation of the arguments (0 if fewer than two samples were provided, or {@code NaN} if any of the samples is not a valid number).
code »
goog.math.sum(var_args)
Returns the sum of the arguments.
Arguments:
var_args :
Numbers to add.
Returns:   The sum of the arguments (0 if no arguments were provided, {@code NaN} if any of the arguments is not a valid number).
code »
goog.math.toDegrees(angleRadians)
Converts radians to degrees.
Arguments:
angleRadians :
Angle in radians.
Returns:   Angle in degrees.
code »
goog.math.toRadians(angleDegrees)
Converts degrees to radians.
Arguments:
angleDegrees :
Angle in degrees.
Returns:   Angle in radians.
code »
goog.math.uniformRandom(ab)
Returns a random number greater than or equal to {@code a} and less than {@code b}.
Arguments:
a :
The lower bound for the random number (inclusive).
b :
The upper bound for the random number (exclusive).
Returns:   A random number N such that a <= N < b.
code »

Directory math

File Reference