public class ASTMath
extends java.lang.Object
These methods are provided to be sure they perform the calculations as required by the programs and to simplify translating the code to another language. For example, the Visual Basic function Truncate already does what the Trunc function defined below does and hence Trunc is unnecessary for Visual Basic. But, the Trunc function is defined here because other languages, such as Java, do not have a built-in Truncate function.
All methods are static so that an instance of this class does not have to be created before using these methods.
Copyright (c) 2018
Modifier and Type | Field and Description |
---|---|
static double |
EPS
Define a value to use when comparing small real numbers to see if they are the same.
|
Constructor and Description |
---|
ASTMath() |
Modifier and Type | Method and Description |
---|---|
static double |
AU2KM(double AU)
Convert AUs to kilometers
|
static double |
COS_D(double deg)
Compute the cosine of an angle
|
static double |
cuberoot(double x)
Find the cube root of a number.
|
static double |
deg2rad(double deg)
Converts degrees to radians
|
static double |
Frac(double x)
Returns the fractional part of a number.
|
static double |
INVCOS_D(double x)
Computes the inverse cosine of a value
|
static double |
INVSIN_D(double x)
Computes the inverse sine of a value
|
static double |
INVTAN_D(double x)
Computes the arctangent of a value
|
static double |
INVTAN2_D(double y,
double x)
Computes the arctangent of y/x, corrected for the quadrant the resulting angle is in.
|
static boolean |
isClose(double x,
double y)
Determine if the number x is 'close' to the number y
|
static boolean |
isEvenlyDivisible(int n,
int m)
Determines whether n is evenly divisible by m.
|
static double |
KM2AU(double KM)
Convert kilometers to AUs
|
static double |
KM2Miles(double km)
Convert kilometers to miles
|
static double |
Miles2KM(double miles)
Convert miles to kilometers
|
static double |
quadAdjust(double y,
double x)
Compute a quadrant adjustment for the inv tan
function given x and y.
|
static double |
rad2deg(double rad)
Converts radians to degrees
|
static ASTVect |
RotateX(double theta,
ASTVect V)
Rotate about the x-axis.
|
static ASTVect |
RotateZ(double theta,
ASTVect V)
Rotate about the z-axis.
|
static double |
Round(double x,
int d)
Round a number to the specified number of digits.
|
static double |
SIN_D(double deg)
Compute the sine of an angle
|
static double |
TAN_D(double deg)
Compute the tangent of an angle
|
static int |
Trunc(double x)
Gets the integer part of a number.
|
static double |
xMOD(double x,
double div)
Returns x modulo div.
|
static int |
xMOD(int x,
int div)
Returns x modulo div.
|
public static final double EPS
public static double cuberoot(double x)
x
- value whose cube root is desiredpublic static boolean isClose(double x, double y)
x
- first number to comparey
- 2nd number to comparepublic static boolean isEvenlyDivisible(int n, int m)
n
- number to checkm
- divisorpublic static double Frac(double x)
Frac(1.5) = 0.5, Frac(-1.5) = 0.5
x
- value whose decimal part is desiredpublic static double Round(double x, int d)
x
- number to roundd
- number of digitspublic static int Trunc(double x)
Trunc(1.5) = 1, Trunc(-1.5) = -1, etc.
Some languages have built in functions that perform this operation, such as Visual Basic's Truncate function. Also, some languages have a FIX function, which is NOT the same as the function defined here.
x
- value whose integer part is desiredpublic static int xMOD(int x, int div)
x
- x value in x MOD divisordiv
- divisorpublic static double xMOD(double x, double div)
x
- x value in x MOD divisordiv
- divisorpublic static double deg2rad(double deg)
deg
- angle in degreespublic static double rad2deg(double rad)
rad
- angle in radianspublic static double SIN_D(double deg)
deg
- angle in degreespublic static double COS_D(double deg)
deg
- angle in degreespublic static double TAN_D(double deg)
deg
- angle in degreespublic static double INVSIN_D(double x)
x
- value whose inverse sine is desiredpublic static double INVCOS_D(double x)
x
- value whose inverse cosine is desiredpublic static double INVTAN_D(double x)
x
- value whose arctangent is desiredpublic static double INVTAN2_D(double y, double x)
y
- y coordinatex
- x coordinatepublic static double quadAdjust(double y, double x)
y
- y coordinatex
- x coordinatepublic static double KM2Miles(double km)
km
- kilometers to convertpublic static double Miles2KM(double miles)
miles
- miles to convertpublic static double AU2KM(double AU)
AU
- AUs to convertpublic static double KM2AU(double KM)
KM
- kms to convertpublic static ASTVect RotateX(double theta, ASTVect V)
theta
- angle, in degrees, to rotateV
- vector to rotate