-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAngle.js
More file actions
218 lines (192 loc) · 8.15 KB
/
Angle.js
File metadata and controls
218 lines (192 loc) · 8.15 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright 2003-2006, 2009, 2017, 2020 United States Government, as represented
* by the Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The NASAWorldWind/WebWorldWind platform is licensed under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License
* at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* NASAWorldWind/WebWorldWind also contains the following 3rd party Open Source
* software:
*
* ES6-Promise – under MIT License
* libtess.js – SGI Free Software License B
* Proj4 – under MIT License
* JSZip – under MIT License
*
* A complete listing of 3rd Party software notices and licenses included in
* WebWorldWind can be found in the WebWorldWind 3rd-party notices and licenses
* PDF found in code directory.*/
var Angle = {
/**
* Conversion factor for degrees to radians.
* @constant
*/
DEGREES_TO_RADIANS: Math.PI / 180.0,
/**
* Conversion factor for radians to degrees.
* @constant
*/
RADIANS_TO_DEGREES: 180.0 / Math.PI,
/**
* 2 pi.
* @constant
*/
TWO_PI: 2 * Math.PI,
/**
* pi / 2
* @constant
*/
HALF_PI: Math.PI / 2,
/**
* Normalizes a specified value to be within the range of [-180, 180] degrees.
* @param {Number} degrees The value to normalize, in degrees.
* @returns {Number} The specified value normalized to [-180, 180] degrees.
*/
normalizedDegrees: function (degrees) {
var angle = degrees % 360;
return angle > 180 ? angle - 360 : angle < -180 ? 360 + angle : angle;
},
/**
* Normalizes a specified value to be within the range of [-90, 90] degrees.
* @param {Number} degrees The value to normalize, in degrees.
* @returns {Number} The specified value normalized to the normal range of latitude.
*/
normalizedDegreesLatitude: function (degrees) {
var lat = degrees % 180;
return lat > 90 ? 180 - lat : lat < -90 ? -180 - lat : lat;
},
/**
* Normalizes a specified value to be within the range of [-180, 180] degrees.
* @param {Number} degrees The value to normalize, in degrees.
* @returns {Number} The specified value normalized to the normal range of longitude.
*/
normalizedDegreesLongitude: function (degrees) {
var lon = degrees % 360;
return lon > 180 ? lon - 360 : lon < -180 ? 360 + lon : lon;
},
/**
* Normalizes a specified value to be within the range of [-Pi, Pi] radians.
* @param {Number} radians The value to normalize, in radians.
* @returns {Number} The specified value normalized to [-Pi, Pi] radians.
*/
normalizedRadians: function (radians) {
var angle = radians % this.TWO_PI;
return angle > Math.PI ? angle - this.TWO_PI : angle < -Math.PI ? this.TWO_PI + angle : angle;
},
/**
* Normalizes a specified value to be within the range of [-Pi/2, Pi/2] radians.
* @param {Number} radians The value to normalize, in radians.
* @returns {Number} The specified value normalized to the normal range of latitude.
*/
normalizedRadiansLatitude: function (radians) {
var lat = radians % Math.PI;
return lat > this.HALF_PI ? Math.PI - lat : lat < -this.HALF_PI ? -Math.PI - lat : lat;
},
/**
* Normalizes a specified value to be within the range of [-Pi, Pi] radians.
* @param {Number} radians The value to normalize, in radians.
* @returns {Number} The specified value normalized to the normal range of longitude.
*/
normalizedRadiansLongitude: function (radians) {
var lon = radians % this.TWO_PI;
return lon > Math.PI ? lon - this.TWO_PI : lon < -Math.PI ? this.TWO_PI + lon : lon;
},
/**
* Indicates whether a specified value is within the normal range of latitude, [-90, 90].
* @param {Number} degrees The value to test, in degrees.
* @returns {Boolean} true if the value is within the normal range of latitude, otherwise false.
*/
isValidLatitude: function (degrees) {
return degrees >= -90 && degrees <= 90;
},
/**
* Indicates whether a specified value is within the normal range of longitude, [-180, 180].
* @param {Number} degrees The value to test, in degrees.
* @returns {boolean} true if the value is within the normal range of longitude, otherwise false.
*/
isValidLongitude: function (degrees) {
return degrees >= -180 && degrees <= 180;
},
/**
* Returns a string representation of a specified value in degrees.
* @param {Number} degrees The value for which to compute the string.
* @returns {String} The computed string, which is a decimal degrees value followed by the degree symbol.
*/
toString: function (degrees) {
return degrees.toString() + '\u00B0';
},
/**
* Returns a decimal degrees string representation of a specified value in degrees.
* @param {Number} degrees The value for which to compute the string.
* @returns {String} The computed string, which is a decimal degrees value followed by the degree symbol.
*/
toDecimalDegreesString: function (degrees) {
return degrees.toString() + '\u00B0';
},
/**
* Returns a degrees-minutes-seconds string representation of a specified value in degrees.
* @param {Number} degrees The value for which to compute the string.
* @returns {String} The computed string in degrees, minutes and decimal seconds.
*/
toDMSString: function (degrees) {
var sign,
temp,
d,
m,
s;
sign = degrees < 0 ? -1 : 1;
temp = sign * degrees;
d = Math.floor(temp);
temp = (temp - d) * 60;
m = Math.floor(temp);
temp = (temp - m) * 60;
s = Math.round(temp);
if (s == 60) {
m++;
s = 0;
}
if (m == 60) {
d++;
m = 0;
}
return (sign == -1 ? "-" : "") + d + "\u00B0" + " " + m + "\u2019" + " " + s + "\u201D";
},
/**
* Returns a degrees-minutes string representation of a specified value in degrees.
* @param {Number} degrees The value for which to compute the string.
* @returns {String} The computed string in degrees and decimal minutes.
*/
toDMString: function (degrees) {
var sign,
temp,
d,
m,
s,
mf;
sign = degrees < 0 ? -1 : 1;
temp = sign * degrees;
d = Math.floor(temp);
temp = (temp - d) * 60;
m = Math.floor(temp);
temp = (temp - m) * 60;
s = Math.round(temp);
if (s == 60) {
m++;
s = 0;
}
if (m == 60) {
d++;
m = 0;
}
mf = s == 0 ? m : m + s / 60;
return (sign == -1 ? "-" : "") + d + "\u00B0" + " " + mf + "\u2019";
}
};