public class MathUtil extends Object
Modifier and Type | Field and Description |
---|---|
static double |
PHI_INV
The inverse of the Golden Ratio phi.
|
Constructor and Description |
---|
MathUtil() |
Modifier and Type | Method and Description |
---|---|
static double |
average(double x1,
double x2)
Computes the average of two numbers.
|
static int |
ceil(int num,
int denom)
Computes the ceiling function of the dividend of two integers.
|
static double |
clamp(double x,
double min,
double max)
Clamps a double value to a given range.
|
static int |
clamp(int x,
int min,
int max)
Clamps an int value to a given range.
|
static int |
clampMax(int x,
int max)
Clamps an integer to a given maximum limit.
|
static double |
log10(double x)
Computes the base-10 logarithm of a double value.
|
static double |
max(double v1,
double v2,
double v3) |
static double |
max(double v1,
double v2,
double v3,
double v4) |
static double |
min(double v1,
double v2,
double v3,
double v4) |
static double |
quasirandom(double curr)
Generates a quasi-random sequence of numbers in the range [0,1].
|
static double |
quasirandom(double curr,
double alpha)
Generates a quasi-random sequence of numbers in the range [0,1].
|
static int[] |
shuffle(int n)
Generates a randomly-shuffled list of the integers from [0..n-1].
|
static int |
wrap(int index,
int max)
Computes an index which wraps around a given maximum value.
|
public static double clamp(double x, double min, double max)
x
- the value to clampmin
- the minimum value of the rangemax
- the maximum value of the rangepublic static int clamp(int x, int min, int max)
x
- the value to clampmin
- the minimum value of the rangemax
- the maximum value of the rangepublic static int clampMax(int x, int max)
x
- the value to clampmax
- the maximum valuepublic static int ceil(int num, int denom)
num
- the numeratordenom
- the denominatorpublic static double log10(double x)
x
- a positive numberpublic static int wrap(int index, int max)
index
- the value to wrapmax
- the maximum value (or modulus)public static double average(double x1, double x2)
x1
- a numberx2
- a numberpublic static double max(double v1, double v2, double v3)
public static double max(double v1, double v2, double v3, double v4)
public static double min(double v1, double v2, double v3, double v4)
public static double quasirandom(double curr)
See Wikipedia: Low-discrepancy Sequences - Additive Recurrence.
The sequence is initialized by calling it with any positive fractional number; 0 works well for most uses.
curr
- the current number in the sequencepublic static double quasirandom(double curr, double alpha)
R(α) : tn = { t0 + nα }, n = 1,2,3,...When α is irrational this produces a Low discrepancy sequence which is more evenly distributed than random numbers.
The sequence is initialized by calling it with any positive fractional number. 0 works well for most uses.
curr
- the current number in the sequencealpha
- the sequence additive constantpublic static int[] shuffle(int n)
One use is to randomize points inserted into a KDtree
.
n
- the number of integers to shuffleCopyright © 2024. All rights reserved.