Ignore:
Timestamp:
2016-02-14T15:12:10+01:00 (4 years ago)
Author:
bastiK
Message:

applied #12524 - heading calculation reversed longitudes (patch by kolesar)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r9558 r9796  
    327327
    328328    /**
    329      * Returns the heading, in radians, that you have to use to get from this lat/lon to another.
     329     * Returns the heading that you have to use to get from this lat/lon to another.
     330     *
     331     * Angle starts from north and increases counterclockwise (!), PI/2 means west.
     332     * You can get usual clockwise angle from {@link #bearing(LatLon)} method.
     333     * This method is kept as deprecated because it is called from many plugins.
    330334     *
    331335     * (I don't know the original source of this formula, but see
     
    333337     * for some hints how it is derived.)
    334338     *
     339     * @deprecated see bearing method
    335340     * @param other the "destination" position
    336      * @return heading in the range 0 <= hd < 2*PI
    337      */
     341     * @return heading in radians in the range 0 <= hd < 2*PI
     342     */
     343    @Deprecated
    338344    public double heading(LatLon other) {
    339345        double hd = atan2(sin(toRadians(this.lon() - other.lon())) * cos(toRadians(other.lat())),
     
    348354
    349355    /**
     356     * Returns bearing from this point to another.
     357     *
     358     * Angle starts from north and increases clockwise, PI/2 means east.
     359     * Old deprecated method {@link #heading(LatLon)} used unusual reverse angle.
     360     *
     361     * Please note that reverse bearing (from other point to this point) should NOT be
     362     * calculated from return value of this method, because great circle path
     363     * between the two points have different bearings at each position.
     364     *
     365     * To get bearing from another point to this point call other.bearing(this)
     366     *
     367     * @param other the "destination" position
     368     * @return heading in radians in the range 0 <= hd < 2*PI
     369     */
     370    public double bearing(LatLon other) {
     371        double lat1 = toRadians(this.lat());
     372        double lat2 = toRadians(other.lat());
     373        double dlon = toRadians(other.lon() - this.lon());
     374        double bearing = atan2(
     375            sin(dlon) * cos(lat2),
     376            cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon)
     377        );
     378        bearing %= 2 * PI;
     379        if (bearing < 0) {
     380            bearing += 2 * PI;
     381        }
     382        return bearing;
     383    }
     384
     385    /**
    350386     * Returns this lat/lon pair in human-readable format.
    351387     *
Note: See TracChangeset for help on using the changeset viewer.