Opened 4 years ago

Closed 4 years ago

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

Reported by: Owned by: Don-vip team normal 16.04 Core projection 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 +
// 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);
```

### comment:2 Changed 4 years ago by Don-vip

Resolution: → fixed new → closed

In 10033/josm:

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

### comment:3 Changed 4 years ago by Don-vip

Milestone: 16.03 → 16.04

Milestone renamed

### Modify Ticket

Change Properties