net.grelf
Class Maths

java.lang.Object
  extended by net.grelf.Maths

public class Maths
extends java.lang.Object

Static methods to do common mathematical calculations.


Nested Class Summary
static class Maths.Statistics
          Just a record to hold public values.
 
Field Summary
static double DEGREES_PER_RADIAN
           
static double RADIANS_PER_DEGREE
           
static double SQRT2
           
 
Method Summary
static double acosDegs(double cos)
          Get arccos in degrees.
static double angleDifference(double a1degrees, double a2degrees)
          Find the difference (a1 - a2) between 2 angles in degrees, taking into account periodicity.
static double angleMean(double... anglesInDegrees)
          Find the mean of a set of angles, taking into account periodicity.
static Maths.Statistics angleStatistics(java.util.Collection<java.lang.Double> anglesInDegrees)
          Calculate the min, max, mean and stdDev (all in degrees) of a set or list of angles, taking into account periodicity.
static Maths.Statistics angleStatistics(double... anglesInDegrees)
          Calculate the min, max, mean and stdDev of a set of angles, taking into account periodicity.
static double asinDegs(double sin)
          Get arcsin in degrees.
static double asinh(double x)
          Hyperbolic inverse sine.
static double atan2Degs(double sin, double cos)
          Get atan2 in degrees.
static double cosDegs(double xDegs)
          Get cosine of an angle given in degrees.
static double erf(double z)
          Gauss error function erf (z) = (2 / sqrt (pi)) * integral (exp (-t * t), t = 0..z) Fractional error less than 1.2E-7 although subject to catastrophic cancellation when z is very close to 0.
static double erf2(double z)
          Fractional error less than x.xx * 10 ^ -4.
static double in360(double xDegs)
          Convert angle x (degrees) to lie in range 0..360
static double phi(double z)
          Cumulative normal distribution calculated using erf ().
static double sinDegs(double xDegs)
          Get sine of an angle given in degrees.
static double tanDegs(double xDegs)
          Get tangent of an angle in degrees.
static double toDegrees(double xRads)
           
static double toRadians(double xDegs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEGREES_PER_RADIAN

public static final double DEGREES_PER_RADIAN
See Also:
Constant Field Values

RADIANS_PER_DEGREE

public static final double RADIANS_PER_DEGREE
See Also:
Constant Field Values

SQRT2

public static final double SQRT2
Method Detail

angleMean

public static double angleMean(double... anglesInDegrees)
Find the mean of a set of angles, taking into account periodicity. Uses angleStatistics ().


angleDifference

public static double angleDifference(double a1degrees,
                                     double a2degrees)
Find the difference (a1 - a2) between 2 angles in degrees, taking into account periodicity. The result is in the range -180..+180.


angleStatistics

public static Maths.Statistics angleStatistics(double... anglesInDegrees)
Calculate the min, max, mean and stdDev of a set of angles, taking into account periodicity. Uses angleDifference () from a working mean of the first angle. Does NOT use the erroneous method you can find on the web that averages sin and cos and then takes atan2.


angleStatistics

public static Maths.Statistics angleStatistics(java.util.Collection<java.lang.Double> anglesInDegrees)
Calculate the min, max, mean and stdDev (all in degrees) of a set or list of angles, taking into account periodicity. Uses angleDifference () from a working mean of the first angle. Does NOT use the erroneous method you can find on the web that averages sin and cos and then takes atan2.


in360

public static double in360(double xDegs)
Convert angle x (degrees) to lie in range 0..360


acosDegs

public static double acosDegs(double cos)
Get arccos in degrees.


asinDegs

public static double asinDegs(double sin)
Get arcsin in degrees.


asinh

public static double asinh(double x)
Hyperbolic inverse sine.


atan2Degs

public static double atan2Degs(double sin,
                               double cos)
Get atan2 in degrees.


sinDegs

public static double sinDegs(double xDegs)
Get sine of an angle given in degrees.


cosDegs

public static double cosDegs(double xDegs)
Get cosine of an angle given in degrees.


tanDegs

public static double tanDegs(double xDegs)
Get tangent of an angle in degrees.


toDegrees

public static double toDegrees(double xRads)

toRadians

public static double toRadians(double xDegs)

erf

public static double erf(double z)
Gauss error function erf (z) = (2 / sqrt (pi)) * integral (exp (-t * t), t = 0..z) Fractional error less than 1.2E-7 although subject to catastrophic cancellation when z is very close to 0. From Chebyshev fitting formula for erf (z) from Numerical Recipes, 6.2


erf2

public static double erf2(double z)
Fractional error less than x.xx * 10 ^ -4. Algorithm 26.2.17 in Abromowitz and Stegun, Handbook of Mathematical


phi

public static double phi(double z)
Cumulative normal distribution calculated using erf ().