de.cau.cs.kieler.core.math
Class KielerMath

java.lang.Object
  extended by de.cau.cs.kieler.core.math.KielerMath

public final class KielerMath
extends Object

Mathematics utility class for the KIELER projects.

Rating proposed yellow
(2009-12-11) msp

Method Summary
static KVectorChain appoximateSpline(KVectorChain controlPoints)
          Computes an approximation for the spline that is defined by the given control points.
static double averaged(double... values)
          Determines the average for an arbitrary number of doubles.
static float averagef(float... values)
          Determines the average for an arbitrary number of floats.
static int averagei(int... values)
          Determines the average for an arbitrary number of integers.
static long averagei(long... values)
          Determines the average for an arbitrary number of long integers.
static double binomiald(int n, int k)
          The binomial coefficient of integers n and k as double value.
static long binomiall(int n, int k)
          The binomial coefficient of integers n and k as long value.
static KVector[] calcBezierPoints(int resultSize, KVector... controlPoints)
          Calculate a number of points on the Bezier curve defined by the given control points.
static KVector[] calcBezierPoints(KVector... controlPoints)
          Calculate a number of points on the Bezier curve defined by the given control points.
static KVector[] calcBezierPoints(List<KVector> controlPoints, int resultSize)
          Calculates a number of points on the Bezier curve defined by the given control points.
static double distanceFromSpline(KVector start, KVector c1, KVector c2, KVector end, KVector needle)
          Calculate the distance from a cubic spline curve to the point needle.
static double factd(int x)
          The factorial of an integer x as double value.
static long factl(int x)
          The factorial of an integer x as long value.
static int getApproximationCount(KVector... controlPoints)
          Calculate a suggestion for the number of approximation points of the Bezier curve that is defined by the given control points.
static double maxd(double... values)
          Determines the maximum for an arbitrary number of doubles.
static float maxf(float... values)
          Determines the maximum for an arbitrary number of floats.
static int maxi(int... values)
          Determines the maximum for an arbitrary number of integers.
static long maxl(long... values)
          Determines the maximum for an arbitrary number of long integers.
static double mind(double... values)
          Determines the minimum for an arbitrary number of doubles.
static float minf(float... values)
          Determines the minimum for an arbitrary number of floats.
static int mini(int... values)
          Determines the minimum for an arbitrary number of integers.
static long minl(long... values)
          Determines the minimum for an arbitrary number of long integers.
static double pow(double a, int b)
          The first argument raised to the power of the second argument.
static float pow(float a, int b)
          The first argument raised to the power of the second argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

factl

public static long factl(int x)
The factorial of an integer x as long value. If x is negative the result is 1. This method always returns the exact value, but may lead to overflow for large input values.

Parameters:
x - an integer
Returns:
the factorial of x

factd

public static double factd(int x)
The factorial of an integer x as double value. If x is negative the result is 1. This method returns the exact value for small input values, and uses Stirling's approximation for large input values.

Parameters:
x - an integer
Returns:
the factorial of x

binomiall

public static long binomiall(int n,
                             int k)
The binomial coefficient of integers n and k as long value. If n is not positive or k is not between 0 and n the result is 1. This method always returns the exact value, but may take very long for large input values.

Parameters:
n - the upper integer
k - the lower integer
Returns:
n choose k

binomiald

public static double binomiald(int n,
                               int k)
The binomial coefficient of integers n and k as double value. If n is not positive or k is not between 0 and n the result is 1. This method returns the exact value for small input values, and uses an approximation for large input values.

Parameters:
n - the upper integer
k - the lower integer
Returns:
n choose k

pow

public static double pow(double a,
                         int b)
The first argument raised to the power of the second argument.

Parameters:
a - the base
b - the exponent
Returns:
a to the power of b

pow

public static float pow(float a,
                        int b)
The first argument raised to the power of the second argument.

Parameters:
a - the base
b - the exponent
Returns:
a to the power of b

calcBezierPoints

public static KVector[] calcBezierPoints(List<KVector> controlPoints,
                                         int resultSize)
