93 lines · 1.8 KB · C
RawDownload
/*  * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include <u.h>#include <libc.h>#include "map.h" #define ORTHRAD 1000static double viewpt; static intXperspective(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);} projperspective(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 */intXstereographic(struct place *place, double *x, double *y){	double v = viewpt;	int retval;	viewpt = -1;	retval = Xperspective(place, x, y);	viewpt = v;	return retval;} projstereographic(void){	viewpt = -1.;	return(Xperspective);} projgnomonic(void){	viewpt = 0.;	return(Xperspective);} intplimb(double *lat, double *lon, double res){	static 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;}