Java Radian Calculation radiansToRA(final double raRadians)

Here you can find the source of radiansToRA(final double raRadians)

Description

Obtain the String RA of the given Radians.

License

Open Source License

Parameter

Parameter Description
raRadians a parameter

Return

String HH mm ss.s

Declaration

public static String radiansToRA(final double raRadians) 

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();

    /**//from   w ww.  j  a  va  2  s . c  o m
     * Obtain the String RA of the given Radians.
     * @param raRadians
     * @return String HH mm ss.s
     */
    public static String radiansToRA(final double raRadians) {
        return degreesToRA((raRadians * 180) / Math.PI);
    }

    public static String degreesToRA(double val) {
        // raneg reduction to [0.0,360.0)
        while (val < 0.0)
            val += 360.0;
        while (val >= 360.0)
            val -= 360.0;

        //if (val < 0.0 || val >= 360.0)
        //   throw new IllegalArgumentException("value "+val+" out of bounds: [0.0, 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 d = Double.toString(val);
        String s = null;
        String hh = Integer.toString(h);
        String mm = Integer.toString(m);
        if (h < 10)
            hh = "0" + h;
        if (m < 10)
            mm = "0" + m;

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

Related

  1. radianAdd(double a, double b)
  2. radiancheck(double x)
  3. radians(double d)
  4. radians(double w)
  5. radiansToBrads(double angleRadians)