Java Utililty Methods Angle

List of utility methods to do Angle

Description

The list of methods to do Angle are organized into topic(s).

Method

booleanangleInRange(double angle, double min, double max)
angle In Range
if (min < max) {
    return (angle > min && angle < max);
return (angle > min || angle < max);
booleanangleInRange(float theta1, float theta2, float tolerance)
angle In Range
theta1 = boundAngle(theta1);
theta2 = boundAngle(theta2);
float dtheta = Math.abs(theta1 - theta2);
if (dtheta > Math.PI) {
    if (2 * Math.PI - dtheta <= tolerance)
        return true;
} else {
    if (dtheta <= tolerance)
...
floatangleLinear(float a, float b, int spin, float f)
angle Linear
if (spin == 0)
    return a;
if (spin > 0 && (b - a) < 0)
    b += 360.0f;
if (spin < 0 && (b - a) > 0)
    b -= 360.0f;
return linear(a, b, f);
doubleangleOfLine(int x1, int y1, int x2, int y2)
Given the coordinates of the start and end of a line, returns the angle in radians of the line
if (y1 == y2) 
    if (x2 >= x1)
        return 0.0;
    else
        return Math.PI;
if (x1 == x2) 
    if (y2 >= y1)
        return Math.PI / 2.0;
...
doubleangleOfLineDeg(double x1, double y1, double x2, double y2)
Determines the angle at which a line must be drawn to get from the first point to the second in degrees.
double t = Math.toDegrees(Math.atan2((y2 - y1), (x2 - x1)));
return (t < 0) ? t + 360 : t;
intangleRadToDegClipped(final double angleRad)
angle Rad To Deg Clipped
final int degUnclipped = (int) (Math.toDegrees(angleRad) + 0.5);
return ((degUnclipped % 360) + 360) % 360;
booleananglesInvalid(double sza, double vza, double saa, double vaa)
angles Invalid
final double eps = 1.E-6;
final boolean szaInvalid = sza > 70.0; 
final boolean vzaInvalid = Double.isNaN(vza);
final boolean saaInvalid = Double.isNaN(saa);
final boolean vaaInvalid = Double.isNaN(vaa);
return szaInvalid || saaInvalid || vzaInvalid || vaaInvalid;
floatangleSum(float a1, float a2)
Sum of two angles.
double val = a1 + a2;
if (val > Math.PI) {
    val -= 2. * Math.PI;
if (val < -Math.PI) {
    val += 2. * Math.PI;
return (float) val;
...
floatangleTo(final int x, final int y, final int thatx, final int thaty)
Returns the angle between this point and that point.
final int dx = thatx - x;
final int dy = thaty - y;
return (float) Math.atan2(dy, dx);
StringangleToCompass(double angleIn)
angle To Compass
double angle = angleIn % 360.0;
if (angle < 22.5)
    return "N ";
else if (angle < 67.5)
    return "NE";
else if (angle < 112.5)
    return "E ";
else if (angle < 157.5)
...