Changeset 13632 in josm for trunk/src/org


Ignore:
Timestamp:
2018-04-15T14:46:01+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16129 - add spherical versions of Cassini and Albers projections

Location:
trunk/src/org/openstreetmap/josm/data/projection/proj
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/proj/AlbersEqualArea.java

    r12013 r13632  
    6464     * Constants used by the spherical and elliptical Albers projection.
    6565     */
    66     private double n, c, rho0;
     66    private double n, n2, c, rho0;
    6767
    6868    /**
     
    116116        ec = 1.0 - .5 * (1.0-e2) *
    117117             Math.log((1.0 - e) / (1.0 + e)) / e;
     118        n2 = n * n;
    118119        this.n = n;
    119120    }
     
    121122    @Override
    122123    public double[] project(double y, double x) {
    123         x *= n;
    124         double rho = c - n * qsfn(Math.sin(y));
     124        double theta = n * x;
     125        double rho = c - (spherical ? n2 * Math.sin(y) : n * qsfn(Math.sin(y)));
    125126        if (rho < 0.0) {
    126127            if (rho > -EPSILON) {
     
    132133        rho = Math.sqrt(rho) / n;
    133134        // CHECKSTYLE.OFF: SingleSpaceSeparator
    134         y = rho0 - rho * Math.cos(x);
    135         x =        rho * Math.sin(x);
     135        y = rho0 - rho * Math.cos(theta);
     136        x =        rho * Math.sin(theta);
    136137        // CHECKSTYLE.ON: SingleSpaceSeparator
    137138        return new double[] {x, y};
     
    150151            x = Math.atan2(x, y) / n;
    151152            y = rho * n;
    152             y = (c - y*y) / n;
    153             if (Math.abs(y) <= ec) {
    154                 y = phi1(y);
     153            if (spherical) {
     154                y = aasin((c - y*y) / n2);
    155155            } else {
    156                 y = (y < 0.0) ? -Math.PI/2.0 : Math.PI/2.0;
     156                y = (c - y*y) / n;
     157                if (Math.abs(y) <= ec) {
     158                    y = phi1(y);
     159                } else {
     160                    y = (y < 0.0) ? -Math.PI/2.0 : Math.PI/2.0;
     161                }
    157162            }
    158163        } else {
  • trunk/src/org/openstreetmap/josm/data/projection/proj/CassiniSoldner.java

    r12013 r13632  
    3333
    3434    /**
    35      * Contants used for the forward and inverse transform for the eliptical
     35     * Latitude of origin.
     36     */
     37    private double phi0;
     38
     39    /**
     40     * Constants used for the forward and inverse transform for the elliptical
    3641     * case of the Cassini-Soldner.
    3742     */
     
    5762        if (params.lat0 == null)
    5863            throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
    59         double latitudeOfOrigin = Utils.toRadians(params.lat0);
    60         ml0 = mlfn(latitudeOfOrigin, Math.sin(latitudeOfOrigin), Math.cos(latitudeOfOrigin));
     64        phi0 = Utils.toRadians(params.lat0);
     65        ml0 = mlfn(phi0, Math.sin(phi0), Math.cos(phi0));
    6166    }
    6267
    6368    @Override
    6469    public double[] project(double phi, double lam) {
    65         double sinphi = Math.sin(phi);
    66         double cosphi = Math.cos(phi);
     70        if (spherical) {
     71            double x = aasin(Math.cos(phi) * Math.sin(lam));
     72            double y = Math.atan2(Math.tan(phi), Math.cos(lam));
     73            return new double[] {x, y};
     74        } else {
     75            double sinphi = Math.sin(phi);
     76            double cosphi = Math.cos(phi);
    6777
    68         double n = 1.0 / (Math.sqrt(1.0 - e2 * sinphi * sinphi));
    69         double tn = Math.tan(phi);
    70         double t = tn * tn;
    71         double a1 = lam * cosphi;
    72         double c = cosphi * cosphi * e2 / (1 - e2);
    73         double a2 = a1 * a1;
     78            double n = 1.0 / (Math.sqrt(1.0 - e2 * sinphi * sinphi));
     79            double tn = Math.tan(phi);
     80            double t = tn * tn;
     81            double a1 = lam * cosphi;
     82            double c = cosphi * cosphi * e2 / (1 - e2);
     83            double a2 = a1 * a1;
    7484
    75         double x = n * a1 * (1.0 - a2 * t * (C1 - (8.0 - t + 8.0 * c) * a2 * C2));
    76         double y = mlfn(phi, sinphi, cosphi) - ml0 + n * tn * a2 * (0.5 + (5.0 - t + 6.0 * c) * a2 * C3);
    77         return new double[] {x, y};
     85            double x = n * a1 * (1.0 - a2 * t * (C1 - (8.0 - t + 8.0 * c) * a2 * C2));
     86            double y = mlfn(phi, sinphi, cosphi) - ml0 + n * tn * a2 * (0.5 + (5.0 - t + 6.0 * c) * a2 * C3);
     87            return new double[] {x, y};
     88        }
    7889    }
    7990
    8091    @Override
    8192    public double[] invproject(double x, double y) {
    82         double ph1 = invMlfn(ml0 + y);
    83         double tn = Math.tan(ph1);
    84         double t = tn * tn;
    85         double n = Math.sin(ph1);
    86         double r = 1.0 / (1.0 - e2 * n * n);
    87         n = Math.sqrt(r);
    88         r *= (1.0 - e2) * n;
    89         double dd = x / n;
    90         double d2 = dd * dd;
    91         double phi = ph1 - (n * tn / r) * d2 * (0.5 - (1.0 + 3.0 * t) * d2 * C3);
    92         double lam = dd * (1.0 + t * d2 * (-C4 + (1.0 + 3.0 * t) * d2 * C5)) / Math.cos(ph1);
    93         return new double[] {phi, lam};
     93        if (spherical) {
     94            double dd = y + phi0;
     95            double phi = aasin(Math.sin(dd * Math.cos(x)));
     96            double lam = Math.atan2(Math.tan(x), Math.cos(dd));
     97            return new double[] {phi, lam};
     98        } else {
     99            double ph1 = invMlfn(ml0 + y);
     100            double tn = Math.tan(ph1);
     101            double t = tn * tn;
     102            double n = Math.sin(ph1);
     103            double r = 1.0 / (1.0 - e2 * n * n);
     104            n = Math.sqrt(r);
     105            r *= (1.0 - e2) * n;
     106            double dd = x / n;
     107            double d2 = dd * dd;
     108            double phi = ph1 - (n * tn / r) * d2 * (0.5 - (1.0 + 3.0 * t) * d2 * C3);
     109            double lam = dd * (1.0 + t * d2 * (-C4 + (1.0 + 3.0 * t) * d2 * C5)) / Math.cos(ph1);
     110            return new double[] {phi, lam};
     111        }
    94112    }
    95113
Note: See TracChangeset for help on using the changeset viewer.