pythagoras.f

## Class MathUtil

• Direct Known Subclasses:
FloatMath

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

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

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

All Methods
Modifier and Type Method and Description
`static float` ```angularDifference(float a1, float a2)```
Returns the (shortest) difference between two angles, assuming that both angles are in [-pi, +pi].
`static float` ```angularDistance(float a1, float a2)```
Returns the (shortest) distance between two angles, assuming that both angles are in [-pi, +pi].
`static float` ```clamp(float v, float lower, float upper)```
Clamps a value to the range [lower, upper].
`static boolean` ```epsilonEquals(float v1, float v2)```
Determines whether two values are "close enough" to equal.
`static float` ```exponential(float random, float mean)```
Returns a random value according to the exponential distribution with the provided mean.
`static int` `iceil(float v)`
Returns the ceiling of v as an integer without calling the relatively expensive `Math.ceil(double)`.
`static int` `ifloor(float v)`
Returns the floor of v as an integer without calling the relatively expensive `Math.floor(double)`.
`static boolean` ```isWithin(float v, float lower, float upper)```
Checks whether the value supplied is in [lower, upper].
`static float` ```lerp(float v1, float v2, float t)```
Linearly interpolates between v1 and v2 by the parameter t.
`static float` ```lerpa(float a1, float a2, float t)```
Linearly interpolates between two angles, taking the shortest path around the circle.
`static float` `mirrorAngle(float a)`
Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]).
`static float` ```normal(float normal, float mean, float stddev)```
Returns a random value according to the normal distribution with the provided mean and standard deviation.
`static float` `normalizeAngle(float a)`
Returns an angle in the range [-pi, pi).
`static float` `normalizeAnglePositive(float a)`
Returns an angle in the range [0, 2pi).
`static int` `round(float v)`
A cheaper version of `Math.round(float)` that doesn't handle the special cases.
`static float` ```roundNearest(float v, float 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(float value)`
Formats the supplied value, truncated to the currently configured number of decimal places.
`static String` ```toString(float value, int decimalPlaces)```
Formats the supplied floating 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 float EPSILON`
A small number.
Constant Field Values
• #### TAU

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

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

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

• #### MathUtil

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

• #### round

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

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

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

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

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

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

```public static float normal(float normal,
float mean,
float 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 float exponential(float random,
float 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 float lerpa(float a1,
float a2,
float 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 float lerp(float v1,
float v2,
float t)```
Linearly interpolates between v1 and v2 by the parameter t.
• #### epsilonEquals

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

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

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

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

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

`public static float mirrorAngle(float 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(float 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(float value,
int decimalPlaces)```
Formats the supplied floating 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).