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

/Proj4/PJ_tpeqd.c

http://github.com/route-me/route-me
C | 79 lines | 74 code | 3 blank | 2 comment | 7 complexity | aa81ed3445de429e01f6f85cf7a5f4f7 MD5 | raw file
 1#ifndef lint
 2static const char SCCSID[]="@(#)PJ_tpeqd.c	4.1	94/02/15	GIE	REL";
 3#endif
 4#define PROJ_PARMS__ \
 5	double cp1, sp1, cp2, sp2, ccs, cs, sc, r2z0, z02, dlam2; \
 6	double hz0, thz0, rhshz0, ca, sa, lp, lamc;
 7#define PJ_LIB__
 8#include	"projects.h"
 9PROJ_HEAD(tpeqd, "Two Point Equidistant")
10	"\n\tMisc Sph\n\tlat_1= lon_1= lat_2= lon_2=";
11FORWARD(s_forward); /* sphere */
12	double t, z1, z2, dl1, dl2, sp, cp;
13
14	sp = sin(lp.phi);
15	cp = cos(lp.phi);
16	z1 = aacos(P->sp1 * sp + P->cp1 * cp * cos(dl1 = lp.lam + P->dlam2));
17	z2 = aacos(P->sp2 * sp + P->cp2 * cp * cos(dl2 = lp.lam - P->dlam2));
18	z1 *= z1;
19	z2 *= z2;
20	xy.x = P->r2z0 * (t = z1 - z2);
21	t = P->z02 - t;
22	xy.y = P->r2z0 * asqrt(4. * P->z02 * z2 - t * t);
23	if ((P->ccs * sp - cp * (P->cs * sin(dl1) - P->sc * sin(dl2))) < 0.)
24		xy.y = -xy.y;
25	return xy;
26}
27INVERSE(s_inverse); /* sphere */
28	double cz1, cz2, s, d, cp, sp;
29
30	cz1 = cos(hypot(xy.y, xy.x + P->hz0));
31	cz2 = cos(hypot(xy.y, xy.x - P->hz0));
32	s = cz1 + cz2;
33	d = cz1 - cz2;
34	lp.lam = - atan2(d, (s * P->thz0));
35	lp.phi = aacos(hypot(P->thz0 * s, d) * P->rhshz0);
36	if ( xy.y < 0. )
37		lp.phi = - lp.phi;
38	/* lam--phi now in system relative to P1--P2 base equator */
39	sp = sin(lp.phi);
40	cp = cos(lp.phi);
41	lp.phi = aasin(P->sa * sp + P->ca * cp * (s = cos(lp.lam -= P->lp)));
42	lp.lam = atan2(cp * sin(lp.lam), P->sa * cp * s - P->ca * sp) + P->lamc;
43	return lp;
44}
45FREEUP; if (P) pj_dalloc(P); }
46ENTRY0(tpeqd)
47	double lam_1, lam_2, phi_1, phi_2, A12, pp;
48
49	/* get control point locations */
50	phi_1 = pj_param(P->params, "rlat_1").f;
51	lam_1 = pj_param(P->params, "rlon_1").f;
52	phi_2 = pj_param(P->params, "rlat_2").f;
53	lam_2 = pj_param(P->params, "rlon_2").f;
54	if (phi_1 == phi_2 && lam_1 == lam_2) E_ERROR(-25);
55	P->lam0 = adjlon(0.5 * (lam_1 + lam_2));
56	P->dlam2 = adjlon(lam_2 - lam_1);
57	P->cp1 = cos(phi_1);
58	P->cp2 = cos(phi_2);
59	P->sp1 = sin(phi_1);
60	P->sp2 = sin(phi_2);
61	P->cs = P->cp1 * P->sp2;
62	P->sc = P->sp1 * P->cp2;
63	P->ccs = P->cp1 * P->cp2 * sin(P->dlam2);
64	P->z02 = aacos(P->sp1 * P->sp2 + P->cp1 * P->cp2 * cos(P->dlam2));
65	P->hz0 = .5 * P->z02;
66	A12 = atan2(P->cp2 * sin(P->dlam2),
67		P->cp1 * P->sp2 - P->sp1 * P->cp2 * cos(P->dlam2));
68	P->ca = cos(pp = aasin(P->cp1 * sin(A12)));
69	P->sa = sin(pp);
70	P->lp = adjlon(atan2(P->cp1 * cos(A12), P->sp1) - P->hz0);
71	P->dlam2 *= .5;
72	P->lamc = HALFPI - atan2(sin(A12) * P->sp1, cos(A12)) - P->dlam2;
73	P->thz0 = tan(P->hz0);
74	P->rhshz0 = .5 / sin(P->hz0);
75	P->r2z0 = 0.5 / P->z02;
76	P->z02 *= P->z02;
77	P->inv = s_inverse; P->fwd = s_forward;
78	P->es = 0.;
79ENDENTRY(P)