xref: /plan9-contrib/sys/src/cmd/map/libmap/harrison.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include "map.h"
2 
3 static double v3,u2,u3,a,b; /*v=view,p=obj,u=unit.y*/
4 
5 static int
6 Xharrison(struct place *place, double *x, double *y)
7 {
8 	double p1 = -place->nlat.c*place->wlon.s;
9 	double p2 = -place->nlat.c*place->wlon.c;
10 	double p3 = place->nlat.s;
11 	double d = b + u3*p2 - u2*p3;
12 	double t;
13 	if(d < .01)
14 		return -1;
15 	t = a/d;
16 	if(v3*place->nlat.s < 1.)
17 		return -1;
18 	*y = t*p2*u2 + (v3-t*(v3-p3))*u3;
19 	*x = t*p1;
20 	if(t < 0)
21 		return 0;
22 	if(*x * *x + *y * *y > 16)
23 		return -1;
24 	return 1;
25 }
26 
27 proj
28 harrison(double r, double alpha)
29 {
30 	u2 = cos(alpha*RAD);
31 	u3 = sin(alpha*RAD);
32 	v3 = r;
33 	b = r*u2;
34 	a = 1 + b;
35 	if(r<1.001 || a<sqrt(r*r-1))
36 		return 0;
37 	return Xharrison;
38 }
39