pythagoras.d

## Class MathUtil

• ```public class MathUtil
extends Object```
Math utility methods.
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `EPSILON`
A small number.
`static double` `HALF_PI`
Pi times one half.
`static double` `TAU`
The circle constant, Tau (τ) http://tauday.com/
`static double` `TWO_PI`
Twice Pi.
• ### Constructor Summary

Constructors
Constructor and Description
`MathUtil()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static double` ```angularDifference(double a1, double a2)```
Returns the (shortest) difference between two angles, assuming that both angles are in [-pi, +pi].
`static double` ```angularDistance(double a1, double a2)```
Returns the (shortest) distance between two angles, assuming that both angles are in [-pi, +pi].
`static double` ```clamp(double v, double lower, double upper)```
Clamps a value to the range [lower, upper].
`static boolean` ```epsilonEquals(double v1, double v2)```
Determines whether two values are "close enough" to equal.
`static double` ```exponential(double random, double mean)```
Returns a random value according to the exponential distribution with the provided mean.
`static int` `iceil(double v)`
Returns the ceiling of v as an integer without calling the relatively expensive `Math.ceil(double)`.
`static int` `ifloor(double v)`
Returns the floor of v as an integer without calling the relatively expensive `Math.floor(double)`.
`static boolean` ```isWithin(double v, double lower, double upper)```
Checks whether the value supplied is in [lower, upper].
`static double` ```lerp(double v1, double v2, double t)```
Linearly interpolates between v1 and v2 by the parameter t.
`static double` ```lerpa(double a1, double a2, double t)```
Linearly interpolates between two angles, taking the shortest path around the circle.
`static double` `mirrorAngle(double a)`
Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]).
`static double` ```normal(double normal, double mean, double stddev)```
Returns a random value according to the normal distribution with the provided mean and standard deviation.
`static double` `normalizeAngle(double a)`
Returns an angle in the range [-pi, pi).
`static double` `normalizeAnglePositive(double a)`
Returns an angle in the range [0, 2pi).
`static int` `round(double v)`
A cheaper version of `Math.round(float)` that doesn't handle the special cases.
`static double` ```roundNearest(double v, double target)```
Rounds a value to the nearest multiple of a target.
`static void` `setToStringDecimalPlaces(int places)`
Sets the number of decimal places to show when formatting values.
`static String` `toString(double value)`
Formats the supplied value, truncated to the currently configured number of decimal places.
`static String` ```toString(double value, int decimalPlaces)```
Formats the supplied doubleing point value, truncated to the given number of decimal places.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### EPSILON

`public static final double EPSILON`
A small number.
Constant Field Values
• #### TAU

`public static final double TAU`
The circle constant, Tau (τ) http://tauday.com/
Constant Field Values
• #### TWO_PI

`public static final double TWO_PI`
Twice Pi.
Constant Field Values
• #### HALF_PI

`public static final double HALF_PI`
Pi times one half.
Constant Field Values
• ### Constructor Detail

• #### MathUtil

`public MathUtil()`
• ### Method Detail

• #### round

`public static int round(double v)`
A cheaper version of `Math.round(float)` that doesn't handle the special cases.
• #### ifloor

`public static int ifloor(double v)`
Returns the floor of v as an integer without calling the relatively expensive `Math.floor(double)`.
• #### iceil

`public static int iceil(double v)`
Returns the ceiling of v as an integer without calling the relatively expensive `Math.ceil(double)`.
• #### clamp

```public static double clamp(double v,
double lower,
double upper)```
Clamps a value to the range [lower, upper].
• #### roundNearest

```public static double roundNearest(double v,
double target)```
Rounds a value to the nearest multiple of a target.
• #### isWithin

```public static boolean isWithin(double v,
double lower,
double upper)```
Checks whether the value supplied is in [lower, upper].
• #### normal

```public static double normal(double normal,
double mean,
double stddev)```
Returns a random value according to the normal distribution with the provided mean and standard deviation.
Parameters:
`normal` - a normally distributed random value.
`mean` - the desired mean.
`stddev` - the desired standard deviation.
• #### exponential

```public static double exponential(double random,
double mean)```
Returns a random value according to the exponential distribution with the provided mean.
Parameters:
`random` - a uniformly distributed random value.
`mean` - the desired mean.
• #### lerpa

```public static double lerpa(double a1,
double a2,
double t)```
Linearly interpolates between two angles, taking the shortest path around the circle. This assumes that both angles are in [-pi, +pi].
• #### lerp

```public static double lerp(double v1,
double v2,
double t)```
Linearly interpolates between v1 and v2 by the parameter t.
• #### epsilonEquals

```public static boolean epsilonEquals(double v1,
double v2)```
Determines whether two values are "close enough" to equal.
• #### angularDistance

```public static double angularDistance(double a1,
double a2)```
Returns the (shortest) distance between two angles, assuming that both angles are in [-pi, +pi].
• #### angularDifference

```public static double angularDifference(double a1,
double a2)```
Returns the (shortest) difference between two angles, assuming that both angles are in [-pi, +pi].
• #### normalizeAngle

`public static double normalizeAngle(double a)`
Returns an angle in the range [-pi, pi).
• #### normalizeAnglePositive

`public static double normalizeAnglePositive(double a)`
Returns an angle in the range [0, 2pi).
• #### mirrorAngle

`public static double mirrorAngle(double a)`
Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]). The angle is mirrored around the PI/2 if it is positive, and -PI/2 if it is negative. One can visualize this as mirroring around the "y-axis".
• #### setToStringDecimalPlaces

`public static void setToStringDecimalPlaces(int places)`
Sets the number of decimal places to show when formatting values. By default, they are formatted to three decimal places.
• #### toString

`public static String toString(double value)`
Formats the supplied value, truncated to the currently configured number of decimal places. The value is also always preceded by a sign (e.g. +1.0 or -0.5).
• #### toString

```public static String toString(double value,
int decimalPlaces)```
Formats the supplied doubleing point value, truncated to the given number of decimal places. The value is also always preceded by a sign (e.g. +1.0 or -0.5).