jv.vecmath

Class PuMath

• java.lang.Object
• jv.vecmath.PuMath

• public class PuMath
extends java.lang.Object
Mathematical utility functions extending java.lang.Math.
Math
• Field Summary

Fields
Modifier and Type Field and Description
static double EPS
Numerical machine accuracy, e.g. used to check for zero and as stopping criterion.
static double GOLD
Ratio of the golden section GOLD = 2/(sqrt(5)-1).
• Constructor Summary

Constructors
Constructor and Description
PuMath()
• Method Summary

Methods
Modifier and Type Method and Description
static double acosh(double x)
Mathematical acosh(x)=ln(x+sqrt(x*x-1)) function.
static double acoth(double x)
Mathematical acoth(x) = ln((1.
static boolean angle(double[] agl, double a, double b, double c)
Return all three angles opposite to sides of triangle with given side lengths.
static double angle(double a, double b, double c)
Return angle opposite to side a of triangle with given side lengths.
static double area(double a, double b, double c)
Return area of triangle with given side lengths.
static double asinh(double x)
Mathematical asinh(x)=ln(x+sqrt(x*x+1)) function.
static double atanh(double x)
Mathematical atanh(x) = ln((1.
static double binom(int n, int k)
Return binomial coefficients n over k.
static double cosh(double x)
Mathematical cosh(x) function.
static double coth(double x)
Mathematical coth(x) function.
static void ctg(double[] ctg, double a, double b, double c)
Return cot() of all three angles opposite to sides of triangle with given side lengths.
static double ctg(double a, double b, double c)
Return cot(alpha) of angle opposite to side a of triangle with given side lengths.
static double dist(double[] v, double[] w)
Return distance between two vectors given as double arrays.
static double dot(double[] v, double[] w)
Return dot product of two vectors given as double arrays.
static double exp(double basis, double exp)
Return exponential with respect to given basis.
static int factorial(int n)
Return faculty n!
static int gcd(int m, int n)
Compute the greatest common divisor of two integers m and n.
static int gcd(PiVector piv)
Compute the greatest common divisor of an arrary of numbers.
static void heapsort(int n, double[] arrin, int[] indx)
Sort an array of double value in ascending order.
static void heapsort(int n, int[] arrin, int[] indx)
Sort an array of integer value in ascending order.
static int lcm(int a, int b)
Returns the least common multiple of a and b.
static double log(double basis, double arg)
Return logarithm with respect to given basis.
static void main(java.lang.String[] args)
Main method to test heapsort method
static int modulo(int value, int base)
Performs a modulo operation (value mod base).
static double precision(double x, double p)
Rounds the given number to a certain precision.
static void projectOnto(double[] v, double[] dir)
Project vector v onto line dir and store result in v.
static int sign(double x)
Return sign of argument as integer value.
static double sign(double a, double b)
Return first argument with sign of second argument.
static double sinh(double x)
Mathematical sinh(x) function.
static double sqr(double x)
Mathematical x^2 function.
static double sqrDist(double[] v, double[] w)
Return square distance between two vectors given as double arrays.
static double tanh(double x)
Mathematical tanh(x) function.
Converts an angle measured in radians [0,2Pi] to the equivalent angle measured in degrees [0,360].
Converts an angle measured in degrees [0,360] to the equivalent angle measured in radians [0,2Pi].
• Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• Field Detail

• EPS

public static final double EPS
Numerical machine accuracy, e.g. used to check for zero and as stopping criterion.
Constant Field Values
• GOLD

public static final double GOLD
Ratio of the golden section GOLD = 2/(sqrt(5)-1).
Constant Field Values
• Constructor Detail

• PuMath

public PuMath()
• 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)
Mathematical x^2 function.
• sinh

public static double sinh(double x)
Mathematical sinh(x) function.
• cosh

public static double cosh(double x)
Mathematical cosh(x) function.
• tanh

public static double tanh(double x)
Mathematical tanh(x) function.
• coth

public static double coth(double x)
Mathematical coth(x) function.
• asinh

public static double asinh(double x)
Mathematical asinh(x)=ln(x+sqrt(x*x+1)) function.
• acosh

public static double acosh(double x)
Mathematical acosh(x)=ln(x+sqrt(x*x-1)) function.
• atanh

public static double atanh(double x)
Mathematical atanh(x) = ln((1.+x)/(1.-x))/2. function.
• acoth

public static double acoth(double x)
Mathematical acoth(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 side a of 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)
Return cot(alpha) of angle opposite to side a of triangle with given side lengths.
• ctg

public static void ctg(double[] ctg,
double a,
double b,
double c)
Return cot() of all three angles opposite to sides of triangle with given side lengths.
• projectOnto

public static void projectOnto(double[] v,
double[] dir)
Project vector v onto line dir and store result in v. 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 argument n.
• binom

public static double binom(int n,
int k)
Return binomial coefficients n over k.

Converts an angle measured in degrees [0,360] to the equivalent angle measured in radians [0,2Pi].
Parameters:
angdeg - an angle, in degrees
Returns:
Since:
JavaView 3.84.025
• toDegrees

Converts an angle measured in radians [0,2Pi] to the equivalent angle measured in degrees [0,360].
Parameters:
Returns:
Since:
JavaView 3.84.025
• gcd

public static int gcd(int m,
int n)
Compute the greatest common divisor of two integers m and n.
• gcd

public static int gcd(PiVector piv)
Compute the greatest common divisor of an arrary of numbers.
• 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] 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.

• 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] 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.

• precision

public static double precision(double x,
double p)
Rounds the given number to a certain precision.
Parameters:
x - number
p - 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.
base - Base number for evaluation. Must be positive.
• lcm

public static int lcm(int a,
int b)
Returns the least common multiple of a and b.
Parameters:
a - An integer
b - An integer
Returns:
The least common multiple.