# Changeset 3473 in josm

Ignore:
Timestamp:
2010-08-26T23:56:47+02:00 (11 years ago)
Message:

see #5327 (patch by sbrunner) - Swissgrild uses approximate formulas => better use exact formulas

Location:
trunk
Files:
4 edited

Unmodified
Removed
• ## trunk/src/org/openstreetmap/josm/data/projection/Ellipsoid.java

 r3083 package org.openstreetmap.josm.data.projection; import org.openstreetmap.josm.data.coor.LatLon; /** * the reference ellipsoids */ public static final Ellipsoid WGS84 = new Ellipsoid(6378137.0, 6356752.3142); /** * Bessel 1841 ellipsoid */ public static final Ellipsoid Bessel1841 = new Ellipsoid(6377397.155, 6356078.962822); /** return lati1; } /** * convert cartesian coordinates to ellipsoidal coordinates * * @param XYZ the coordinates in meters (X, Y, Z) * @return The corresponding latitude and longitude in degrees */ public LatLon cart2LatLon(double[] XYZ) { return cart2LatLon(XYZ, 1e-11); } public LatLon cart2LatLon(double[] XYZ, double epsilon) { double norm = Math.sqrt(XYZ[0] * XYZ[0] + XYZ[1] * XYZ[1]); double lg = 2.0 * Math.atan(XYZ[1] / (XYZ[0] + norm)); double lt = Math.atan(XYZ[2] / (norm * (1.0 - (a * e2 / Math.sqrt(XYZ[0] * XYZ[0] + XYZ[1] * XYZ[1] + XYZ[2] * XYZ[2]))))); double delta = 1.0; while (delta > epsilon) { double s2 = Math.sin(lt); s2 *= s2; double l = Math.atan((XYZ[2] / norm) / (1.0 - (a * e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - e2 * s2))))); delta = Math.abs(l - lt); lt = l; } return new LatLon(Math.toDegrees(lt), Math.toDegrees(lg)); } /** * convert ellipsoidal coordinates to cartesian coordinates * * @param coord The Latitude and longitude in degrees * @return the corresponding (X, Y Z) cartesian coordinates in meters. */ public double[] latLon2Cart(LatLon coord) { double phi = Math.toRadians(coord.lat()); double lambda = Math.toRadians(coord.lon()); double Rn = a / Math.sqrt(1 - e2 * Math.pow(Math.sin(phi), 2)); double[] XYZ = new double[3]; XYZ[0] = Rn * Math.cos(phi) * Math.cos(lambda); XYZ[1] = Rn * Math.cos(phi) * Math.sin(lambda); XYZ[2] = Rn * (1 - e2) * Math.sin(phi); return XYZ; } }