com.tensegrity.generic.math
Class MathUtil

java.lang.Object
  extended bycom.tensegrity.generic.math.MathUtil

public final class MathUtil
extends java.lang.Object

MathUtil consists of various math related utility functions. All provided methods are static.

Version:
$Id: MathUtil.java,v 1.25 2006/01/26 17:05:22 MichaelKegel Exp $
Author:
M.Kegel, S.Rutz

Method Summary
static double degtoRad(double degrees)
          Converts the given angle in degree into the aquivalent angle in radians.
static int fractAsInt(double intWithFrac)
          Converts the fractional part of the real number given by d into an int.
static int gcd(int m, int n)
          Computes the greatest common divisor of two numbers.
static long gcd(long m, long n)
          Computes the greatest common divisor of two numbers.
static double mod(double divident, double divisor)
          Returns the remainder of a real number devision.
static void mul(double[] vector, Matrix44D matrix)
          Multiplicates the components of the given vector with the components of the given matrix and writes the results back to the vector components.
static void mul(Vector4 vector, Matrix44D matrix)
          Multiplicates the component of the given vector with the component of the given matrix and writes the results back to the vector components.
static double[] pq(double a, double b, double c)
          Solves a quadratic polynomial (degree = 2) of the form f(x) = ax^2 + bx + c using a numerically stable variant of the pq formula.
static double radByVector(double dx, double dy)
          Calculates the angle in radians of the two dimensional vector given by its two components.
static double radtoDeg(double radians)
          Converts the given angle in radians into the aquivalent angle in degree This method is final.
static void randomPermutation(int[] array)
          Randomly shuffles an integer array in place.
static void randomPermutation(java.lang.Object[] array)
          Randomly shuffles an array in place.
static double sign(double n)
          Returns the sign of a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

randomPermutation

public static final void randomPermutation(java.lang.Object[] array)
Randomly shuffles an array in place. (Generates a single random permutation of the array).

Parameters:
array - the array whose contents to shuffle in place.

randomPermutation

public static final void randomPermutation(int[] array)
Randomly shuffles an integer array in place. (Generates a single random permutation of the array).

Parameters:
array - the integer array whose contents to shuffle in place.

gcd

public static final long gcd(long m,
                             long n)
Computes the greatest common divisor of two numbers.

Parameters:
m - the first divident.
n - the second divident.
Returns:
greatest common divisor.

gcd

public static final int gcd(int m,
                            int n)
Computes the greatest common divisor of two numbers.

Parameters:
m - the first number.
n - the second number.
Returns:
greatest common divisor.

sign

public static final double sign(double n)
Returns the sign of a value.

Parameters:
n - the value whose sign is to be computed.
Returns:
+1 if n is >= 0.0, otherwise -1.

pq

public static final double[] pq(double a,
                                double b,
                                double c)
Solves a quadratic polynomial (degree = 2) of the form f(x) = ax^2 + bx + c using a numerically stable variant of the pq formula. The solutions might be NaN, if negative square root(s) occur.

Parameters:
a - coefficient for x^2.
b - coefficient for x^1.
c - coefficient for x^0.
Returns:
the solutions for the quadratic equation.

mul

public static final void mul(Vector4 vector,
                             Matrix44D matrix)
Multiplicates the component of the given vector with the component of the given matrix and writes the results back to the vector components.

Parameters:
vector - the vector to multiplicate.
matrix - the matrix to multiplicate with.

mul

public static final void mul(double[] vector,
                             Matrix44D matrix)
Multiplicates the components of the given vector with the components of the given matrix and writes the results back to the vector components.

Parameters:
vector - the vector to multiplicate.
matrix - the matrix to multiplicate with.

mod

public static double mod(double divident,
                         double divisor)
Returns the remainder of a real number devision.

Parameters:
divident - the divident.
divisor - the divisor.
Returns:
remainder of the division.

fractAsInt

public static int fractAsInt(double intWithFrac)
Converts the fractional part of the real number given by d into an int.

Parameters:
intWithFrac - a real number with fractional part.
Returns:
fractional part of the real number as integer.

degtoRad

public static final double degtoRad(double degrees)
Converts the given angle in degree into the aquivalent angle in radians. This method is final, otherwise one can use java.lang.Math.toRadians.

Parameters:
degrees - angle in degrees.
Returns:
angle in radians.

radtoDeg

public static final double radtoDeg(double radians)
Converts the given angle in radians into the aquivalent angle in degree This method is final. One can also use java.lang.Math.toDegrees.

Parameters:
radians - angle in radians.
Returns:
angle in degrees.

radByVector

public static final double radByVector(double dx,
                                       double dy)
Calculates the angle in radians of the two dimensional vector given by its two components.

Parameters:
dx - horizontal component of vector
dy - vertical component of vector
Returns:
the angle of the vector in radians where 0 means east and thr rotation direction is counterclockwise


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.