PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/Proj4/PJ_gn_sinu.c

http://github.com/route-me/route-me
C | 103 lines | 97 code | 4 blank | 2 comment | 18 complexity | d256ab339699281799f1be84cd4296db MD5 | raw file
  1#ifndef lint
  2static const char SCCSID[]="@(#)PJ_gn_sinu.c	4.1	94/02/15	GIE	REL";
  3#endif
  4#define PROJ_PARMS__ \
  5	double	*en; \
  6	double	m, n, C_x, C_y;
  7#define PJ_LIB__
  8#include	"projects.h"
  9PROJ_HEAD(gn_sinu, "General Sinusoidal Series") "\n\tPCyl, Sph.\n\tm= n=";
 10PROJ_HEAD(sinu, "Sinusoidal (Sanson-Flamsteed)") "\n\tPCyl, Sph&Ell";
 11PROJ_HEAD(eck6, "Eckert VI") "\n\tPCyl, Sph.";
 12PROJ_HEAD(mbtfps, "McBryde-Thomas Flat-Polar Sinusoidal") "\n\tPCyl, Sph.";
 13#define EPS10	1e-10
 14#define MAX_ITER 8
 15#define LOOP_TOL 1e-7
 16/* Ellipsoidal Sinusoidal only */
 17FORWARD(e_forward); /* ellipsoid */
 18	double s, c;
 19
 20	xy.y = pj_mlfn(lp.phi, s = sin(lp.phi), c = cos(lp.phi), P->en);
 21	xy.x = lp.lam * c / sqrt(1. - P->es * s * s);
 22	return (xy);
 23}
 24INVERSE(e_inverse); /* ellipsoid */
 25	double s;
 26
 27	if ((s = fabs(lp.phi = pj_inv_mlfn(xy.y, P->es, P->en))) < HALFPI) {
 28		s = sin(lp.phi);
 29		lp.lam = xy.x * sqrt(1. - P->es * s * s) / cos(lp.phi);
 30	} else if ((s - EPS10) < HALFPI)
 31		lp.lam = 0.;
 32	else I_ERROR;
 33	return (lp);
 34}
 35/* General spherical sinusoidals */
 36FORWARD(s_forward); /* sphere */
 37	if (!P->m)
 38		lp.phi = P->n != 1. ? aasin(P->n * sin(lp.phi)): lp.phi;
 39	else {
 40		double k, V;
 41		int i;
 42
 43		k = P->n * sin(lp.phi);
 44		for (i = MAX_ITER; i ; --i) {
 45			lp.phi -= V = (P->m * lp.phi + sin(lp.phi) - k) /
 46				(P->m + cos(lp.phi));
 47			if (fabs(V) < LOOP_TOL)
 48				break;
 49		}
 50		if (!i)
 51			F_ERROR
 52	}
 53	xy.x = P->C_x * lp.lam * (P->m + cos(lp.phi));
 54	xy.y = P->C_y * lp.phi;
 55	return (xy);
 56}
 57INVERSE(s_inverse); /* sphere */
 58	double s;
 59
 60	xy.y /= P->C_y;
 61	lp.phi = P->m ? aasin((P->m * xy.y + sin(xy.y)) / P->n) :
 62		( P->n != 1. ? aasin(sin(xy.y) / P->n) : xy.y );
 63	lp.lam = xy.x / (P->C_x * (P->m + cos(xy.y)));
 64	return (lp);
 65}
 66FREEUP; if (P) { if (P->en) pj_dalloc(P->en); pj_dalloc(P); } }
 67	static void /* for spheres, only */
 68setup(PJ *P) {
 69	P->es = 0;
 70	P->C_x = (P->C_y = sqrt((P->m + 1.) / P->n))/(P->m + 1.);
 71	P->inv = s_inverse;
 72	P->fwd = s_forward;
 73}
 74ENTRY1(sinu, en)
 75	if (!(P->en = pj_enfn(P->es)))
 76		E_ERROR_0;
 77	if (P->es) {
 78		P->inv = e_inverse;
 79		P->fwd = e_forward;
 80	} else {
 81		P->n = 1.;
 82		P->m = 0.;
 83		setup(P);
 84	}
 85ENDENTRY(P)
 86ENTRY1(eck6, en)
 87	P->m = 1.;
 88	P->n = 2.570796326794896619231321691;
 89	setup(P);
 90ENDENTRY(P)
 91ENTRY1(mbtfps, en)
 92	P->m = 0.5;
 93	P->n = 1.785398163397448309615660845;
 94	setup(P);
 95ENDENTRY(P)
 96ENTRY1(gn_sinu, en)
 97	if (pj_param(P->params, "tn").i && pj_param(P->params, "tm").i) {
 98		P->n = pj_param(P->params, "dn").f;
 99		P->m = pj_param(P->params, "dm").f;
100	} else
101		E_ERROR(-99)
102	setup(P);
103ENDENTRY(P)