/** * Computes the absolute distance to the other coordinate's latitude * * @methodtype get * @methodproperty regular */ public double getLatitudinalDistance(SphericCoordinate other) { if (other == null) { throw new IllegalArgumentException("Other coordinate must not be null"); } return Math.abs(other.getLatitude() - this.getLatitude()); }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof SphericCoordinate)) return false; SphericCoordinate otherCoordinate = (SphericCoordinate) obj; if (latitude == otherCoordinate.getLatitude() && longitude == otherCoordinate.getLongitude() && radius == otherCoordinate.getRadius()) return true; else return false; }
/** * @Pattern ( name = "Template" participants = { "AbstactCoordinate", "CartesianCoordinate", * "SphericCoordinate" } ) */ @Override protected double getRadialDistance(Coordinate other) { if (other == null) { throw new IllegalArgumentException("Other coordinate must not be null"); } SphericCoordinate sphOther = convertToSpheric(other); double radLatitude = Math.toRadians(this.getLatitude()); double otherRadLatitude = Math.toRadians(sphOther.getLatitude()); double lonDistance = Math.toRadians(this.getLongitudinalDistance(sphOther)); return (Math.acos( Math.sin(radLatitude) * Math.sin(otherRadLatitude) + Math.cos(radLatitude) * Math.cos(otherRadLatitude) * Math.cos(lonDistance))); }
/** * @param other the other Coordinate-Object * @return distance between the latitude-values of both coordinates as double-value * @methodtype query */ public double getLatitudinalDistance(SphericCoordinate secondCoordinate) { // preconditions assertNotNull(secondCoordinate); double latitudinalDistance = this.latitude - secondCoordinate.getLatitude(); latitudinalDistance = Math.abs(latitudinalDistance); // check for shortest way if (latitudinalDistance > 90) { latitudinalDistance = 180 - latitudinalDistance; } // postconditions assertIsValidDistance(latitudinalDistance); return latitudinalDistance; }
/** * Computes the absolute distance to the other coordinate's longitude * * @methodtype get * @methodproperty regular */ public double getLongitudinalDistance(SphericCoordinate other) { if (other == null) { throw new IllegalArgumentException("Other coordinate must not be null"); } double result; if (Math.signum(this.getLongitude()) != Math.signum(other.getLatitude())) { result = Math.abs(this.getLongitude()) + Math.abs(other.getLongitude()); if (result > 180.) { result = 360. - result; } } else { result = Math.abs(Math.abs(this.getLongitude()) - Math.abs(other.getLongitude())); } return result; }