summaryrefslogtreecommitdiff
path: root/src/3rdparty/proj/PJ_fouc_s.c
blob: dee05a96b6990e461b06a40f803eacc3a91b6099 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define PROJ_PARMS__ \
	double n, n1;
#define PJ_LIB__
#include	<projects.h>
PROJ_HEAD(fouc_s, "Foucaut Sinusoidal") "\n\tPCyl., Sph.";
#define MAX_ITER    10
#define LOOP_TOL    1e-7
FORWARD(s_forward); /* spheroid */
	double t;

	t = cos(lp.phi);
	xy.x = lp.lam * t / (P->n + P->n1 * t);
	xy.y = P->n * lp.phi + P->n1 * sin(lp.phi);
	return (xy);
}
INVERSE(s_inverse); /* spheroid */
	double V;
	int i;

	if (P->n) {
		lp.phi = xy.y;
		for (i = MAX_ITER; i ; --i) {
			lp.phi -= V = (P->n * lp.phi + P->n1 * sin(lp.phi) - xy.y ) /
				(P->n + P->n1 * cos(lp.phi));
			if (fabs(V) < LOOP_TOL)
				break;
		}
		if (!i)
			lp.phi = xy.y < 0. ? -HALFPI : HALFPI;
	} else
		lp.phi = aasin(xy.y);
	V = cos(lp.phi);
	lp.lam = xy.x * (P->n + P->n1 * V) / V;
	return (lp);
}
FREEUP; if (P) pj_dalloc(P); }
ENTRY0(fouc_s)
	P->n = pj_param(P->params, "dn").f;
	if (P->n < 0. || P->n > 1.)
		E_ERROR(-99)
	P->n1 = 1. - P->n;
	P->es = 0;
	P->inv = s_inverse;
	P->fwd = s_forward;
ENDENTRY(P)