~ubuntu-branches/ubuntu/vivid/proj/vivid

« back to all changes in this revision

Viewing changes to src/PJ_poly.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter S Galbraith
  • Date: 2002-01-11 10:27:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020111102712-ayi18r8y2eesv0y9
Tags: upstream-4.4.5
ImportĀ upstreamĀ versionĀ 4.4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef lint
 
2
static const char SCCSID[]="@(#)PJ_poly.c       4.1     94/02/15        GIE     REL";
 
3
#endif
 
4
#define PROJ_PARMS__ \
 
5
        double ml0; \
 
6
        double *en;
 
7
#define PJ_LIB__
 
8
#include <projects.h>
 
9
PROJ_HEAD(poly, "Polyconic (American)")
 
10
        "\n\tConic, Sph&Ell";
 
11
#define TOL     1e-10
 
12
#define CONV    1e-10
 
13
#define N_ITER  10
 
14
#define I_ITER 20
 
15
#define ITOL 1.e-12
 
16
FORWARD(e_forward); /* ellipsoid */
 
17
        double  ms, sp, cp;
 
18
 
 
19
        if (fabs(lp.phi) <= TOL) { xy.x = lp.lam; xy.y = -P->ml0; }
 
20
        else {
 
21
                sp = sin(lp.phi);
 
22
                ms = fabs(cp = cos(lp.phi)) > TOL ? pj_msfn(sp, cp, P->es) / sp : 0.;
 
23
                xy.x = ms * sin(lp.lam *= sp);
 
24
                xy.y = (pj_mlfn(lp.phi, sp, cp, P->en) - P->ml0) + ms * (1. - cos(lp.lam));
 
25
        }
 
26
        return (xy);
 
27
}
 
28
FORWARD(s_forward); /* spheroid */
 
29
        double  cot, E;
 
30
 
 
31
        if (fabs(lp.phi) <= TOL) { xy.x = lp.lam; xy.y = P->ml0; }
 
32
        else {
 
33
                cot = 1. / tan(lp.phi);
 
34
                xy.x = sin(E = lp.lam * sin(lp.phi)) * cot;
 
35
                xy.y = lp.phi - P->phi0 + cot * (1. - cos(E));
 
36
        }
 
37
        return (xy);
 
38
}
 
39
INVERSE(e_inverse); /* ellipsoid */
 
40
        xy.y += P->ml0;
 
41
        if (fabs(xy.y) <= TOL) { lp.lam = xy.x; lp.phi = 0.; }
 
42
        else {
 
43
                double r, c, sp, cp, s2ph, ml, mlb, mlp, dPhi;
 
44
                int i;
 
45
 
 
46
                r = xy.y * xy.y + xy.x * xy.x;
 
47
                for (lp.phi = xy.y, i = I_ITER; i ; --i) {
 
48
                        sp = sin(lp.phi);
 
49
                        s2ph = sp * ( cp = cos(lp.phi));
 
50
                        if (fabs(cp) < ITOL)
 
51
                                I_ERROR;
 
52
                        c = sp * (mlp = sqrt(1. - P->es * sp * sp)) / cp;
 
53
                        ml = pj_mlfn(lp.phi, sp, cp, P->en);
 
54
                        mlb = ml * ml + r;
 
55
                        mlp = P->one_es / (mlp * mlp * mlp);
 
56
                        lp.phi += ( dPhi =
 
57
                                ( ml + ml + c * mlb - 2. * xy.y * (c * ml + 1.) ) / (
 
58
                                P->es * s2ph * (mlb - 2. * xy.y * ml) / c +
 
59
                                2.* (xy.y - ml) * (c * mlp - 1. / s2ph) - mlp - mlp ));
 
60
                        if (fabs(dPhi) <= ITOL)
 
61
                                break;
 
62
                }
 
63
                if (!i)
 
64
                        I_ERROR;
 
65
                c = sin(lp.phi);
 
66
                lp.lam = asin(xy.x * tan(lp.phi) * sqrt(1. - P->es * c * c)) / sin(lp.phi);
 
67
        }
 
68
        return (lp);
 
69
}
 
70
INVERSE(s_inverse); /* spheroid */
 
71
        double B, dphi, tp;
 
72
        int i;
 
73
 
 
74
        if (fabs(xy.y = P->phi0 + xy.y) <= TOL) { lp.lam = xy.x; lp.phi = 0.; }
 
75
        else {
 
76
                lp.phi = xy.y;
 
77
                B = xy.x * xy.x + xy.y * xy.y;
 
78
                i = N_ITER;
 
79
                do {
 
80
                        tp = tan(lp.phi);
 
81
                        lp.phi -= (dphi = (xy.y * (lp.phi * tp + 1.) - lp.phi -
 
82
                                .5 * ( lp.phi * lp.phi + B) * tp) /
 
83
                                ((lp.phi - xy.y) / tp - 1.));
 
84
                } while (fabs(dphi) > CONV && --i);
 
85
                if (! i) I_ERROR;
 
86
                lp.lam = asin(xy.x * tan(lp.phi)) / sin(lp.phi);
 
87
        }
 
88
        return (lp);
 
89
}
 
90
FREEUP; if (P) { if (P->en) pj_dalloc(P->en); pj_dalloc(P); } }
 
91
ENTRY1(poly, en)
 
92
        if (P->es) {
 
93
                if (!(P->en = pj_enfn(P->es))) E_ERROR_0;
 
94
                P->ml0 = pj_mlfn(P->phi0, sin(P->phi0), cos(P->phi0), P->en);
 
95
                P->inv = e_inverse;
 
96
                P->fwd = e_forward;
 
97
        } else {
 
98
                P->ml0 = -P->phi0;
 
99
                P->inv = s_inverse;
 
100
                P->fwd = s_forward;
 
101
        }
 
102
ENDENTRY(P)