Version 1.2 (June 2013)
 All Classes Namespaces Files Functions Variables Pages
Static Public Member Functions | Static Public Attributes | List of all members
utils.ExtraMath Class Reference

Abstract class with some extra useful math functions. More...

Static Public Member Functions

static final double log2 (double x)
 Computes the logarithm of base 2. More...
 
static final int sq (int x)
 Square an integer number. More...
 
static final double sq (double x)
 Square a double. More...
 
static final double cube (double x)
 cube a double number More...
 
static final int exp2 (int x)
 Calculate x to the power of 2 where x is an integer. More...
 
static final double exp2 (double x)
 Calculate x to the power of 2 where x is a double. More...
 
static final double volumeOfASphere (double r)
 Calculate the volume of a sphere with radius r. More...
 
static final double volumeOfACylinder (double r, double l)
 Calculate the volume of a cylinder with radius r and length l. More...
 
static final double areaOfACircle (double r)
 Calculate the area of circle with radius r. More...
 
static final double radiusOfASphere (double v)
 Calculate the radius of a sphere with volume v. More...
 
static final double radiusOfASphere (double v, double lZ)
 Calculate the radius of a sphere with volume v assuming repetition along 3rd dimension. More...
 
static final double radiusOfACylinder (double v, double l)
 Returns the radius of a cylinder with volume v and length l. More...
 
static final double pointDistance (double x1, double y1, double z1, double x2, double y2, double z2)
 Calculate the distance between 2 points for points specified in X,Y,Z. More...
 
static final double pointDistance (ContinuousVector p1, ContinuousVector p2)
 Calculate the distance between 2 points for points specified as continuous vectors. More...
 
static double gammaCorrection (double v, double gamma)
 Perform gamma correction of value v: v^gamma check that v is in the [0,* 1] range. More...
 
static double max (double a, double b)
 Return the maximum among 2 doubles. More...
 
static double min (double a, double b)
 Return the minimum among 2 doubles. More...
 
static double max (double[] a)
 Return the maximum entry in a double array. More...
 
static double average (double[] a)
 Return the average entry in a double array. More...
 
static double min (double[] a)
 Return the minimum entry in a double array. More...
 
static double maxSquare (double a, double b)
 Return the maximum square among 2 doubles. More...
 
static boolean sameSign (double a, double b)
 Determine if two doubles are the same sign. More...
 
static double sumVector (double vector[])
 Return the sum of a vector. More...
 
static String toString (double value, boolean scFormat)
 Output a double value as a string, in a particular decimal format. More...
 
static double getUniRand ()
 Return a uniform distributed random number between 0 and 1. More...
 
static int getUniRandInt (int lBound, int hBound)
 Return an integer random number between two set bounds. More...
 
static double getUniRand (double lBound, double hBound)
 Return a double random number between two set bounds. More...
 
static double getNormRand ()
 Return a truncated N(0,1) distributed random number. Normal distributed random numbers are truncated at 2*sigma to prevent extreme values. More...
 
static double getExp2Rand ()
 Return 2 to the power of a uniformly distributed random number in [0,1]. More...
 
static double deviateFrom (double mu, double sigma)
 Randomise a value with a gaussian distribution in a range fixed by the ratio sigma. More...
 
static double mean (double[] v)
 Calculate the mean of a double array v. More...
 
static double stddev (double[] v)
 Calculate the standard deviation of a double array v. More...
 

Static Public Attributes

static java.text.DecimalFormat dfSc = new DecimalFormat("000.###E0")
 
static java.text.DecimalFormat dfUs = new DecimalFormat("########.##")
 
static Random random
 

Detailed Description

Abstract class with some extra useful math functions.

Abstract class with some extra useful math functions

Author
João Xavier (xavie.nosp@m.rj@m.nosp@m.skcc..nosp@m.org), Memorial Sloan-Kettering Cancer Center (NY, USA)

Member Function Documentation

static final double utils.ExtraMath.areaOfACircle ( double  r)
static

Calculate the area of circle with radius r.

Calculate the area of circle with radius r

Parameters
rRadius of the circle
Returns
area of circle
static double utils.ExtraMath.average ( double[]  a)
static

