PageRenderTime 49ms CodeModel.GetById 13ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

/Proj4/PJ_eqdc.c

http://github.com/route-me/route-me
C | 88 lines | 85 code | 3 blank | 0 comment | 13 complexity | bd8122eb944b6dd05bb9583a0fa45a1f MD5 | raw file
 1#ifndef lint
 2static const char SCCSID[]="@(#)PJ_eqdc.c	4.2	94/03/16	GIE	REL";
 3#endif
 4#define PROJ_PARMS__ \
 5	double phi1; \
 6	double phi2; \
 7	double n; \
 8	double rho; \
 9	double rho0; \
10	double c; \
11	double *en; \
12	int		ellips;
13#define PJ_LIB__
14#include	"projects.h"
15PROJ_HEAD(eqdc, "Equidistant Conic")
16	"\n\tConic, Sph&Ell\n\tlat_1= lat_2=";
17# define EPS10	1.e-10
18FORWARD(e_forward); /* sphere & ellipsoid */
19	P->rho = P->c - (P->ellips ? pj_mlfn(lp.phi, sin(lp.phi),
20		cos(lp.phi), P->en) : lp.phi);
21	xy.x = P->rho * sin( lp.lam *= P->n );
22	xy.y = P->rho0 - P->rho * cos(lp.lam);
23	return (xy);
24}
25INVERSE(e_inverse); /* sphere & ellipsoid */
26	if ((P->rho = hypot(xy.x, xy.y = P->rho0 - xy.y)) != 0.0 ) {
27		if (P->n < 0.) {
28			P->rho = -P->rho;
29			xy.x = -xy.x;
30			xy.y = -xy.y;
31		}
32		lp.phi = P->c - P->rho;
33		if (P->ellips)
34			lp.phi = pj_inv_mlfn(lp.phi, P->es, P->en);
35		lp.lam = atan2(xy.x, xy.y) / P->n;
36	} else {
37		lp.lam = 0.;
38		lp.phi = P->n > 0. ? HALFPI : - HALFPI;
39	}
40	return (lp);
41}
42SPECIAL(fac) {
43	double sinphi, cosphi;
44
45	sinphi = sin(lp.phi);
46	cosphi = cos(lp.phi);
47	fac->code |= IS_ANAL_HK;
48	fac->h = 1.;
49	fac->k = P->n * (P->c - (P->ellips ? pj_mlfn(lp.phi, sinphi,
50		cosphi, P->en) : lp.phi)) / pj_msfn(sinphi, cosphi, P->es);
51}
52FREEUP; if (P) { if (P->en) pj_dalloc(P->en); pj_dalloc(P); } }
53ENTRY1(eqdc, en)
54	double cosphi, sinphi;
55	int secant;
56
57	P->phi1 = pj_param(P->params, "rlat_1").f;
58	P->phi2 = pj_param(P->params, "rlat_2").f;
59	if (fabs(P->phi1 + P->phi2) < EPS10) E_ERROR(-21);
60	if (!(P->en = pj_enfn(P->es)))
61		E_ERROR_0;
62	P->n = sinphi = sin(P->phi1);
63	cosphi = cos(P->phi1);
64	secant = fabs(P->phi1 - P->phi2) >= EPS10;
65	if( (P->ellips = (P->es > 0.)) ) {
66		double ml1, m1;
67
68		m1 = pj_msfn(sinphi, cosphi, P->es);
69		ml1 = pj_mlfn(P->phi1, sinphi, cosphi, P->en);
70		if (secant) { /* secant cone */
71			sinphi = sin(P->phi2);
72			cosphi = cos(P->phi2);
73			P->n = (m1 - pj_msfn(sinphi, cosphi, P->es)) /
74				(pj_mlfn(P->phi2, sinphi, cosphi, P->en) - ml1);
75		}
76		P->c = ml1 + m1 / P->n;
77		P->rho0 = P->c - pj_mlfn(P->phi0, sin(P->phi0),
78			cos(P->phi0), P->en);
79	} else {
80		if (secant)
81			P->n = (cosphi - cos(P->phi2)) / (P->phi2 - P->phi1);
82		P->c = P->phi1 + cos(P->phi1) / P->n;
83		P->rho0 = P->c - P->phi0;
84	}
85	P->inv = e_inverse;
86	P->fwd = e_forward;
87	P->spc = fac;
88ENDENTRY(P)