// // AstroCoords.java: // Various coordinate classes useful for astronomical calculations. // Copyright 1996 by Akkana Peck. // // package Akk.Astro; import java.lang.Math; import java.awt.Graphics; import java.awt.Button; import java.awt.Event; import java.awt.Font; import java.applet.Applet; // A data type to represent heliocentric coordinates: class HelioCoords { double x, y, r; double l; // heliocentric longitude, useful for calculation public HelioCoords() { x=0.; y=0.; r=0.; l=0.; } public HelioCoords(double rr, double xx, double yy) { x=xx; y=yy; r=rr; l = 0; } public HelioCoords(double rr, double xx, double yy, double ll) { x=xx; y=yy; r=rr; l = ll; } } // A class that holds right ascension and declination: class AstroCoords { double RA, dec, dist; double get_RA_radians() { return RA; } double get_dec_radians() { return dec; } double get_RA_hours() { return RA * 12 / Math.PI; } double get_dec_degrees() { return dec * 180 / Math.PI; } public AstroCoords(double _ra, double _dec) { RA = _ra; dec = _dec; } public AstroCoords(double _ra, double _dec, double _dist) { RA = _ra; dec = _dec; dist = _dist; } public AstroCoords(String rastring, String decstring) { RA = getRAFromString(rastring); dec = getDecFromString(decstring); } double getRAFromString(String str) { double ret; int index = str.indexOf('h'); if (index < 0) index = str.indexOf(':'); if (index >= 0) { String sub = str.substring(0, index); ret = Double.valueOf(sub).doubleValue(); str = str.substring(index+1); index = str.indexOf('m'); if (index < 0) index = str.indexOf(':'); if (index > 0) sub = str.substring(0, index); else sub = str; ret += (Double.valueOf(sub).doubleValue() / 60.); // ignore seconds for now, minutes is close enough } else ret = Double.valueOf(str).doubleValue(); // RA is now in decimal hours. Convert to radians: ret *= Math.PI / 12; return ret; } double getDecFromString(String str) { double ret; int index = str.indexOf('^'); if (index < 0) index = str.indexOf(':'); if (index >= 0) { String sub = str.substring(0, index); ret = Double.valueOf(sub).doubleValue(); str = str.substring(index+1); index = str.indexOf('\''); if (index < 0) index = str.indexOf(':'); if (index > 0) sub = str.substring(0, index); else sub = str; ret += (Double.valueOf(sub).doubleValue() / 60.); } else ret = Double.valueOf(str).doubleValue(); // ignore seconds for now, minutes is close enough // dec is now in decimal degrees. Convert to radians: ret *= Math.PI / 180; return ret; } public void setRAFromString(String s) { RA = getRAFromString(s); } public void setDecFromString(String s) { dec = getDecFromString(s); } // Figure out whether we're inside some pair of arbitrary limits. // Account for the mod24 nature of right ascension, // and accept either -1 or 23 in either position. boolean inside(AstroCoords limit1, AstroCoords limit2) { // First check declination, since that's easy (dec doesn't wrap): if (dec < limit1.dec || dec > limit2.dec) return false; // If our coordinate is negative, convert to positive: if (RA < 0) RA += 2 * Math.PI; // and the same for limits: if (limit1.RA < 0) limit1.RA += 2 * Math.PI; if (limit2.RA < 0) limit2.RA += 2 * Math.PI; while (limit2.RA > 2*Math.PI) limit2.RA -= 2*Math.PI; // Case 1: we're not wrapping through zero if (limit1.RA < limit2.RA) return (RA >= limit1.RA && RA <= limit2.RA); // Case 2: we are wrapping through zero return (RA <= limit1.RA || RA >= limit2.RA); } public String toString() { double ra_deg = RA * 12 / Math.PI; Long ra_hours = new Long((long)ra_deg); double ra_frac = ra_deg - ra_hours.longValue(); Long ra_min = new Long((long)(ra_frac*60)); Float ra_sec = new Float((ra_frac * 60 - ra_min.longValue()) * 60); double dec_deg = dec * 180 / Math.PI; Long dec_int = new Long((long)dec_deg); double dec_frac = dec_deg - dec_int.longValue(); Long dec_min = new Long((long)(Math.abs(dec_frac)*60)); Long dec_sec = new Long((long)(Math.abs(dec_frac * 60 - dec_min.longValue()) * 60)); Double dd = new Double(dist); return "RA = " + ra_hours.toString() + "h " + ra_min.toString() + "m " // + ra_sec.toString() + "s " + " Dec = " + dec_int.toString() + "^ " + dec_min.toString() + "'" // + dec_sec.toString() + "\"" + " distance = " + dd.toString() + " AU"; } } class XYCoord { double x, y; public String toString() { return "(" + new Double(x).toString() + ", " + new Double(y).toString() + ")"; } }