class mytest {
public static class Satfind {
final double toDeg = 180.0/Math.PI;
final double toRad = Math.PI/180.0;
/*
*
* ComputePos(input: (earth) lat (deg), lng (deg),
* (satellite) satlng (deg),
*
* output: Complex(x = az true (deg), y = el (deg))
*
* az format: North = 0, East = 90, South = 180, West = 270
* el format: Horizontal 0, Vertical 90
*
*/
private Complex computePos(double lat, double lng, double satLng) {
double dlngr = (lng-satLng) * toRad;
double az = Math.atan2(Math.sin(lat * toRad),Math.tan(dlngr)) * toDeg;
az = (270.0 - az) / 360.0;
az = az - Math.floor(az);
az *= 360.0;
double r1=6.6107; // ratio synchronous orbit/earth radius
double clng = Math.cos(dlngr);
double clat = Math.cos(lat * toRad);
double v1=r1*clat*clng-1.0;
double v2=r1*Math.sqrt(1-clat*clat*clng*clng);
double el = Math.atan2(v1,v2) * toDeg;
return new Complex(az,el);
}
/*
*
* ComputeSkew(input: (earth) lat (deg), lng (deg),
* (satellite) satlng (deg),
*
* output: double skew (deg)
*
*/
private double computeSkew(double lat, double lng, double satLng) {
double dlngr = (satLng-lng) * toRad;
return (Math.atan2(Math.tan(lat * toRad),Math.sin(dlngr)) * toDeg) - 90.0;
}
}
// The rather simple "Complex" class:
public static class Complex {
private double x;
private double y;
public Complex(double x,double y) {
this.x = x;
this.y = y;
}
public double x() {
return x;
}
public double y() {
return y;
}
}
public static void main(String args[]) {
double earthlat=0.0,earthlng=0.0,satlng=0.0;
Satfind sf = new Satfind();
Complex pos = null;
double skew;
if (args.length !=3)
{
System.out.println("Input Required: earthlat, earthlong, satlat");
System.out.println("Remember that southern latitudes and western longitudes should be negative numbers");
System.exit(1); }
try {
earthlat=Double.parseDouble(args[0]);
earthlng=Double.parseDouble(args[1]);
satlng=Double.parseDouble(args[2]);
}
catch (Exception e) {
System.out.println("Error in input: "+e);
}
pos = sf.computePos(earthlat,earthlng,satlng);
skew= sf.computeSkew(earthlat,earthlng,satlng);
System.out.println("Az: "+pos.x+" El: "+pos.y+" Skew: "+skew);
}
}