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

static struct coord stdp0, stdp1;
static double k;

static int
Xlambert(struct place *place, double *x, double *y)
{
	double r;
	if(place->nlat.l < -80.*RAD)
		return(-1);
	if(place->nlat.l > 89.*RAD)
		r = 0;	/* slovenly */
	else
		r = stdp0.c*exp(0.5*k*log(
		   (1+stdp0.s)*(1-place->nlat.s)/((1-stdp0.s)*(1+place->nlat.s))));
	if(stdp1.l<0.)
		r = -r;
	*x = - r*sin(k * place->wlon.l);
	*y = - r*cos(k * place->wlon.l);
	return(1);
}

proj
lambert(double par0, double par1)
{
	double temp;
	if(fabs(par0)>fabs(par1)){
		temp = par0;
		par0 = par1;
		par1 = temp;
	}
	deg2rad(par0, &stdp0);
	deg2rad(par1, &stdp1);
	if(fabs(par1+par0)<.1)
		return(mercator());
	if(fabs(par1-par0)<.1)
		return(perspective(-1.));
	if(fabs(par0)>89.5||fabs(par1)>89.5)
		return(0);
	k = 2*log(stdp1.c/stdp0.c)/log(
		(1+stdp0.s)*(1-stdp1.s)/((1-stdp0.s)*(1+stdp1.s)));
	return(Xlambert);
}