altosuilib: Get rid of AltosUIVersion.java
[fw/altos] / altoslib / AltosGreatCircle.java
index 76b71859394800c2e0f169f25c4940c8f8660dd3..f64a3662da896ce5df933f7bf9f4701e7aeb1774 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.AltosLib;
+package org.altusmetrum.altoslib_7;
 
 import java.lang.Math;
+import java.io.*;
 
-public class AltosGreatCircle {
+public class AltosGreatCircle implements Cloneable, Serializable {
        public double   distance;
        public double   bearing;
+       public double   range;
+       public double   elevation;
 
        double sqr(double a) { return a * a; }
 
        static final double rad = Math.PI / 180;
        static final double earth_radius = 6371.2 * 1000;       /* in meters */
 
-       public static final int BEARING_LONG = 0;
-       public static final int BEARING_SHORT = 1;
-       public static final int BEARING_VOICE = 2;
+       public static final int BEARING_LONG = AltosConvert.BEARING_LONG;
+       public static final int BEARING_SHORT = AltosConvert.BEARING_SHORT;
+       public static final int BEARING_VOICE = AltosConvert.BEARING_VOICE;
 
        public String bearing_words(int length) {
-               String [][] bearing_string = {
-                       {
-                               "North", "North North East", "North East", "East North East",
-                               "East", "East South East", "South East", "South South East",
-                               "South", "South South West", "South West", "West South West",
-                               "West", "West North West", "North West", "North North West"
-                       }, {
-                               "N", "NNE", "NE", "ENE",
-                               "E", "ESE", "SE", "SSE",
-                               "S", "SSW", "SW", "WSW",
-                               "W", "WNW", "NW", "NNW"
-                       }, {
-                               "north", "nor nor east", "north east", "east nor east",
-                               "east", "east sow east", "south east", "sow sow east",
-                               "south", "sow sow west", "south west", "west sow west",
-                               "west", "west nor west", "north west", "nor nor west "
-                       }
-               };
-               return bearing_string[length][(int)((bearing / 90 * 8 + 1) / 2)%16];
+               return AltosConvert.bearing_to_words(length, bearing);
        }
 
-       public AltosGreatCircle (double start_lat, double start_lon,
-                                double end_lat, double end_lon)
-       {
+       public AltosGreatCircle (double start_lat, double start_lon, double start_alt,
+                                double end_lat, double end_lon, double end_alt) {
                double lat1 = rad * start_lat;
                double lon1 = rad * -start_lon;
                double lat2 = rad * end_lat;
@@ -88,14 +72,35 @@ public class AltosGreatCircle {
                }
                distance = d * earth_radius;
                bearing = course * 180/Math.PI;
+
+               double height_diff = end_alt - start_alt;
+               range = Math.sqrt(distance * distance + height_diff * height_diff);
+               elevation = Math.atan2(height_diff, distance) * 180 / Math.PI;
+       }
+
+       public AltosGreatCircle clone() {
+               AltosGreatCircle n = new AltosGreatCircle();
+
+               n.distance = distance;
+               n.bearing = bearing;
+               n.range = range;
+               n.elevation = elevation;
+               return n;
+       }
+
+       public AltosGreatCircle (double start_lat, double start_lon,
+                                double end_lat, double end_lon) {
+               this(start_lat, start_lon, 0, end_lat, end_lon, 0);
        }
 
        public AltosGreatCircle(AltosGPS start, AltosGPS end) {
-               this(start.lat, start.lon, end.lat, end.lon);
+               this(start.lat, start.lon, start.alt, end.lat, end.lon, end.alt);
        }
 
        public AltosGreatCircle() {
                distance = 0;
                bearing = 0;
+               range = 0;
+               elevation = 0;
        }
 }