aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/map/libmap/harrison.c
blob: 6b6003c2c3615263e6c0fad44c1e2d1dcc0a750f (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
#include <u.h>
#include <libc.h>
#include "map.h"

static double v3,u2,u3,a,b; /*v=view,p=obj,u=unit.y*/

static int
Xharrison(struct place *place, double *x, double *y)
{
	double p1 = -place->nlat.c*place->wlon.s;
	double p2 = -place->nlat.c*place->wlon.c;
	double p3 = place->nlat.s;
	double d = b + u3*p2 - u2*p3;
	double t;
	if(d < .01)
		return -1;
	t = a/d;
	if(v3*place->nlat.s < 1.)
		return -1;
	*y = t*p2*u2 + (v3-t*(v3-p3))*u3;
	*x = t*p1;
	if(t < 0)
		return 0;
	if(*x * *x + *y * *y > 16)
		return -1;
	return 1;
}

proj
harrison(double r, double alpha)
{
	u2 = cos(alpha*RAD);
	u3 = sin(alpha*RAD);
	v3 = r;
	b = r*u2;
	a = 1 + b;
	if(r<1.001 || a<sqrt(r*r-1))
		return 0;
	return Xharrison;
}