Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12632 closed defect (fixed)

Use an Ellipsoid constant instead of fixed value for R in LatLon and Selector classes

Reported by: Don-vip Owned by: team
Priority: normal Milestone: 16.04
Component: Core Version:
Keywords: projection Cc: wiktorn, bastiK, cmuelle8

Description

Code from data.osm.LatLon class:

    /**
     * Computes the distance between this lat/lon and another point on the earth.
     * Uses Haversine formular.
     * @param other the other point.
     * @return distance in metres.
     */
    public double greatCircleDistance(LatLon other) {
        double R = 6378135;
        double sinHalfLat = sin(toRadians(other.lat() - this.lat()) / 2);
        double sinHalfLon = sin(toRadians(other.lon() - this.lon()) / 2);
        double d = 2 * R * asin(
                sqrt(sinHalfLat*sinHalfLat +
                        cos(toRadians(this.lat()))*cos(toRadians(other.lat()))*sinHalfLon*sinHalfLon));
        // For points opposite to each other on the sphere,
        // rounding errors could make the argument of asin greater than 1
        // (This should almost never happen.)
        if (java.lang.Double.isNaN(d)) {
            Main.error("NaN in greatCircleDistance");
            d = PI * R;
        }
        return d;
    }

Code from gui.mappaint.mapcss.Selector class

        private static final double R = 6378135;

        public static double level2scale(int lvl) {
            if (lvl < 0)
                throw new IllegalArgumentException("lvl must be >= 0 but is "+lvl);
            // preliminary formula - map such that mapnik imagery tiles of the same
            // or similar level are displayed at the given scale
            return 2.0 * Math.PI * R / Math.pow(2.0, lvl) / 2.56;
        }

        public static int scale2level(double scale) {
            if (scale < 0)
                throw new IllegalArgumentException("scale must be >= 0 but is "+scale);
            return (int) Math.floor(Math.log(2 * Math.PI * R / 2.56 / scale) / Math.log(2));
        }

in both cases we use a constant R = 6378135.

In Ellipsoid, 6378135 is used for WGS72, shouldn't we use WGS84.a instead?

    /**
     * WGS72 ellipsoid
     */
    public static final Ellipsoid WGS72 = Ellipsoid.create_a_rf(6378135.0, 298.26);

    /**
     * WGS84 ellipsoid
     */
    public static final Ellipsoid WGS84 = Ellipsoid.create_a_rf(6378137.0, 298.257223563);

Attachments (0)

Change History (3)

comment:1 by bastiK, 9 years ago

Cc: cmuelle8 added

comment:2 by Don-vip, 9 years ago

Resolution: fixed
Status: newclosed

In 10033/josm:

fix #12632 - Use WGS84 Ellipsoid constant instead of fixed value for R

comment:3 by Don-vip, 9 years ago

Milestone: 16.0316.04

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.