jv.vecmath
Class PuMath
- java.lang.Object
-
- jv.vecmath.PuMath
-
public class PuMath extends java.lang.ObjectMathematical utility functions extendingjava.lang.Math.- See Also:
Math- Author:
- Konrad Polthier
- Version:
- 18.04.05, 1.80 revised (ep) New method
precision.
20.04.02, 1.71 revised (kp) Accuracy of golden section increased.
29.08.00, 1.70 revised (ur) Heap sort method for int[] added.
07.07.99, 1.60 revised (kp) Additional hyperbolic trigonometric functions added.
11.06.99, 1.50 revised (kp) Hyperbolic trigonometric functions of Samy added.
00.00.97, 1.00 created (kp)
-
-
Field Summary
Fields Modifier and Type Field and Description static doubleEPSNumerical machine accuracy, e.g. used to check for zero and as stopping criterion.static doubleGOLDRatio of the golden sectionGOLD = (sqrt(5)+1)/2.
-
Constructor Summary
Constructors Constructor and Description PuMath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleacosh(double x)Mathematicalacosh(x)=ln(x+sqrt(x*x-1))function.static doubleacoth(double x)Mathematicalacoth(x) = ln((1.static booleanangle(double[] agl, double a, double b, double c)Return all three angles opposite to sides of triangle with given side lengths.static doubleangle(double a, double b, double c)Return angle opposite to sideaof triangle with given side lengths.static doublearea(double a, double b, double c)Return area of triangle with given side lengths.static doubleasinh(double x)Mathematicalasinh(x)=ln(x+sqrt(x*x+1))function.static doubleatanh(double x)Mathematicalatanh(x) = ln((1.static doublebinom(int n, int k)Return binomial coefficients n over k.static doublecosh(double x)Mathematicalcosh(x)function.static doublecoth(double x)Mathematicalcoth(x)function.static voidctg(double[] ctg, double a, double b, double c)Returncot()of all three angles opposite to sides of triangle with given side lengths.static doublectg(double a, double b, double c)Returncot(alpha)of angle opposite to sideaof triangle with given side lengths.static doubledist(double[] v, double[] w)Return distance between two vectors given as double arrays.static doubledot(double[] v, double[] w)Return dot product of two vectors given as double arrays.static doubleexp(double basis, double exp)Return exponential with respect to given basis.static intfactorial(int n)Return faculty n!static intgcd(int m, int n)Compute the greatest common divisor of two integers m and n.static intgcd(PiVector piv)Compute the greatest common divisor of an arrary of numbers.static voidheapsort(int n, double[] arrin, int[] indx)Sort an array of double value in ascending order.static voidheapsort(int n, int[] arrin, int[] indx)Sort an array of integer value in ascending order.static intlcm(int a, int b)Returns the least common multiple of a and b.static doublelog(double basis, double arg)Return logarithm with respect to given basis.static voidmain(java.lang.String[] args)Main method to test heapsort methodstatic intmodulo(int value, int base)Performs a modulo operation (value mod base).static doubleprecision(double x, double p)Rounds the given number to a certain precision.static voidprojectOnto(double[] v, double[] dir)Project vectorvonto linedirand store result inv.static intsign(double x)Return sign of argument as integer value.static doublesign(double a, double b)Return first argument with sign of second argument.static doublesinh(double x)Mathematicalsinh(x)function.static doublesqr(double x)Mathematicalx^2function.static doublesqrDist(double[] v, double[] w)Return square distance between two vectors given as double arrays.static doubletanh(double x)Mathematicaltanh(x)function.static doubletoDegrees(double angrad)Converts an angle measured in radians [0,2Pi] to the equivalent angle measured in degrees [0,360].static doubletoRadians(double angdeg)Converts an angle measured in degrees [0,360] to the equivalent angle measured in radians [0,2Pi].
-
-
-
Field Detail
-
EPS
public static final double EPS
Numerical machine accuracy, e.g. used to check for zero and as stopping criterion.- See Also:
- Constant Field Values
-
GOLD
public static final double GOLD
Ratio of the golden sectionGOLD = (sqrt(5)+1)/2.- See Also:
- Constant Field Values
-
-
Method Detail
-
sign
public static int sign(double x)
Return sign of argument as integer value.
-
sign
public static double sign(double a, double b)Return first argument with sign of second argument.
-
log
public static double log(double basis, double arg)Return logarithm with respect to given basis. Basis must be larger than 1.
-
exp
public static double exp(double basis, double exp)Return exponential with respect to given basis. Basis must be larger than 1.
-
sqr
public static double sqr(double x)
Mathematicalx^2function.
-
sinh
public static double sinh(double x)
Mathematicalsinh(x)function.
-
cosh
public static double cosh(double x)
Mathematicalcosh(x)function.
-
tanh
public static double tanh(double x)
Mathematicaltanh(x)function.
-
coth
public static double coth(double x)
Mathematicalcoth(x)function.
-
asinh
public static double asinh(double x)
Mathematicalasinh(x)=ln(x+sqrt(x*x+1))function.
-
acosh
public static double acosh(double x)
Mathematicalacosh(x)=ln(x+sqrt(x*x-1))function.
-
atanh
public static double atanh(double x)
Mathematicalatanh(x) = ln((1.+x)/(1.-x))/2.function.
-
acoth
public static double acoth(double x)
Mathematicalacoth(x) = ln((1.+x)/(x-1.))/2.function.
-
area
public static double area(double a, double b, double c)Return area of triangle with given side lengths.
-
angle
public static double angle(double a, double b, double c)Return angle opposite to sideaof triangle with given side lengths.
-
angle
public static boolean angle(double[] agl, double a, double b, double c)Return all three angles opposite to sides of triangle with given side lengths.
-
ctg
public static double ctg(double a, double b, double c)Returncot(alpha)of angle opposite to sideaof triangle with given side lengths.
-
ctg
public static void ctg(double[] ctg, double a, double b, double c)Returncot()of all three angles opposite to sides of triangle with given side lengths.
-
projectOnto
public static void projectOnto(double[] v, double[] dir)Project vectorvonto linedirand store result inv. Both vectors given as double arrays.
-
dot
public static double dot(double[] v, double[] w)Return dot product of two vectors given as double arrays.
-
sqrDist
public static double sqrDist(double[] v, double[] w)Return square distance between two vectors given as double arrays.
-
dist
public static double dist(double[] v, double[] w)Return distance between two vectors given as double arrays.
-
factorial
public static int factorial(int n)
Return faculty n! for integer argumentn.- Version:
- 02.06.04, 1.10 revised (kp) Avoid superfluous internal array allocation.
-
binom
public static double binom(int n, int k)Return binomial coefficients n over k.
-
toRadians
public static double toRadians(double angdeg)
Converts an angle measured in degrees [0,360] to the equivalent angle measured in radians [0,2Pi].- Parameters:
angdeg- an angle, in degrees- Returns:
- angle
angdegconverted to radians. - Since:
- JavaView 3.84.025
- Version:
- 15.03.05, 1.00 created (kp)
-
toDegrees
public static double toDegrees(double angrad)
Converts an angle measured in radians [0,2Pi] to the equivalent angle measured in degrees [0,360].- Parameters:
angrad- an angle, in radians- Returns:
- angle
angradconverted to degrees. - Since:
- JavaView 3.84.025
- Version:
- 15.03.05, 1.00 created (kp)
-
gcd
public static int gcd(int m, int n)Compute the greatest common divisor of two integers m and n. TODO: (poe) This does not work if m is negative.- Author:
- Konrad Polthier
- Version:
- 27.12.99, 1.10 created (kp) Converted to Java.
18.04.93, 1.00 created (kp) In C code.
-
gcd
public static int gcd(PiVector piv)
Compute the greatest common divisor of an arrary of numbers.- Author:
- Matthias Nieser
- Version:
- 06.08.10, 1.00 created (mn)
-
main
public static void main(java.lang.String[] args)
Main method to test heapsort method
-
heapsort
public static final void heapsort(int n, double[] arrin, int[] indx)Sort an array of double value in ascending order. The ascending order of the double array is provided through the indx vector. After performing this method, the indx vector contains the ordering of the double array, i.e. arrin[indx[0]] is the smallest and arrin[indx[n-1]] the largest double value.The initial values in the index vector are irrelevant.
New heapsort has index counting starts at 0 instead of previous NR-type at 1.
- Author:
- Numerical Recipes, changed to Java and adapted by Konrad Polthier
- Version:
- 25.03.03, 1.15 (kp) Return immediately if
n<=0.
09.06.00, 1.11 (kp) ArrayOutOfBounds exception for n==1 cured.
23.04.00, 1.10 (kp) NR counting changed to start at 0.
-
heapsort
public static final void heapsort(int n, int[] arrin, int[] indx)Sort an array of integer value in ascending order. The ascending order of the double array is provided through the indx vector. After performing this method, the indx vector contains the ordering of the integer array, i.e. arrin[indx[0]] is the smallest and arrin[indx[n-1]] the largest integer value.The initial values in the index vector are irrelevant.
New heapsort has index counting starts at 0 instead of previous NR-type at 1.
- Author:
- Numerical Recipes, changed to Java and adapted by Konrad Polthier
- Version:
- 25.03.03, 1.15 (kp) Return immediately if
n<=0.
09.06.00, 1.11 (kp) ArrayOutOfBounds exception for n==1 cured.
23.04.00, 1.10 (kp) NR counting changed to start at 0.
-
precision
public static double precision(double x, double p)Rounds the given number to a certain precision.- Parameters:
x- numberp- precision, e.g. 1e-10
-
modulo
public static int modulo(int value, int base)Performs a modulo operation (value mod base). If value is positive, this accords to the java operator %. This method also computes the correct modulo values for negative numbers, i.e.(-9) mod 10 = 1.- Parameters:
value- given value.@param @parambase- Base number for evaluation. Must be positive.- Author:
- Matthias Nieser
- Version:
- 22.10.06, 1.00 created (mn)
-
lcm
public static int lcm(int a, int b)Returns the least common multiple of a and b.- Parameters:
a- An integerb- An integer- Returns:
- The least common multiple.
- Author:
- Konstantin Poelke
-
-
"