Return the average entry in a double array.

Return the average entry in a double array

Parameters
aVector of doubles
Returns
average double in a
static final double utils.ExtraMath.cube ( double  x)
static

cube a double number

cube a double number

Parameters
x: value to cube
Returns
The cube of x
static double utils.ExtraMath.deviateFrom ( double  mu,
double  sigma 
)
static

Randomise a value with a gaussian distribution in a range fixed by the ratio sigma.

Randomise a value with a gaussian distribution in a range fixed by the ratio sigma. If mu = 1 and sigma = .1, the results form a truncated gaussian distribution between 0.8 and 1.2 (2*sigma interval)

Parameters
mumean value
sigmastandard deviation
Returns
N(mu,sigma)-distributed random value within [mu-2*sigma,mu+2*sigma]
static final int utils.ExtraMath.exp2 ( int  x)
static

Calculate x to the power of 2 where x is an integer.

Calculate x to the power of 2 where x is an integer

Parameters
xNumber to be raised to power of 2
Returns
2^x
static final double utils.ExtraMath.exp2 ( double  x)
static

Calculate x to the power of 2 where x is a double.

Calculate x to the power of 2 where x is an double

Parameters
xNumber to be raised to power of 2
Returns
2^x
static double utils.ExtraMath.gammaCorrection ( double  v,
double  gamma 
)
static

Perform gamma correction of value v: v^gamma check that v is in the [0,* 1] range.

Perform gamma correction of value v: v^gamma check that v is in the [0,* 1] range

Parameters
vValue to check
gammaGamma Constant
Returns
V corrected by gamma
static double utils.ExtraMath.getExp2Rand ( )
static

Return 2 to the power of a uniformly distributed random number in [0,1].

Return 2 to the power of a uniformly distributed random number in [0,1]

Returns
2 to the power of a uniformly distributed random number in [0,1]
static double utils.ExtraMath.getNormRand ( )
static

Return a truncated N(0,1) distributed random number. Normal distributed random numbers are truncated at 2*sigma to prevent extreme values.

Return a truncated N(0,1) distributed random number. Normal distributed random numbers are truncated at 2*sigma to prevent extreme values.

Returns
truncated N(0,1) distributed random number.
static double utils.ExtraMath.getUniRand ( )
static

Return a uniform distributed random number between 0 and 1.

Return a uniform distributed random number between 0 and 1

Returns
uniform distributed random number in [0,1]
static double utils.ExtraMath.getUniRand ( double  lBound,
double  hBound 
)
static

Return a double random number between two set bounds.

Return a double random number between two set bounds

Parameters
lBoundLower bound
hBoundUpper bound
Returns
an int between lBound inclusive and hBound exclusive
static int utils.ExtraMath.getUniRandInt ( int  lBound,
int  hBound 
)
static

Return an integer random number between two set bounds.

Return an integer random number between two set bounds

Parameters
lBoundLower bound
hBoundUpper bound
Returns
an int between lBound inclusive and hBound exclusive
static final double utils.ExtraMath.log2 ( double  x)
static

Computes the logarithm of base 2.

Computes the logarithm of base 2

Parameters
xa number greater than 0.0
Returns
the logarithm base 2 of x
static double utils.ExtraMath.max ( double  a,
double  b 
)
static

Return the maximum among 2 doubles.

Return the maximum among 2 doubles

Parameters
aDouble 1
bDouble 2
Returns
the maximum among a and b
static double utils.ExtraMath.max ( double[]  a)
static

Return the maximum entry in a double array.

Return the maximum entry in a double array

Parameters
aVector of doubles
Returns
max double in a
static double utils.ExtraMath.maxSquare ( double  a,
double  b 
)
static

Return the maximum square among 2 doubles.

Return the maximum square among 2 doubles

Parameters
aDouble 1
bDouble 2
Returns
the maximum square among a and b
static double utils.ExtraMath.mean ( double[]  v)
static

Calculate the mean of a double array v.

Calculate the mean of a double array v

Parameters
vThe double array
Returns
The mean of the double array
static double utils.ExtraMath.min ( double  a,
double  b 
)
static

Return the minimum among 2 doubles.

Return the minimum among 2 doubles

