blob: 32bdadf95804515b9782e3ec3743889ff79e39d9 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include <u.h>
#include <libc.h>
#include "map.h"
#define ORTHRAD 1000
static double viewpt;
static int
Xperspective(struct place *place, double *x, double *y)
{
double r;
if(viewpt<=1+FUZZ && fabs(place->nlat.s)<=viewpt+.01)
return(-1);
r = place->nlat.c*(viewpt - 1.)/(viewpt - place->nlat.s);
*x = - r*place->wlon.s;
*y = - r*place->wlon.c;
if(r>4.)
return(-1);
if(fabs(viewpt)>1 && place->nlat.s<1/viewpt ||
fabs(viewpt)<=1 && place->nlat.s<viewpt)
return 0;
return(1);
}
proj
perspective(double radius)
{
viewpt = radius;
if(viewpt >= ORTHRAD)
return(Xorthographic);
if(fabs(viewpt-1.)<.0001)
return(0);
return(Xperspective);
}
/* called from various conformal projections,
but not from stereographic itself */
int
Xstereographic(struct place *place, double *x, double *y)
{
double v = viewpt;
int retval;
viewpt = -1;
retval = Xperspective(place, x, y);
viewpt = v;
return retval;
}
proj
stereographic(void)
{
viewpt = -1.;
return(Xperspective);
}
proj
gnomonic(void)
{
viewpt = 0.;
return(Xperspective);
}
int
plimb(double *lat, double *lon, double res)
{
static int first = 1;
if(viewpt >= ORTHRAD)
return olimb(lat, lon, res);
if(first) {
first = 0;
*lon = -180;
if(fabs(viewpt) < .01)
*lat = 0;
else if(fabs(viewpt)<=1)
*lat = asin(viewpt)/RAD;
else
*lat = asin(1/viewpt)/RAD;
} else
*lon += res;
if(*lon <= 180)
return 1;
first = 1;
return -1;
}
|