create changelog entry
[debian/openrocket] / core / 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          * 
19          * @param lat latitude in degrees north. From -90 to 90, values outside are clamped.
20          * @param lon longitude in degrees east. From -180 to 180, values outside are reduced to the range.
21          * @param alt altitude in meters. Unbounded.
22          */
23         public WorldCoordinate(double lat, double lon, double alt) {
24                 this.lat = MathUtil.clamp(Math.toRadians(lat), -Math.PI / 2, Math.PI / 2);
25                 this.lon = MathUtil.reduce180(Math.toRadians(lon));
26                 this.alt = alt;
27         }
28         
29         
30         /**
31          * Returns the altitude.
32          */
33         public double getAltitude() {
34                 return this.alt;
35         }
36         
37         /**
38          * Returns Longitude in radians
39          */
40         public double getLongitudeRad() {
41                 return this.lon;
42         }
43         
44         /**
45          * Returns Longitude in degrees
46          */
47         public double getLongitudeDeg() {
48                 return Math.toDegrees(this.lon);
49         }
50         
51         /**
52          * Returns latitude in radians
53          */
54         public double getLatitudeRad() {
55                 return this.lat;
56         }
57         
58         /**
59          * Returns latitude in degrees
60          */
61         public double getLatitudeDeg() {
62                 return Math.toDegrees(this.lat);
63         }
64         
65         
66
67         @Override
68         public String toString() {
69                 return "WorldCoordinate[lat=" + getLatitudeDeg() + ", lon=" + getLongitudeDeg() + ", alt=" + getAltitude() + "]";
70         }
71         
72         
73
74         @Override
75         public boolean equals(Object obj) {
76                 if (!(obj instanceof WorldCoordinate)) {
77                         return false;
78                 }
79                 WorldCoordinate other = (WorldCoordinate) obj;
80                 return (MathUtil.equals(this.lat, other.lat) &&
81                                 MathUtil.equals(this.lon, other.lon) && MathUtil.equals(this.alt, other.alt));
82         }
83         
84         @Override
85         public int hashCode() {
86                 return ((int) (1000 * (lat + lon + alt)));
87         }
88         
89 }