Java Degree Convert to degreesToRA(double val)

Here you can find the source of degreesToRA(double val)

Description

degrees To RA

License

Open Source License

Declaration

public static String degreesToRA(double val) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.NumberFormat;

public class Main {
    private static NumberFormat raFormat = NumberFormat.getInstance();

    public static String degreesToRA(double val) {
        // raneg reduction to [0.0,360.0)
        while (val < 0.0) {
            val += 360.0;
        }//from   w w  w.ja va  2 s.  c  om
        while (val >= 360.0) {
            val -= 360.0;
        }

        // 24 hours/360 degrees = 15 deg/hour
        int h = (int) (val / 15.0);
        val -= h * 15.0;
        // 15 deg/hour == 0.25 deg/min == 4 min/deg
        int m = (int) (val * 4.0);
        val -= m / 4.0;
        // 4 min/deg == 240 sec/deg
        val *= 240.0;

        String hh = Integer.toString(h);
        String mm = Integer.toString(m);

        if (h < 10) {
            hh = "0" + h;
        }
        if (m < 10) {
            mm = "0" + m;
        }

        return (hh + ":" + mm + ":") + raFormat.format(val);
    }
}

Related

  1. degreeSin(double angle)
  2. degreesMinSecToDegrees(String position)
  3. degreesToDecimal(String input)
  4. degreesToMetres(double degrees)
  5. degreesToPercent(float n)
  6. degreesToSexigessimal(double ra, double dec)
  7. degreesToString(final double value, final char positiveChar, final char negativeChar)
  8. toDecimalDegrees(String picaValue)
  9. toDegrees(double degrees, int nDecimals, boolean longitude)