Parameters
aDouble 1
bDouble 2
Returns
the minimum among a and b
static double utils.ExtraMath.min ( double[]  a)
static

Return the minimum entry in a double array.

Return the minimum entry in a double array

Parameters
aVector of doubles
Returns
minimum double in a
static final double utils.ExtraMath.pointDistance ( double  x1,
double  y1,
double  z1,
double  x2,
double  y2,
double  z2 
)
static

Calculate the distance between 2 points for points specified in X,Y,Z.

Calculate the distance between 2 points for points specified in X,Y,Z

Parameters
x1X coordinate of point 1
y1Y coordinate of point 1
z1Z coordinate of point 1
x2X coordinate of point 2
y2Y coordinate of point 2
z2Z coordinate of point 2
Returns
Distance between the two points
static final double utils.ExtraMath.pointDistance ( ContinuousVector  p1,
ContinuousVector  p2 
)
static

Calculate the distance between 2 points for points specified as continuous vectors.

Calculate the distance between 2 points for points specified as continuous vectors

Parameters
p1Point 1
p2Point 2
Returns
Distance between the two points
static final double utils.ExtraMath.radiusOfACylinder ( double  v,
double  l 
)
static

Returns the radius of a cylinder with volume v and length l.

Returns the radius of a cylinder with volume v and length l

Parameters
vVolume of the cylinder
lLength of the cylinder
Returns
Radius of the cylinder
static final double utils.ExtraMath.radiusOfASphere ( double  v)
static

Calculate the radius of a sphere with volume v.

Parameters
vVolume of the sphere
Returns
Radius of the sphere
static final double utils.ExtraMath.radiusOfASphere ( double  v,
double  lZ 
)
static

Calculate the radius of a sphere with volume v assuming repetition along 3rd dimension.

Calculate the radius of a sphere with volume v assuming repetition along 3rd dimension

Parameters
vVolume of the sphere
lZOmitted dimension
Returns
Radius of the sphere
static boolean utils.ExtraMath.sameSign ( double  a,
double  b 
)
static

Determine if two doubles are the same sign.

Determine if two doubles are the same sign

Parameters
aDouble 1
bDouble 2
Returns
Boolean noting whether the two are the same sign
static final int utils.ExtraMath.sq ( int  x)
static

Square an integer number.

Square an integer number

Parameters
xvalue to square
Returns
The square of x
static final double utils.ExtraMath.sq ( double  x)
static

Square a double.

Square a double

Parameters
x,:value to square
Returns
The square value of x
static double utils.ExtraMath.stddev ( double[]  v)
static

Calculate the standard deviation of a double array v.

Calculate the standard deviation of a double array v

Parameters
vThe double array
Returns
The standard deviation of the double array
static double utils.ExtraMath.sumVector ( double  vector[])
static

Return the sum of a vector.

Return the sum of a vector

Parameters
vectorVector to sum
Returns
The sum of that vector
static String utils.ExtraMath.toString ( double  value,
boolean  scFormat 
)
static

Output a double value as a string, in a particular decimal format.

Output a double value as a string, in a particular decimal format

Parameters
valueValue to be output
scFormatThe decimal format to use
Returns
A string containing that value in the required decimal format
static final double utils.ExtraMath.volumeOfACylinder ( double  r,
double  l 
)
static

Calculate the volume of a cylinder with radius r and length l.

Calculate the volume of a cylinder with radius r and length l

Parameters
rRadius of the cylinder
lLength of the cylinder
Returns
volume of cylinder
static final double utils.ExtraMath.volumeOfASphere ( double  r)
static

Calculate the volume of a sphere with radius r.

Calculate the volume of a sphere with radius r

Parameters
rRadius of the sphere
Returns
volume of sphere

Member Data Documentation

java.text.DecimalFormat utils.ExtraMath.dfSc = new DecimalFormat("000.###E0")
static

One option for decimal of decimals when these are written to the screen

java.text.DecimalFormat utils.ExtraMath.dfUs = new DecimalFormat("########.##")
static

Second option for decimal of decimals when these are written to the screen

Random utils.ExtraMath.random
static

Random number generator


The documentation for this class was generated from the following file: