## DuMath

Math related methods

View Source Duik_api_fordoc.jsxinc, line 7405

# Members

Type: `int`

#### # static readonly Location

Enum for locations.

##### Properties:

Name | Type | Description
--- | --- | ---
`TOP` | `int` |
`TOP_RIGHT` | `int` |
`RIGHT` | `int` |
`BOTTOM_RIGHT` | `int` |
`BOTTOM` | `int` |
`BOTTOM_LEFT` | `int` |
`LEFT` | `int` |
`TOP_LEFT` | `int` |
`CENTER` | `int` |

View Source Duik_api_fordoc.jsxinc, line 7413

# Methods

#### # static angleFromSides(anglePoint, oppositePointA, oppositePointB) → {float}

Finds the angle formed by three points

##### Parameters:

Name | Type | Description
--- | --- | ---
`anglePoint` | `Array.<float>` | The point at which to measure the angle
`oppositePointA` | `Array.<float>` | One of the opposite points
`oppositePointB` | `Array.<float>` | The other opposite point

View Source Duik_api_fordoc.jsxinc, line 7967

Returns:
The angle in radians.
Type: `float`

#### # static average(values) → {float}

Calculates the average value in a list

##### Parameters:

Name | Type | Description
--- | --- | ---
`values` | `Number` | `Array.<Number>` | values

View Source Duik_api_fordoc.jsxinc, line 7637

Returns:
The average value
Type: `float`

#### # static bounds(values) → {Array.<float>}

Gets the bounds of the values

##### Parameters:

Name | Type | Description
--- | --- | ---
`values` | `Array.<Array.<Number>>` | A list of values

View Source Duik_api_fordoc.jsxinc, line 7888

Returns:
The bounds, for N dimensions: [min1, min2, ..., minN, max1, max2, ..., maxN]
Type: `Array.<float>`

#### # static clamp(values, minopt, maxopt) → {Number|Array.<Number>}

Clamps the value

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`values` | `Number` | `Array.<Number>` |  |  | values
`min` | `Number` | <optional> | 0 | The minimum value
`max` | `Number` | <optional> | 1 | The maximum value

View Source Duik_api_fordoc.jsxinc, line 7663

Returns:
The clamped values
Type: `Number` | `Array.<Number>`

#### # static equals(value1, value2, floatPrecisionopt) → {boolean}

Compares two numbers

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value1` | `Number` | `Array.<Number>` |  |  | The first value
`value2` | `Number` | `Array.<Number>` |  |  | The second value
`floatPrecision` | `int` | <optional> | -1 | The precision for (float) number comparison, number of decimals. Set to -1 to not use.

View Source Duik_api_fordoc.jsxinc, line 7592

Returns:
true if the two values are equal
Type: `boolean`

#### # static gaussian(value, minopt, maxopt, centeropt, fwhmopt) → {Number}

The gaussian function

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | `Number` |  |  | The variable
`min` | `Number` | <optional> | 0 | The minimum return value
`max` | `Number` | <optional> | 1 | The maximum return value
`center` | `Number` | <optional> | 0 | The center of the peak
`fwhm` | `Number` | <optional> | 1 | The full width at half maximum of the curve

View Source Duik_api_fordoc.jsxinc, line 7757

Returns:
The result
Type: `Number`

#### # static gaussRandom(minopt, maxopt, boundedopt) → {int}

Generates a random integer between minimum and maximum.
The results are distributed along a gaussian (bell) curve.
Note that a few (< 10%) values may be outside of the range. Set the `bounded` to true to avoid that.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`min` | `int` | <optional> | 0 | The minimum value
`max` | `int` | <optional> | 1 | The maximum value
`bounded` | `Bool` | <optional> | false | When this is false, a few values may be outside the range. Set it to true to make sure all values are between min and max.

View Source Duik_api_fordoc.jsxinc, line 7548

Returns:
The randomly generated integer
Type: `int`

#### # static inverseGaussian(v, minopt, maxopt, centeropt, fwhmopt) → {Array.<Number>}

The inverse gaussian function

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`v` | `Number` |  |  | The variable
`min` | `Number` | <optional> | 0 | The minimum return value of the corresponding gaussian function
`max` | `Number` | <optional> | 1 | The maximum return value of the corresponding gaussian function
`center` | `Number` | <optional> | 0 | The center of the peak of the corresponding gaussian function
`fwhm` | `Number` | <optional> | 1 | The full width at half maximum of the curve of the corresponding gaussian function

View Source Duik_api_fordoc.jsxinc, line 7795

Returns:
The two possible results, the lower is the first in the list. If both are the same, it is the maximum
Type: `Array.<Number>`

#### # static inverseLogistic(v, midValueopt, minopt, maxopt, rateopt) → {Number}

The inverse logistic function (inverse sigmoid)

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`v` | `Number` |  |  | The variable
`midValue` | `Number` | <optional> | 0 | The midpoint value, at which the function returns max/2 in the original logistic function
`min` | `Number` | <optional> | 0 | The minimum return value of the original logistic function
`max` | `Number` | <optional> | 1 | The maximum return value of the original logistic function
`rate` | `Number` | <optional> | 1 | The logistic growth rate or steepness of the original logistic function

View Source Duik_api_fordoc.jsxinc, line 7737

Returns:
The result
Type: `Number`

#### # static inverseReversedGaussian(value, minopt, maxopt, centeropt, fwhmopt) → {Array.<Number>}

The inverse of the reversed gaussian function

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | `Number` |  |  | The variable
`min` | `Number` | <optional> | 0 | The minimum return value of the corresponding gaussian function
`max` | `Number` | <optional> | 1 | The maximum return value of the corresponding gaussian function
`center` | `Number` | <optional> | 0 | The center of the peak of the corresponding gaussian function
`fwhm` | `Number` | <optional> | 1 | The full width at half maximum of the curve of the corresponding gaussian function

View Source Duik_api_fordoc.jsxinc, line 7820

Returns:
The two possible results, the lower is the first in the list. If both are the same, it is the maximum
Type: `Array.<Number>`

#### # static isExtremePoint(previousValue, point, nextValue, precisionopt) → {Boolean}

Checks if the direction changes (if the point is at an extreme value). If the values have multiple dimensions, checks each axis individually.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`previousValue` | `Number` | `Array.<Number>` |  |  | The value just before the point.
`point` | `Number` | `Array.<Number>` |  |  | The point to check.
`nextValue` | `Number` | `Array.<Number>` |  |  | The value just after the point.
`precision` | `int` | <optional> | 1 | The precision for floating point comparisons; number of decimals.

View Source Duik_api_fordoc.jsxinc, line 7914

Returns:
Type: `Boolean`

#### # static isInflexionPoint(previousVelocity, pointVelocity, nextVelocity) → {Boolean}

Checks if the point is an inflexion point.

##### Parameters:

Name | Type | Description
--- | --- | ---
`previousVelocity` | `Number` | `Array.<Number>` | The derivative (speed) of a point just before the point.
`pointVelocity` | `Number` | `Array.<Number>` | The derivative (speed) at the point to check.
`nextVelocity` | `Number` | `Array.<Number>` | The derivative (speed) of a point just after the point.

View Source Duik_api_fordoc.jsxinc, line 7944

Returns:
Type: `Boolean`

#### # static isInside(point, bounds) → {Boolean}

Checks if a point is located inside given bounds

##### Parameters:

Name | Type | Description
--- | --- | ---
`point` | `Array.<float>` | The point
`bounds` | `Array.<float>` | The bounds. The number of bounds must be at least twice the number of dimensions, in this order : [a1, a2, ..., x1,x2,y1,y2,z1,z2]

View Source Duik_api_fordoc.jsxinc, line 7860

Returns:
true if the point is inside the bounds
Type: `Boolean`

#### # static isLocationBottom(location) → {boolean}

Checks if the given location is on the bottom side

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7490

Returns:
Type: `boolean`

#### # static isLocationHCenter(location) → {boolean}

Checks if the given location is on the center on the horizontal axis

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7442

Returns:
Type: `boolean`

#### # static isLocationLeft(location) → {boolean}

Checks if the given location is on the left side

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7454

Returns:
Type: `boolean`

#### # static isLocationRight(location) → {boolean}

Checks if the given location is on the right side

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7430

Returns:
Type: `boolean`

#### # static isLocationTop(location) → {boolean}

Checks if the given location is on the top side

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7466

Returns:
Type: `boolean`

#### # static isLocationVCenter(location) → {boolean}

Checks if the given location is on the center on the vertical axis

##### Parameters:

Name | Type | Description
--- | --- | ---
`location` | `DuMath.Location` | The location

View Source Duik_api_fordoc.jsxinc, line 7478

Returns:
Type: `boolean`

#### # static length(value1, value2) → {float}

Measures the vector length between two points

##### Parameters:

Name | Type | Description
--- | --- | ---
`value1` | `Array.<int>` | The first value
`value2` | `Array.<int>` | The second value

View Source Duik_api_fordoc.jsxinc, line 7570

Returns:
The length
Type: `float`

#### # static linear(value, minopt, maxopt, targetMinopt, targetMaxopt, clampopt) → {Number}

The linear function

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | `Number` |  |  | The variable
`min` | `Number` | <optional> | 0 | The minimum input value
`max` | `Number` | <optional> | 1 | The maximum input value
`targetMin` | `Number` | <optional> | 0 | The minimum output value
`targetMax` | `Number` | <optional> | 1 | The maximum output value
`clamp` | `Boolean` | <optional> | false | Whether to clamp the output value to the target or not.

View Source Duik_api_fordoc.jsxinc, line 7835

Returns:
Type: `Number`

#### # static log10(w) → {float}

Calculates the log10 of a number

##### Parameters:

Name | Type | Description
--- | --- | ---
`w` | `float` | The number

View Source Duik_api_fordoc.jsxinc, line 7627

Returns:
The result of log10(x)
i.e. Math.log(x)/Math.LN10
Type: `float`

#### # static logistic(value, midValueopt, minopt, maxopt, rateopt) → {Number}

The logistic function (sigmoid)

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | `Number` |  |  | The value
`midValue` | `Number` | <optional> | 0 | The midpoint value, at which the function returns max/2
`min` | `Number` | <optional> | 0 | The minimum return value
`max` | `Number` | <optional> | 1 | The maximum return value
`rate` | `Number` | <optional> | 1 | The logistic growth rate or steepness of the function

View Source Duik_api_fordoc.jsxinc, line 7718

Returns:
The result in the range [min, max] (excluding min and max)
Type: `Number`

#### # static mean()

Alias for `DuMath.average`.

View Source Duik_api_fordoc.jsxinc, line 7653

#### # static random(minopt, maxopt) → {int}

Generates a random integer between minimum and maximum

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`min` | `int` | <optional> | 0 | The minimum value
`max` | `int` | <optional> | 1 | The maximum value

View Source Duik_api_fordoc.jsxinc, line 7525

Returns:
The randomly generated integer
Type: `int`

#### # static relativeLocation(point, originopt) → {DuMath.Location}

Returns the location of the point relative to the origin. Works with 2D values, the first two coordinates. Considers the coordinate [0,0] to be the top left corner of the system: positive values are right, bottom

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`point` | `Array.<float>` |  |  | The point to check
`origin` | `Array.<float>` | <optional> | [0,0] | The coordinates of the origin

View Source Duik_api_fordoc.jsxinc, line 7504

Returns:
The location
Type: `DuMath.Location`

#### # static reversedGaussian(value, minopt, maxopt, centeropt, fwhmopt) → {Number}

A "reversed" gaussian function, growing faster with low value

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`value` | `Number` |  |  | The variable
`min` | `Number` | <optional> | 0 | The minimum return value
`max` | `Number` | <optional> | 1 | The maximum return value
`center` | `Number` | <optional> | 0 | The center of the peak
`fwhm` | `Number` | <optional> | 1 | The full width at half maximum of the curve

View Source Duik_api_fordoc.jsxinc, line 7781

Returns:
The result
Type: `Number`

#### # static sign(num) → {int}

Checks the sign of a number

##### Parameters:

Name | Type | Description
--- | --- | ---
`num` | `Number` | The number to check

View Source Duik_api_fordoc.jsxinc, line 7877

Returns:
1 if num is positive, -1 if negative, 0 in other cases (0, NaN...)
Type: `int`

#### # static toDegrees(value) → {float}

Converts the number from radians to degrees

##### Parameters:

Name | Type | Description
--- | --- | ---
`value` | `number` | the value

View Source Duik_api_fordoc.jsxinc, line 7705

Returns:
The value in degrees
Type: `float`

#### # static toRadians(value) → {float}

Converts the number from degrees to radians

##### Parameters:

Name | Type | Description
--- | --- | ---
`value` | `number` | the value

View Source Duik_api_fordoc.jsxinc, line 7695

Returns:
The value in radians
Type: `float`