public class MathUtils extends Object
java.lang.Math
class.
All functions have been implemented with extreme caution in order to provide a maximum performance.
Modifier and Type | Field and Description |
---|---|
static double |
DTOR
Conversion factor for degrees to radians for the
double data type. |
static float |
DTOR_F
Conversion factor for degrees to radians for the
float data type. |
static double |
EPS
The epsilon value for the
double data type. |
static float |
EPS_F
The epsilon value for the
float data type. |
static double |
HALFPI
Pi half
|
static double |
LOG10
The natural logarithm of 10 as given by
Math.logging(10) |
static double |
RTOD
Conversion factor for radians to degrees for the
double data type. |
static float |
RTOD_F
Conversion factor for radians to degrees for the
float data type. |
Constructor and Description |
---|
MathUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
ceilInt(double x)
Returns
(int) Math.ceil(x) . |
static long |
ceilLong(double x)
Returns
(long) Math.ceil(x) . |
static double |
computeRoundFactor(double min,
double max,
int numDigits)
Computes a rounding factor suitable for the given value range and number of significant digits after the decimal
point.
|
static float |
computeRoundFactor(float min,
float max,
int numDigits)
Computes a rounding factor suitable for the given value range and number of significant digits.
|
static byte[] |
createGammaCurve(double gamma,
byte[] f)
Creates a quantized gamma (correction) curve for 256 samples in range from
0 to 1 . |
static byte |
crop(byte val,
byte min,
byte max)
Crops the value to the range
min to max . |
static double |
crop(double val,
double min,
double max)
Crops the value to the range
min to max . |
static float |
crop(float val,
float min,
float max)
Crops the value to the range
min to max . |
static int |
crop(int val,
int min,
int max)
Crops the value to the range
min to max . |
static long |
crop(long val,
long min,
long max)
Crops the value to the range
min to max . |
static short |
crop(short val,
short min,
short max)
Crops the value to the range
min to max . |
static boolean |
equalValues(double x1,
double x2)
Compares two double values for equality within the fixed epsilon.
|
static boolean |
equalValues(double x1,
double x2,
double eps)
Compares two double values for equality within the given epsilon.
|
static boolean |
equalValues(float x1,
float x2)
Compares two float values for equality within the fixed epsilon.
|
static boolean |
equalValues(float x1,
float x2,
float eps)
Compares two float values for equality within the given epsilon.
|
static Dimension |
fitDimension(int n,
double a,
double b)
Computes an integer dimension for a given integer area that best fits the
rectangle given by floating point width and height.
|
static int |
floorAndCrop(double x,
int min,
int max)
First calls
Math.floor with x and then crops the resulting value to the range
min to max . |
static int |
floorInt(double value)
Returns
(int) Math.floor(value) . |
static long |
floorLong(double x)
Returns
(long) Math.floor(x) . |
static double |
getOrderOfMagnitude(double x)
Returns the order of magnitude for the value
x . |
static double |
interpolate2D(double wi,
double wj,
double x00,
double x10,
double x01,
double x11)
Performs a fast linear interpolation in two dimensions i and j.
|
static float |
interpolate2D(float wi,
float wj,
float x00,
float x10,
float x01,
float x11)
Performs a fast linear interpolation in two dimensions i and j.
|
static double |
log10(double x)
Computes the common logarithm (to the base 10).
|
static double |
round(double x,
double roundFactor)
Computes a rounded value for the given rounding factor.
|
static float |
round(float x,
float roundFactor)
Computes a rounded value for the given rounding factor.
|
static long |
roundAndCrop(double value,
long min,
long max)
First calls
Math.round with value and then crops the resulting value to the range
min to max . |
static int |
roundAndCrop(float x,
int min,
int max)
First calls
Math.round with x and then crops the resulting value to the range
min to max . |
static double |
sphereDistance(double sphereRadius,
double lambda1_rad,
double phi1_rad,
double lambda2_rad,
double phi2_rad) |
static double |
sphereDistanceDeg(double sphereRadius,
double lambda1_deg,
double phi1_deg,
double lambda2_deg,
double phi2_deg) |
static Rectangle[] |
subdivideRectangle(int width,
int height,
int numTilesX,
int numTilesY,
int extraBorder)
Subdivides a rectangle into tiles.
|
public static final float EPS_F
float
data type. The exact value of this constant is 1.0E-6
.public static final double EPS
double
data type. The exact value of this constant is
1.0E-12
.public static final double DTOR
double
data type.public static final double RTOD
double
data type.public static final float DTOR_F
float
data type.public static final float RTOD_F
float
data type.public static final double LOG10
Math.logging(10)
public static final double HALFPI
public static boolean equalValues(float x1, float x2)
x1
- the first valuex2
- the second valuepublic static boolean equalValues(double x1, double x2)
x1
- the first valuex2
- the second valuepublic static boolean equalValues(float x1, float x2, float eps)
x1
- the first valuex2
- the second valueeps
- the maximum allowed differencepublic static boolean equalValues(double x1, double x2, double eps)
x1
- the first valuex2
- the second valueeps
- the maximum allowed differencepublic static float interpolate2D(float wi, float wj, float x00, float x10, float x01, float x11)
wi
- weight in i-direction, a weight of 0.0 corresponds to i, 1.0 to i+1wj
- weight in j-direction, a weight of 0.0 corresponds to j, 1.0 to j+1x00
- first anchor point located at (i,j)x10
- second anchor point located at (i+1,j)x01
- third anchor point located at (i,j+1)x11
- forth anchor point located at (i+1,j+1)public static double interpolate2D(double wi, double wj, double x00, double x10, double x01, double x11)
wi
- weight in i-direction, a weight of 0.0 corresponds to i, 1.0 to i+1wj
- weight in j-direction, a weight of 0.0 corresponds to j, 1.0 to j+1x00
- first anchor point located at (i,j)x10
- second anchor point located at (i+1,j)x01
- third anchor point located at (i,j+1)x11
- forth anchor point located at (i+1,j+1)public static int floorAndCrop(double x, int min, int max)
Math.floor
with x
and then crops the resulting value to the range
min
to max
.public static int roundAndCrop(float x, int min, int max)
Math.round
with x
and then crops the resulting value to the range
min
to max
.public static long roundAndCrop(double value, long min, long max)
Math.round
with value
and then crops the resulting value to the range
min
to max
.value
- the value to round and cropmin
- the minimum value of the crop rangemax
- the maximum value of the crop rangepublic static int floorInt(double value)
(int) Math.floor(value)
.value
- the double
value to be convertedvalue
public static long floorLong(double x)
(long) Math.floor(x)
.x
- the value to be convertedx
public static int ceilInt(double x)
(int) Math.ceil(x)
.x
- the value to be convertedx
public static long ceilLong(double x)
(long) Math.ceil(x)
.x
- the value to be convertedx
public static float computeRoundFactor(float min, float max, int numDigits)
min
- the minimum value of the rangemax
- the maximum value of the rangenumDigits
- the number of significant digits, must be =0
round(float, float)
public static double computeRoundFactor(double min, double max, int numDigits)
min
- the minimum value of the rangemax
- the maximum value of the rangenumDigits
- the number of significant digits after the decimal point, must be =0
round(double, double)
public static float round(float x, float roundFactor)
int
and then again divided by the the rounding factor.
The rounding factor can be computed for a given value range and accuracy with the
computeRoundFactor
method.
x
- the value to be roundedroundFactor
- the rounding factor specifying the accuracy, should always be a power to the base 10computeRoundFactor(float, float, int)
public static double round(double x, double roundFactor)
int
and then again divided by the the rounding factor.
The rounding factor can be computed for a given value range and accuracy with the
computeRoundFactor
method.
x
- the value to be roundedroundFactor
- the rounding factor specifying the accuracy, should always be a power to the base 10computeRoundFactor(double, double, int)
public static double getOrderOfMagnitude(double x)
x
.x
- the inputMath.floor(log10(x))
public static double log10(double x)
x
- the inputMath.logging(x)/LOG10
public static byte[] createGammaCurve(double gamma, byte[] f)
0
to 1
. The
array returned for can be used as a lookup table for gamma transformations. In order to interpret the value
correctly use the following code snippet:
byte[] f = MathUtils.createGammaCurve(gamma, null); for (int i = 0; i < 256; i++) { // transform i --> j j = f[i] & 0xff; // now use j instead of i }
gamma
- the gamma value, reasonable range is 1/10
to 10
, if 1
then
each f[i] & 0xff
will be i
.f
- the curve as an array of length 256. If not null
, the method used this array as returen
value after values have been written into it. If null
, the method creates a new array
and returns it.public static byte crop(byte val, byte min, byte max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static short crop(short val, short min, short max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static int crop(int val, int min, int max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static long crop(long val, long min, long max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static float crop(float val, float min, float max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static double crop(double val, double min, double max)
min
to max
.val
- the value to cropmin
- the minimum crop limitmax
- the maximum crop limitpublic static Dimension fitDimension(int n, double a, double b)
n
- the integer areaa
- the rectangle's widthb
- the rectangle's heightpublic static Rectangle[] subdivideRectangle(int width, int height, int numTilesX, int numTilesY, int extraBorder)
width
- the rectangle's widthheight
- the rectangle's heightnumTilesX
- the number of tiles in X directionnumTilesY
- the number of tiles in Y directionextraBorder
- an extra border size to extend each tilepublic static final double sphereDistanceDeg(double sphereRadius, double lambda1_deg, double phi1_deg, double lambda2_deg, double phi2_deg)
sphereRadius
- the radius of the spherelambda1_deg
- the lambda angle of point one, in degreephi1_deg
- the phi angle of point one, in degreelambda2_deg
- the lambda angle of point two, in degreephi2_deg
- the phi angle of point one, in degreepublic static final double sphereDistance(double sphereRadius, double lambda1_rad, double phi1_rad, double lambda2_rad, double phi2_rad)
sphereRadius
- the radius of the spherelambda1_rad
- the lambda angle of point one, in radiansphi1_rad
- the phi angle of point one, in radianslambda2_rad
- the lambda angle of point two, in radiansphi2_rad
- the phi angle of point one, in radiansCopyright © 2014–2017 European Space Agency (ESA). All rights reserved.