2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.geom
;
9 import gov
.nasa
.worldwind
.*;
12 * Represents a point on the two-dimensional surface of a globe. Latitude is the degrees North and ranges between [-90,
13 * 90], while longitude refers to degrees East, and ranges between (-180, 180].
15 * Instances of <code>LatLon</code> are immutable.
18 * @version $Id: LatLon.java 1749 2007-05-06 19:48:14Z tgaskins $
22 private final Angle latitude
;
23 private final Angle longitude
;
26 * Factor method for obtaining a new <code>LatLon</code> from two angles expressed in radians.
28 * @param latitude in radians
29 * @param longitude in radians
30 * @return a new <code>LatLon</code> from the given angles, which are expressed as radians
32 public static LatLon
fromRadians(double latitude
, double longitude
)
34 return new LatLon(Math
.toDegrees(latitude
), Math
.toDegrees(longitude
));
38 * Factory method for obtaining a new <code>LatLon</code> from two angles expressed in degrees.
40 * @param latitude in degrees
41 * @param longitude in degrees
42 * @return a new <code>LatLon</code> from the given angles, which are expressed as degrees
44 public static LatLon
fromDegrees(double latitude
, double longitude
)
46 return new LatLon(latitude
, longitude
);
49 private LatLon(double latitude
, double longitude
)
51 this.latitude
= Angle
.fromDegrees(latitude
);
52 this.longitude
= Angle
.fromDegrees(longitude
);
56 * Contructs a new <code>LatLon</code> from two angles. Neither angle may be null.
60 * @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null
62 public LatLon(Angle latitude
, Angle longitude
)
64 if (latitude
== null || longitude
== null)
66 String message
= WorldWind
.retrieveErrMsg("nullValue.LatitudeOrLongitudeIsNull");
67 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
68 throw new IllegalArgumentException(message
);
71 this.latitude
= latitude
;
72 this.longitude
= longitude
;
76 * Obtains the latitude of this <code>LatLon</code>.
78 * @return this <code>LatLon</code>'s latitude
80 public final Angle
getLatitude()
86 * Obtains the longitude of this <code>LatLon</code>.
88 * @return this <code>LatLon</code>'s longitude
90 public final Angle
getLongitude()
92 return this.longitude
;
95 public static LatLon
interpolate(double t
, LatLon begin
, LatLon end
)
97 if (begin
== null || end
== null)
99 String message
= WorldWind
.retrieveErrMsg("nullValue.LatitudeOrLongitudeIsNull");
100 WorldWind
.logger().log(java
.util
.logging
.Level
.FINE
, message
);
101 throw new IllegalArgumentException(message
);
108 Quaternion beginQuat
= Quaternion
.EulerToQuaternion(begin
.getLongitude().getRadians(),
109 begin
.getLatitude().getRadians(), 0);
110 Quaternion endQuat
= Quaternion
.EulerToQuaternion(end
.getLongitude().getRadians(),
111 end
.getLatitude().getRadians(), 0);
112 Quaternion q
= Quaternion
.Slerp(beginQuat
, endQuat
, t
);
113 Point v
= Quaternion
.QuaternionToEuler(q
);
114 if (Double
.isNaN(v
.x()) || Double
.isNaN(v
.y()))
116 return LatLon
.fromRadians(v
.y(), v
.x());
120 public String
toString()
122 return "(" + this.latitude
.toString() + ", " + this.longitude
.toString() + ")";
126 public boolean equals(Object o
)
130 if (o
== null || getClass() != o
.getClass())
133 final gov
.nasa
.worldwind
.geom
.LatLon latLon
= (gov
.nasa
.worldwind
.geom
.LatLon
) o
;
135 if (!latitude
.equals(latLon
.latitude
))
137 //noinspection RedundantIfStatement
138 if (!longitude
.equals(latLon
.longitude
))
145 public int hashCode()
148 result
= latitude
.hashCode();
149 result
= 29 * result
+ longitude
.hashCode();