|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.util.MathUtilities
The class MathUtilities collects several useful
static mathematical functions. The class may be viewed as an
extension of the tools found in java.lang.Math.
In 2.6.0, added the hyperbolic functions.
In 2.6.0, added getTileIndexLimits which is a
tool for computing tilings.
| Constructor Summary | |
MathUtilities()
|
|
| Method Summary | |
static double |
acosdeg(double value)
Return the arc cosine in degrees of the specified input value in the range -1 to +1. |
static double |
acosh(double c)
Inverse hyperbolic cosine. |
static double |
asindeg(double value)
Return the arc sine in degrees of the specified input value in the range -1 to +1. |
static double |
asinh(double s)
Inverse hyperbolic sine. |
static double |
atan2deg(double y,
double x)
Return the polar angle in degrees of the point (x, y) where the y-coordinate is given first and the x-coordinate second. |
static double |
atandeg(double value)
Return the arc tangent in degrees of the specified input value. |
static double |
atanh(double t)
Inverse hyperbolic tangent. |
static double |
cosdeg(double degrees)
Return the cosine of the given angle specified in degrees. |
static double |
cosh(double x)
Hyperbolic cosine. |
static int |
GCD(int a,
int b)
Returns the greatest common divisor of the int inputs a and b. |
static long |
GCD(long a,
long b)
Returns the greatest common divisor of the long inputs a and b. |
static int[] |
getTileIndexLimits(double x,
double w,
double x0,
double w0)
Returns an integer array with indices i
and j that determine how a small interval
from x0 to x0+w0 may be tiled
to cover a large interval from x to
x+w. |
static int |
LCM(int a,
int b)
Returns the least common multiple of the int inputs a and b. |
static long |
LCM(long a,
long b)
Returns the least common multiple of the long inputs a and b. |
static int |
modulus(int number,
int base)
Returns the modulus of int number relative to int base. |
static long |
modulus(long number,
long base)
Returns the modulus of long number relative to long base. |
static double |
power(double x,
int n)
Returns the n-th power of x, xn, using
the given integer exponent n. |
static double |
randomDouble(double x)
Return a random double r in the range between 0 and x. |
static double |
randomDouble(double x,
double y)
Return a random double r in the range between x and y. |
static int |
randomInt(int a)
Return a random int r in the range between 0 and a inclusive. |
static int |
randomInt(int a,
int b)
Return a random int r in the range between a and b inclusive. |
static double |
root(double x,
double n)
Returns the n-th root of x. |
static double |
sindeg(double degrees)
Return the sine of the given angle specified in degrees. |
static double |
sinh(double x)
Hyperbolic sine. |
static double |
tandeg(double degrees)
Return the tangent of the given angle specified in degrees. |
static double |
tanh(double x)
Hyperbolic tangent. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public MathUtilities()
| Method Detail |
public static int randomInt(int a)
a - an endpoint of a range
public static int randomInt(int a,
int b)
a - endpoint 1 of a rangeb - endpoint 2 of a rangepublic static double randomDouble(double x)
x - an endpoint of a range
public static double randomDouble(double x,
double y)
x - endpoint 1 of a rangey - endpoint 2 of a rangepublic static double sindeg(double degrees)
public static double cosdeg(double degrees)
public static double tandeg(double degrees)
public static double asindeg(double value)
public static double acosdeg(double value)
public static double atandeg(double value)
public static double atan2deg(double y,
double x)
y - the y-coordinate of the pointx - the x-coordinate of the pointpublic static double sinh(double x)
Hyperbolic sine.
Returns (exp(x) - 1/exp(x))/2
but computes the exponential only once.
x - the argumentpublic static double cosh(double x)
Hyperbolic cosine.
Returns (exp(x) + 1/exp(x))/2
but computes the exponential only once.
x - the argumentpublic static double tanh(double x)
Hyperbolic tangent.
Effectively returns sinh(x)/cosh(x)
but computes only one exponential.
x - the argumentpublic static double asinh(double s)
Inverse hyperbolic sine.
Returns log(s + sqrt(s*s + 1)).
s - the sinh value to invertpublic static double acosh(double c)
Inverse hyperbolic cosine.
Returns log(c + sqrt(c*c - 1)).
This chooses the positive branch of acosh,
that is, the return value is always >=0.
If c < 1 returns Nan.
c - the cosh value to invertpublic static double atanh(double t)
Inverse hyperbolic tangent.
Returns log(sqrt((1 + t)/(1 - t))).
If abs(t) >= 1 returns Nan.
t - the tanh value to invert
public static int GCD(int a,
int b)
Returns the greatest common divisor of the int inputs a and b.
The return value will be positive or zero and will be zero only if both a and b are zero.
public static long GCD(long a,
long b)
Returns the greatest common divisor of the long inputs a and b.
The return value will be positive or zero and will be zero only if both a and b are zero.
public static int LCM(int a,
int b)
Returns the least common multiple of the int inputs a and b.
The return value will be positive or zero and will be zero only if both a and b are zero.
public static long LCM(long a,
long b)
Returns the least common multiple of the long inputs a and b.
The return value will be positive or zero and will be zero only if both a and b are zero.
public static int modulus(int number,
int base)
Returns the modulus of int number relative to int base.
Returns n such that n is congruent to number modulo base and 0 <= n < Math.abs(base).
Throws ArithmeticException if base is zero.
public static long modulus(long number,
long base)
Returns the modulus of long number relative to long base.
Returns n such that n is congruent to number modulo base and 0 <= n < Math.abs(base).
Throws ArithmeticException if base is zero.
public static double power(double x,
int n)
Returns the n-th power of x, xn, using
the given integer exponent n.
Computes using ordinary arithmetic operations.
Returns 1.0 regardless of x if n equals 0.
Returns Double.NaN if n is negative and x is zero.
Note: Departs from the convention of the Java Math
class by calling the method power rather than simply
pow.
Note added in 2.5.0: This method uses only multiplication and
division and does not use exp or log. Recents experiments showed
that this method may be less accurate than calling
Math.pow. Hence the use of this method is no longer
recommended. It is retained in JPT to avoid breaking old code.
x - the basen - the exponent
public static double root(double x,
double n)
Returns the n-th root of x.
If n is 0, returns NaN.
If x is 0 and n > 0, returns 0; otherwise returns NaN.
If x > 0, returns Math.pow(x,1.0/n).
If x < 0 and n is an odd integer, then, with z = -x, returns -Math.pow(z,1.0/n); otherwise, returns NaN.
x - the basen - the inverse of the exponent
public static int[] getTileIndexLimits(double x,
double w,
double x0,
double w0)
Returns an integer array with indices i
and j that determine how a small interval
from x0 to x0+w0 may be tiled
to cover a large interval from x to
x+w.
Specifically:
i is the largest integer such that
(x0+i*w0)<=x.j is the smallest integer such that
(x+w)<=(x0+j*w0).With these specifications, a loop on k,
starting at k=i and running as long
as k(x0+k*w0,x0+k*w0+w0) that cover the
interval (x,x+w).
This utility is used in AbstractPaintable
to manage tiling but it is included here since it might
have wider value.
This function returns null if:
w<=0w0<=0Although the discussion and parameter names focus on the horizontal direction, the method can clearly be used to find tiling indices for vertical tiling as well.
x - the left endpoint of the interval to coverw - the width < 0 of the interval to coverx0 - the left endpoint of the covering intervalw0 - the width < 0 of the covering interval
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||