public class MathUtil extends Object
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 and Description |
---|
MathUtil() |
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.
|
public static final double EPSILON
public static final double TAU
public static final double TWO_PI
public static final double HALF_PI
public static int round(double v)
Math.round(float)
that doesn't handle the special cases.public static int ifloor(double v)
Math.floor(double)
.public static int iceil(double v)
Math.ceil(double)
.public static double clamp(double v, double lower, double upper)
public static double roundNearest(double v, double target)
public static boolean isWithin(double v, double lower, double upper)
public static double normal(double normal, double mean, double stddev)
normal
- a normally distributed random value.mean
- the desired mean.stddev
- the desired standard deviation.public static double exponential(double random, double mean)
random
- a uniformly distributed random value.mean
- the desired mean.public static double lerpa(double a1, double a2, double t)
public static double lerp(double v1, double v2, double t)
public static boolean epsilonEquals(double v1, double v2)
public static double angularDistance(double a1, double a2)
public static double angularDifference(double a1, double a2)
public static double normalizeAngle(double a)
public static double normalizeAnglePositive(double a)
public static double mirrorAngle(double a)
public static void setToStringDecimalPlaces(int places)
public static String toString(double value)
public static String toString(double value, int decimalPlaces)
Copyright © 2017. All rights reserved.