Calculates a number of points on the Bezier curve defined by the given control points. The degree of the curve is derived from the number of control points. The array of resulting curve points includes the target point, but does not include the source point of the curve.

Parameters:
controlPoints - list of control points
resultSize - number of returned curve points
Returns:
points on the curve defined by the given control points

calcBezierPoints

public static KVector[] calcBezierPoints(int resultSize,
                                         KVector... controlPoints)
Calculate a number of points on the Bezier curve defined by the given control points. The degree of the curve is derived from the number of control points. The array of resulting curve points includes the target point, but does not include the source point of the curve.

Parameters:
controlPoints - the control points
resultSize - number of returned curve points
Returns:
points on the curve defined by the given control points

calcBezierPoints

public static KVector[] calcBezierPoints(KVector... controlPoints)
Calculate a number of points on the Bezier curve defined by the given control points. The degree of the curve is derived from the number of control points. The array of resulting curve points includes the target point, but does not include the source point of the curve. The number of approximation points is derived from the given control points.

Parameters:
controlPoints - the control points
Returns:
points on the curve defined by the given control points

getApproximationCount

public static int getApproximationCount(KVector... controlPoints)
Calculate a suggestion for the number of approximation points of the Bezier curve that is defined by the given control points. The degree of the curve is derived from the number of control points.

Parameters:
controlPoints - the control points
Returns:
a recommendation for the number of approximation points for the curve

appoximateSpline

public static KVectorChain appoximateSpline(KVectorChain controlPoints)
Computes an approximation for the spline that is defined by the given control points. The control points are interpreted as a series of cubic Bezier curves.

Parameters:
controlPoints - control points of a piecewise cubic spline
Returns:
a vector chain that approximates the spline

distanceFromSpline

public static double distanceFromSpline(KVector start,
                                        KVector c1,
                                        KVector c2,
                                        KVector end,
                                        KVector needle)
Calculate the distance from a cubic spline curve to the point needle.

Parameters:
start - starting point
c1 - control point 1
c2 - control point 2
end - end point
needle - point to look for
Returns:
distance from needle to curve

maxi

public static int maxi(int... values)
Determines the maximum for an arbitrary number of integers.

Parameters:
values - integer values
Returns:
the maximum of the given values, or MIN_VALUE if no values are given

mini

public static int mini(int... values)
Determines the minimum for an arbitrary number of integers.

Parameters:
values - integer values
Returns:
the minimum of the given values, or MAX_VALUE if no values are given

averagei

public static int averagei(int... values)
Determines the average for an arbitrary number of integers.

Parameters:
values - integer values
Returns:
the average of the given values

maxl

public static long maxl(long... values)
Determines the maximum for an arbitrary number of long integers.

Parameters:
values - integer values
Returns:
the maximum of the given values, or MIN_VALUE if no values are given

minl

public static long minl(long... values)
Determines the minimum for an arbitrary number of long integers.

Parameters:
values - integer values
Returns:
the minimum of the given values, or MAX_VALUE if no values are given

averagei

public static long averagei(long... values)
Determines the average for an arbitrary number of long integers.

Parameters:
values - integer values
Returns:
the average of the given values

maxf

public static float maxf(float... values)
Determines the maximum for an arbitrary number of floats.

Parameters:
values - float values
Returns:
the maximum of the given values, or -MAX_VALUE if no values are given

minf

public static float minf(float... values)
Determines the minimum for an arbitrary number of floats.

Parameters:
values - float values
Returns:
the minimum of the given values, or MAX_VALUE if no values are given

averagef

public static float averagef(float... values)
Determines the average for an arbitrary number of floats.

Parameters:
values - float values
Returns:
the average of the given values

maxd

public static double maxd(double... values)
Determines the maximum for an arbitrary number of doubles.

Parameters:
values - double values
Returns:
the maximum of the given values, or -MAX_VALUE if no values are given

mind

public static double mind(double... values)
Determines the minimum for an arbitrary number of doubles.

Parameters:
values - double values
Returns:
the minimum of the given values, or MAX_VALUE if no values are given

averaged

public static double averaged(double... values)
Determines the average for an arbitrary number of doubles.

Parameters:
values - double values
Returns:
the average of the given values