示例#1
0
 @BeforeClass
 public static void setUp() {
   /* Example provided by https://de.wikipedia.org/wiki/Orthodrome, released 07.09.2015 19:55 */
   berlinSpheric = SphericCoordinate.getCoordinate(52.517, 13.4);
   tokioSpheric = SphericCoordinate.getCoordinate(35.7, 139.767);
   berlinCartesian = CartesianCoordinate.getCoordinate(3771.373, 898.468, 5055.605);
   tokioCartesian = CartesianCoordinate.getCoordinate(-3949.792, 3341.734, 3717.741);
   berlinSphericSameHashCode =
       SphericCoordinate.getCoordinate(
           ((AbstractCoordinate) berlinCartesian).getLatitude(),
           ((AbstractCoordinate) berlinCartesian).getLongitude(),
           ((AbstractCoordinate) berlinCartesian).getRadius());
   berlinSpheric2 = SphericCoordinate.getCoordinate(52.517, 13.4);
   berlinCartesian2 = CartesianCoordinate.getCoordinate(3771.373, 898.468, 5055.605);
 }
  /**
   * @methodtype conversion
   * @param Coordinate to convert
   * @return SphericCoordinate
   */
  private static SphericCoordinate convertToSpheric(Coordinate other) {
    if (SphericCoordinate.class.isInstance(other)) {
      return (SphericCoordinate) other;
    } else if (CartesianCoordinate.class.isInstance(other)) {
      CartesianCoordinate carOther = (CartesianCoordinate) other;

      double r =
          Math.sqrt(
              Math.pow(carOther.getX(), 2)
                  + Math.pow(carOther.getY(), 2)
                  + Math.pow(carOther.getZ(), 2));
      double latitude = Math.toDegrees(Math.asin(carOther.getZ() / r));
      double longitude = Math.toDegrees(Math.atan2(carOther.getY(), carOther.getX()));

      SphericCoordinate toRet = getSphericCoordinate(latitude, longitude, r);
      toRet.assertClassInvariants();
      return toRet;
    } else {
      throw new UnsupportedOperationException("Unknown Type of Coordinate");
    }
  }