1 package net.sf.openrocket.util;
4 * A WorldCoordinate contains the latitude, longitude and altitude position of a rocket.
6 public class WorldCoordinate {
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;
14 private final double lat, lon, alt;
17 * Constructs a new WorldCoordinate
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.
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));
31 * Returns the altitude.
33 public double getAltitude() {
38 * Returns Longitude in radians
40 public double getLongitudeRad() {
45 * Returns Longitude in degrees
47 public double getLongitudeDeg() {
48 return Math.toDegrees(this.lon);
52 * Returns latitude in radians
54 public double getLatitudeRad() {
59 * Returns latitude in degrees
61 public double getLatitudeDeg() {
62 return Math.toDegrees(this.lat);
68 public String toString() {
69 return "WorldCoordinate[lat=" + getLatitudeDeg() + ", lon=" + getLongitudeDeg() + ", alt=" + getAltitude() + "]";
75 public boolean equals(Object obj) {
76 if (!(obj instanceof WorldCoordinate)) {
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));
85 public int hashCode() {
86 return ((int) (1000 * (lat + lon + alt)));