ortho.js
3.62 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
NAME ORTHOGRAPHIC
PURPOSE: Transforms input longitude and latitude to Easting and
Northing for the Orthographic projection. The
longitude and latitude must be in radians. The Easting
and Northing values will be returned in meters.
PROGRAMMER DATE
---------- ----
T. Mittan Mar, 1993
ALGORITHM REFERENCES
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
State Government Printing Office, Washington D.C., 1987.
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
U.S. Geological Survey Professional Paper 1453 , United State Government
Printing Office, Washington D.C., 1989.
*******************************************************************************/
Proj4js.Proj.ortho = {
/* Initialize the Orthographic projection
-------------------------------------*/
init: function(def) {
//double temp; /* temporary variable */
/* Place parameters in static storage for common use
-------------------------------------------------*/;
this.sin_p14=Math.sin(this.lat0);
this.cos_p14=Math.cos(this.lat0);
},
/* Orthographic forward equations--mapping lat,long to x,y
---------------------------------------------------*/
forward: function(p) {
var sinphi, cosphi; /* sin and cos value */
var dlon; /* delta longitude value */
var coslon; /* cos of longitude */
var ksp; /* scale factor */
var g;
var lon=p.x;
var lat=p.y;
/* Forward equations
-----------------*/
dlon = Proj4js.common.adjust_lon(lon - this.long0);
sinphi=Math.sin(lat);
cosphi=Math.cos(lat);
coslon = Math.cos(dlon);
g = this.sin_p14 * sinphi + this.cos_p14 * cosphi * coslon;
ksp = 1.0;
if ((g > 0) || (Math.abs(g) <= Proj4js.common.EPSLN)) {
var x = this.a * ksp * cosphi * Math.sin(dlon);
var y = this.y0 + this.a * ksp * (this.cos_p14 * sinphi - this.sin_p14 * cosphi * coslon);
} else {
Proj4js.reportError("orthoFwdPointError");
}
p.x=x;
p.y=y;
return p;
},
inverse: function(p) {
var rh; /* height above ellipsoid */
var z; /* angle */
var sinz,cosz; /* sin of z and cos of z */
var temp;
var con;
var lon , lat;
/* Inverse equations
-----------------*/
p.x -= this.x0;
p.y -= this.y0;
rh = Math.sqrt(p.x * p.x + p.y * p.y);
if (rh > this.a + .0000001) {
Proj4js.reportError("orthoInvDataError");
}
z = Proj4js.common.asinz(rh / this.a);
sinz=Math.sin(z);
cosi=Math.cos(z);
lon = this.long0;
if (Math.abs(rh) <= Proj4js.common.EPSLN) {
lat = this.lat0;
}
lat = Proj4js.common.asinz(cosz * this.sin_p14 + (y * sinz * this.cos_p14)/rh);
con = Math.abs(lat0) - Proj4js.common.HALF_PI;
if (Math.abs(con) <= Proj4js.common.EPSLN) {
if (this.lat0 >= 0) {
lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2(p.x, -p.y));
} else {
lon = Proj4js.common.adjust_lon(this.long0 -Math.atan2(-p.x, p.y));
}
}
con = cosz - this.sin_p14 * Math.sin(lat);
if ((Math.abs(con) >= Proj4js.common.EPSLN) || (Math.abs(x) >= Proj4js.common.EPSLN)) {
lon = Proj4js.common.adjust_lon(this.long0 + Math.atan2((p.x * sinz * this.cos_p14), (con * rh)));
}
p.x=lon;
p.y=lat;
return p;
}
};