/** * Computes altitude and azimuth from latitude, hour angle and declination. * Glen Cowan, RHUL Physics * 16 October, 2003 */ import java.io.*; public class CoordCalc{ public static void main (String[] args) throws IOException { // Get phi, delta and h from console and convert from degrees to radians BufferedReader b = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter latitude phi (degrees): "); double phi = Double.parseDouble ( b.readLine() ) * Math.PI / 180 ; System.out.println("Enter declination delta (degrees): "); double delta = Double.parseDouble ( b.readLine() ) * Math.PI / 180 ; System.out.println("Enter hour angle h (degrees): "); double h = Double.parseDouble ( b.readLine() ) * Math.PI / 180 ; // Compute altitude double alt = Math.asin ( Math.cos(delta) * Math.cos(h) * Math.cos(phi) + Math.sin(delta) * Math.sin(phi) ); // Now get sine and cosine of azimuth and use atan2 to figure out quadrant double sinAz = - Math.cos(delta) * Math.sin(h) / Math.cos(alt) ; double cosAz = ( - Math.cos(delta) * Math.cos(h) * Math.sin(phi) + Math.sin(delta) * Math.cos(phi) ) / Math.cos(alt) ; double Az = Math.atan2(sinAz, cosAz); // Convert to degrees and output to screen System.out.println("altitude = " + alt*180/Math.PI + " degrees"); System.out.println("Azimuth = " + Az*180/Math.PI + " degrees"); } }