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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.