PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Proj4/PJ_moll.c

http://github.com/route-me/route-me
C | 65 lines | 62 code | 3 blank | 0 comment | 4 complexity | 3cdb293f3337fc05a14df961772e40b8 MD5 | raw file
 1#ifndef lint
 2static const char SCCSID[]="@(#)PJ_moll.c	4.1	94/02/15	GIE	REL";
 3#endif
 4#define PROJ_PARMS__ \
 5	double	C_x, C_y, C_p;
 6#define PJ_LIB__
 7#include	"projects.h"
 8PROJ_HEAD(moll, "Mollweide") "\n\tPCyl., Sph.";
 9PROJ_HEAD(wag4, "Wagner IV") "\n\tPCyl., Sph.";
10PROJ_HEAD(wag5, "Wagner V") "\n\tPCyl., Sph.";
11#define MAX_ITER	10
12#define LOOP_TOL	1e-7
13FORWARD(s_forward); /* spheroid */
14	double k, V;
15	int i;
16
17	k = P->C_p * sin(lp.phi);
18	for (i = MAX_ITER; i ; --i) {
19		lp.phi -= V = (lp.phi + sin(lp.phi) - k) /
20			(1. + cos(lp.phi));
21		if (fabs(V) < LOOP_TOL)
22			break;
23	}
24	if (!i)
25		lp.phi = (lp.phi < 0.) ? -HALFPI : HALFPI;
26	else
27		lp.phi *= 0.5;
28	xy.x = P->C_x * lp.lam * cos(lp.phi);
29	xy.y = P->C_y * sin(lp.phi);
30	return (xy);
31}
32INVERSE(s_inverse); /* spheroid */
33	double th, s;
34
35	lp.phi = aasin(xy.y / P->C_y);
36	lp.lam = xy.x / (P->C_x * cos(lp.phi));
37	lp.phi += lp.phi;
38	lp.phi = aasin((lp.phi + sin(lp.phi)) / P->C_p);
39	return (lp);
40}
41FREEUP; if (P) pj_dalloc(P); }
42	static PJ *
43setup(PJ *P, double p) {
44	double r, sp, p2 = p + p;
45
46	P->es = 0;
47	sp = sin(p);
48	r = sqrt(TWOPI * sp / (p2 + sin(p2)));
49	P->C_x = 2. * r / PI;
50	P->C_y = r / sp;
51	P->C_p = p2 + sin(p2);
52	P->inv = s_inverse;
53	P->fwd = s_forward;
54	return P;
55}
56ENTRY0(moll) ENDENTRY(setup(P, HALFPI))
57ENTRY0(wag4) ENDENTRY(setup(P, PI/3.))
58ENTRY0(wag5)
59	P->es = 0;
60	P->C_x = 0.90977;
61	P->C_y = 1.65014;
62	P->C_p = 3.00896;
63	P->inv = s_inverse;
64	P->fwd = s_forward;
65ENDENTRY(P)