world coordinate patch
[debian/openrocket] / src / net / sf / openrocket / util / WorldCoordinate.java
1 package net.sf.openrocket.util;
2
3 /**
4  * A WorldCoordinate contains the latitude, longitude and altitude position of a rocket.
5  */
6 public class WorldCoordinate {
7         
8         /** Mean Earth radius */
9         public static final double REARTH = 6371000.0;
10         /** Sidearial Earth rotation rate  */
11         public static final double EROT = 7.2921150e-5;
12         
13
14         private final double lat, lon, alt;
15         
16         /**
17          * Constructs a new WorldCoordinate
18          * @param lat latitude in degrees north. From -90 to 90, values outside are clamped.
19          * @param lon longitude in degrees east. From -180 to 180, values outside are reduced to the range.
20          * @param alt altitude in m. Unbounded.
21          */
22         public WorldCoordinate(double lat, double lon, double alt) {
23                 this.lat = MathUtil.clamp(Math.toRadians(lat), -Math.PI / 2, Math.PI / 2);
24                 this.lon = MathUtil.reduce180(Math.toRadians(lon));
25                 this.alt = alt;
26         }
27         
28         
29
30         public double getAltitude() {
31                 return this.alt;
32         }
33         
34         /*
35          * Returns Longitude in radians
36          */
37         public double getLongitudeRad() {
38                 return this.lon;
39         }
40         
41         /*
42          * Returns Longitude in degrees
43          */
44         public double getLongitudeDeg() {
45                 return Math.toDegrees(this.lon);
46         }
47         
48         /*
49          * Returns latitude in radians
50          */
51         public double getLatitudeRad() {
52                 return this.lat;
53         }
54         
55         /*
56          * Returns latitude in degrees
57          */
58         public double getLatitudeDeg() {
59                 return Math.toDegrees(this.lat);
60         }
61         
62         
63         @Override
64         public String toString() {
65                 return "WorldCoordinate[lat=" + lat + ", lon=" + lon + ", alt=" + alt + "]";
66         }
67         
68         
69
70         @Override
71         public boolean equals(Object obj) {
72                 if (!(obj instanceof WorldCoordinate)) {
73                         return false;
74                 }
75                 WorldCoordinate other = (WorldCoordinate) obj;
76                 return (MathUtil.equals(this.lat, other.lat) &&
77                                 MathUtil.equals(this.lon, other.lon) && MathUtil.equals(this.alt, other.alt));
78         }
79         
80         @Override
81         public int hashCode() {
82                 return ((int) (1000 * (lat + lon + alt)));
83         }
84         
85 }