public class EuclidCoreTools
extends java.lang.Object
fastSquareRoot(double)
, or also an linear interpolation algorithm
interpolate(double, double, double)
.Modifier and Type | Field | Description |
---|---|---|
static double |
CLAMP_EPS |
Tolerance used in
clamp(double, double, double) to verify the bounds are sane. |
static double |
EPS_ANGLE_SHIFT |
An epsilon that is just slightly bigger than numerical inaccuracies used in
shiftAngleInRange(double, double) . |
static double |
EPS_NORM_FAST_SQRT |
Magic number used as a tolerance for switching to the fast square-root formula.
|
static double |
TwoPI |
This field is used to save unnecessary computation and represents the number
2.0 * Math.PI . |
Constructor | Description |
---|---|
EuclidCoreTools() |
Modifier and Type | Method | Description |
---|---|---|
static double |
angleDifferenceMinusPiToPi(double angleA,
double angleB) |
Computes the angle difference:
difference = angleA - angleB and shift the result to be contained in [ -pi, pi [. |
static double |
clamp(double value,
double minMax) |
Clamps value to the given range, defined by
-minMax and minMax , inclusive. |
static double |
clamp(double value,
double min,
double max) |
Clamps value to the given range, inclusive.
|
static boolean |
containsNaN(double[] array) |
Tests if at least one element in the given array is equal to
Double.NaN . |
static boolean |
containsNaN(double a,
double b) |
Tests if at least one of the two given elements is equal to Double.NaN.
|
static boolean |
containsNaN(double a,
double b,
double c) |
Tests if at least one of the three given elements is equal to Double.NaN.
|
static boolean |
containsNaN(double a,
double b,
double c,
double d) |
Tests if at least one of the four given elements is equal to Double.NaN.
|
static boolean |
containsNaN(double a0,
double a1,
double a2,
double a3,
double a4,
double a5,
double a6,
double a7,
double a8) |
Tests if at least one of the nine given elements is equal to Double.NaN.
|
static boolean |
epsilonEquals(double expectedValue,
double actualValue,
double epsilon) |
Tests if the two values are equal to an
epsilon :| expectedValue - actualValue | ≤ epsilon |
static double |
fastSquareRoot(double squaredValueClosedToOne) |
Calculates and returns the square root of the given value.
|
static double |
interpolate(double a,
double b,
double alpha) |
Performs a linear interpolation from
a to b given the percentage alpha . |
static double |
max(double a,
double b,
double c) |
Find and return the argument with the maximum value.
|
static double |
med(double a,
double b,
double c) |
Find and return the argument with the value in between the two others.
|
static double |
min(double a,
double b,
double c) |
Find and return the argument with the minimum value.
|
static double |
norm(double x,
double y) |
Calculates and returns the norm squared of the given two elements.
|
static double |
norm(double x,
double y,
double z) |
Calculates and returns the norm squared of the given three elements.
|
static double |
norm(double x,
double y,
double z,
double s) |
Calculates and returns the norm squared of the given four elements.
|
static double |
normSquared(double x,
double y) |
Calculates and returns the norm squared of the given two elements.
|
static double |
normSquared(double x,
double y,
double z) |
Calculates and returns the norm squared of the given three elements.
|
static double |
normSquared(double x,
double y,
double z,
double s) |
Calculates and returns the norm squared of the given four elements.
|
static double |
shiftAngleInRange(double angleToShift,
double angleStart) |
Recomputes the angle value
angleToShift such that the result is in [angleStart ,
angleStart + 2pi[ and still represent the same physical angle as
angleToShift . |
static double |
trimAngleMinusPiToPi(double angleToShift) |
Recomputes the angle value
angleToShift such that the result is in [ -pi,
pi [ and still represent the same physical angle as angleToShift . |
public static final double TwoPI
2.0 * Math.PI
.public static final double EPS_NORM_FAST_SQRT
public static final double EPS_ANGLE_SHIFT
shiftAngleInRange(double, double)
.public static final double CLAMP_EPS
clamp(double, double, double)
to verify the bounds are sane.public static double fastSquareRoot(double squaredValueClosedToOne)
This method is optimized when squaredValueClosedToOne
is equal to
1+/-2.107342E-8 by using an approximation of the square root.
squaredValueClosedToOne
- the value to calculates the square root of.public static boolean containsNaN(double a, double b)
a
- the first element.b
- the second element.true
if at least one element is equal to Double.NaN
, false
otherwise.public static boolean containsNaN(double a, double b, double c)
a
- the first element.b
- the second element.c
- the third element.true
if at least one element is equal to Double.NaN
, false
otherwise.public static boolean containsNaN(double a, double b, double c, double d)
a
- the first element.b
- the second element.c
- the third element.d
- the fourth element.true
if at least one element is equal to Double.NaN
, false
otherwise.public static boolean containsNaN(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
a0
- the first element.a1
- the second element.a2
- the third element.a3
- the fourth element.a4
- the fifth element.a5
- the sixth element.a6
- the seventh element.a7
- the eighth element.a8
- the ninth element.true
if at least one element is equal to Double.NaN
, false
otherwise.public static boolean containsNaN(double[] array)
Double.NaN
.array
- the array containing the elements to test for Double.NaN
. Not modified.true
if at least one element is equal to Double.NaN
, false
otherwise.public static double normSquared(double x, double y)
norm2 = x2 + y2
x
- the first element.y
- the second element.public static double normSquared(double x, double y, double z)
norm2 = x2 + y2 + z2
x
- the first element.y
- the second element.z
- the third element.public static double normSquared(double x, double y, double z, double s)
norm2 = x2 + y2 + z2 + s2
x
- the first element.y
- the second element.z
- the third element.s
- the fourth element.public static double norm(double x, double y)
norm = √(x2 + y2)
This method is optimized for calculating norms closed to 1 by using
fastSquareRoot(double)
. For computing norms that are not closed to 1, prefer using the
usual Math.sqrt(double)
on the norm squared.
x
- the first element.y
- the second element.public static double norm(double x, double y, double z)
norm = √(x2 + y2 + z2)
This method is optimized for calculating norms closed to 1 by using
fastSquareRoot(double)
. For computing norms that are not closed to 1, prefer using the
usual Math.sqrt(double)
on the norm squared.
x
- the first element.y
- the second element.z
- the third element.public static double norm(double x, double y, double z, double s)
norm = √(x2 + y2 + z2 + s2)
This method is optimized for calculating norms closed to 1 by using
fastSquareRoot(double)
. For computing norms that are not closed to 1, prefer using the
usual Math.sqrt(double)
on the norm squared.
x
- the first element.y
- the second element.z
- the third element.s
- the fourth element.public static double trimAngleMinusPiToPi(double angleToShift)
angleToShift
such that the result is in [ -pi,
pi [ and still represent the same physical angle as angleToShift
.
Edge cases:
Math.abs(angleToShift + Math.PI) <
EPS_ANGLE_SHIFT
, the returned angle is
-Math.PI
.
Math.abs(angleToShift - Math.PI) <
EPS_ANGLE_SHIFT
, the returned angle is
-Math.PI
.
angleToShift
- the angle to shift.public static double angleDifferenceMinusPiToPi(double angleA, double angleB)
difference = angleA - angleB
angleA
- the first angle in the difference.angleB
- the second angle in the difference.public static double shiftAngleInRange(double angleToShift, double angleStart)
angleToShift
such that the result is in [angleStart
,
angleStart
+ 2pi[ and still represent the same physical angle as
angleToShift
.
Edge cases:
Math.abs(angleToShift - angleStart) <
EPS_ANGLE_SHIFT
, the returned angle
is angleStart
.
Math.abs(angleToShift - angleStart + 2.0 * Math.PI) <
EPS_ANGLE_SHIFT
,
the returned angle is angleStart
.
angleToShift
- the angle to shift.angleStart
- the lowest admissible angle value.angleStart
, angleStart
+ 2pi[public static final double max(double a, double b, double c)
a
- the first argument to compare.b
- the second argument to compare.c
- the third argument to compare.public static final double min(double a, double b, double c)
a
- the first argument to compare.b
- the second argument to compare.c
- the third argument to compare.public static final double med(double a, double b, double c)
a
- the first argument to compare.b
- the second argument to compare.c
- the third argument to compare.public static boolean epsilonEquals(double expectedValue, double actualValue, double epsilon)
epsilon
:expectedValue
- actualValue
| ≤ epsilon
If any of the two values is equal to Double.NaN
, this method fails and returns
false
.
expectedValue
- the first value to compare.actualValue
- the second value to compare.epsilon
- the tolerance to use for the test.true
if the two values are considered to be equal, false otherwise
.public static double clamp(double value, double minMax)
-minMax
and minMax
, inclusive.value
- valueminMax
- inclusive absolute boundary-minMax
if value
is less than -minMax
minMax
if value
is greater than minMax
value
if value
is between or equal to -minMax
and
minMax
public static double clamp(double value, double min, double max)
value
- valuemin
- inclusive boundary startmax
- inclusive boundary endmin
if value
is less than min
max
if value
is greater than max
value
if value
is between or equal to min
and
max
public static double interpolate(double a, double b, double alpha)
a
to b
given the percentage alpha
.
result = (1.0 - alpha) * a + alpha * b
a
- the first value used in the interpolation.b
- the second value used in the interpolation.alpha
- the percentage to use for the interpolation. A value of 0 will return a
,
while a value of 1 will return b
.