Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
2 | .\" | |
3 | .\" Standard preamble: | |
4 | .\" ======================================================================== | |
5 | .de Sh \" Subsection heading | |
6 | .br | |
7 | .if t .Sp | |
8 | .ne 5 | |
9 | .PP | |
10 | \fB\\$1\fR | |
11 | .PP | |
12 | .. | |
13 | .de Sp \" Vertical space (when we can't use .PP) | |
14 | .if t .sp .5v | |
15 | .if n .sp | |
16 | .. | |
17 | .de Vb \" Begin verbatim text | |
18 | .ft CW | |
19 | .nf | |
20 | .ne \\$1 | |
21 | .. | |
22 | .de Ve \" End verbatim text | |
23 | .ft R | |
24 | .fi | |
25 | .. | |
26 | .\" Set up some character translations and predefined strings. \*(-- will | |
27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left | |
28 | .\" double quote, and \*(R" will give a right double quote. | will give a | |
29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to | |
30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' | |
31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. | |
32 | .tr \(*W-|\(bv\*(Tr | |
33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' | |
34 | .ie n \{\ | |
35 | . ds -- \(*W- | |
36 | . ds PI pi | |
37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch | |
38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch | |
39 | . ds L" "" | |
40 | . ds R" "" | |
41 | . ds C` "" | |
42 | . ds C' "" | |
43 | 'br\} | |
44 | .el\{\ | |
45 | . ds -- \|\(em\| | |
46 | . ds PI \(*p | |
47 | . ds L" `` | |
48 | . ds R" '' | |
49 | 'br\} | |
50 | .\" | |
51 | .\" If the F register is turned on, we'll generate index entries on stderr for | |
52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index | |
53 | .\" entries marked with X<> in POD. Of course, you'll have to process the | |
54 | .\" output yourself in some meaningful fashion. | |
55 | .if \nF \{\ | |
56 | . de IX | |
57 | . tm Index:\\$1\t\\n%\t"\\$2" | |
58 | .. | |
59 | . nr % 0 | |
60 | . rr F | |
61 | .\} | |
62 | .\" | |
63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes | |
64 | .\" way too many mistakes in technical documents. | |
65 | .hy 0 | |
66 | .if n .na | |
67 | .\" | |
68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). | |
69 | .\" Fear. Run. Save yourself. No user-serviceable parts. | |
70 | . \" fudge factors for nroff and troff | |
71 | .if n \{\ | |
72 | . ds #H 0 | |
73 | . ds #V .8m | |
74 | . ds #F .3m | |
75 | . ds #[ \f1 | |
76 | . ds #] \fP | |
77 | .\} | |
78 | .if t \{\ | |
79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) | |
80 | . ds #V .6m | |
81 | . ds #F 0 | |
82 | . ds #[ \& | |
83 | . ds #] \& | |
84 | .\} | |
85 | . \" simple accents for nroff and troff | |
86 | .if n \{\ | |
87 | . ds ' \& | |
88 | . ds ` \& | |
89 | . ds ^ \& | |
90 | . ds , \& | |
91 | . ds ~ ~ | |
92 | . ds / | |
93 | .\} | |
94 | .if t \{\ | |
95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" | |
96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' | |
97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' | |
98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' | |
99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' | |
100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' | |
101 | .\} | |
102 | . \" troff and (daisy-wheel) nroff accents | |
103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' | |
104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' | |
105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] | |
106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' | |
107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' | |
108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] | |
109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] | |
110 | .ds ae a\h'-(\w'a'u*4/10)'e | |
111 | .ds Ae A\h'-(\w'A'u*4/10)'E | |
112 | . \" corrections for vroff | |
113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' | |
114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' | |
115 | . \" for low resolution devices (crt and lpr) | |
116 | .if \n(.H>23 .if \n(.V>19 \ | |
117 | \{\ | |
118 | . ds : e | |
119 | . ds 8 ss | |
120 | . ds o a | |
121 | . ds d- d\h'-1'\(ga | |
122 | . ds D- D\h'-1'\(hy | |
123 | . ds th \o'bp' | |
124 | . ds Th \o'LP' | |
125 | . ds ae ae | |
126 | . ds Ae AE | |
127 | .\} | |
128 | .rm #[ #] #H #V #F C | |
129 | .\" ======================================================================== | |
130 | .\" | |
131 | .IX Title "Math::Trig 3" | |
132 | .TH Math::Trig 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide" | |
133 | .SH "NAME" | |
134 | Math::Trig \- trigonometric functions | |
135 | .SH "SYNOPSIS" | |
136 | .IX Header "SYNOPSIS" | |
137 | .Vb 1 | |
138 | \& use Math::Trig; | |
139 | .Ve | |
140 | .PP | |
141 | .Vb 3 | |
142 | \& $x = tan(0.9); | |
143 | \& $y = acos(3.7); | |
144 | \& $z = asin(2.4); | |
145 | .Ve | |
146 | .PP | |
147 | .Vb 1 | |
148 | \& $halfpi = pi/2; | |
149 | .Ve | |
150 | .PP | |
151 | .Vb 1 | |
152 | \& $rad = deg2rad(120); | |
153 | .Ve | |
154 | .SH "DESCRIPTION" | |
155 | .IX Header "DESCRIPTION" | |
156 | \&\f(CW\*(C`Math::Trig\*(C'\fR defines many trigonometric functions not defined by the | |
157 | core Perl which defines only the \f(CW\*(C`sin()\*(C'\fR and \f(CW\*(C`cos()\*(C'\fR. The constant | |
158 | \&\fBpi\fR is also defined as are a few convenience functions for angle | |
159 | conversions. | |
160 | .SH "TRIGONOMETRIC FUNCTIONS" | |
161 | .IX Header "TRIGONOMETRIC FUNCTIONS" | |
162 | The tangent | |
163 | .IP "\fBtan\fR" 4 | |
164 | .IX Item "tan" | |
165 | .PP | |
166 | The cofunctions of the sine, cosine, and tangent (cosec/csc and cotan/cot | |
167 | are aliases) | |
168 | .PP | |
169 | \&\fBcsc\fR, \fBcosec\fR, \fBsec\fR, \fBsec\fR, \fBcot\fR, \fBcotan\fR | |
170 | .PP | |
171 | The arcus (also known as the inverse) functions of the sine, cosine, | |
172 | and tangent | |
173 | .PP | |
174 | \&\fBasin\fR, \fBacos\fR, \fBatan\fR | |
175 | .PP | |
176 | The principal value of the arc tangent of y/x | |
177 | .PP | |
178 | \&\fBatan2\fR(y, x) | |
179 | .PP | |
180 | The arcus cofunctions of the sine, cosine, and tangent (acosec/acsc | |
181 | and acotan/acot are aliases) | |
182 | .PP | |
183 | \&\fBacsc\fR, \fBacosec\fR, \fBasec\fR, \fBacot\fR, \fBacotan\fR | |
184 | .PP | |
185 | The hyperbolic sine, cosine, and tangent | |
186 | .PP | |
187 | \&\fBsinh\fR, \fBcosh\fR, \fBtanh\fR | |
188 | .PP | |
189 | The cofunctions of the hyperbolic sine, cosine, and tangent (cosech/csch | |
190 | and cotanh/coth are aliases) | |
191 | .PP | |
192 | \&\fBcsch\fR, \fBcosech\fR, \fBsech\fR, \fBcoth\fR, \fBcotanh\fR | |
193 | .PP | |
194 | The arcus (also known as the inverse) functions of the hyperbolic | |
195 | sine, cosine, and tangent | |
196 | .PP | |
197 | \&\fBasinh\fR, \fBacosh\fR, \fBatanh\fR | |
198 | .PP | |
199 | The arcus cofunctions of the hyperbolic sine, cosine, and tangent | |
200 | (acsch/acosech and acoth/acotanh are aliases) | |
201 | .PP | |
202 | \&\fBacsch\fR, \fBacosech\fR, \fBasech\fR, \fBacoth\fR, \fBacotanh\fR | |
203 | .PP | |
204 | The trigonometric constant \fBpi\fR is also defined. | |
205 | .PP | |
206 | $pi2 = 2 * \fBpi\fR; | |
207 | .Sh "\s-1ERRORS\s0 \s-1DUE\s0 \s-1TO\s0 \s-1DIVISION\s0 \s-1BY\s0 \s-1ZERO\s0" | |
208 | .IX Subsection "ERRORS DUE TO DIVISION BY ZERO" | |
209 | The following functions | |
210 | .PP | |
211 | .Vb 14 | |
212 | \& acoth | |
213 | \& acsc | |
214 | \& acsch | |
215 | \& asec | |
216 | \& asech | |
217 | \& atanh | |
218 | \& cot | |
219 | \& coth | |
220 | \& csc | |
221 | \& csch | |
222 | \& sec | |
223 | \& sech | |
224 | \& tan | |
225 | \& tanh | |
226 | .Ve | |
227 | .PP | |
228 | cannot be computed for all arguments because that would mean dividing | |
229 | by zero or taking logarithm of zero. These situations cause fatal | |
230 | runtime errors looking like this | |
231 | .PP | |
232 | .Vb 3 | |
233 | \& cot(0): Division by zero. | |
234 | \& (Because in the definition of cot(0), the divisor sin(0) is 0) | |
235 | \& Died at ... | |
236 | .Ve | |
237 | .PP | |
238 | or | |
239 | .PP | |
240 | .Vb 2 | |
241 | \& atanh(-1): Logarithm of zero. | |
242 | \& Died at... | |
243 | .Ve | |
244 | .PP | |
245 | For the \f(CW\*(C`csc\*(C'\fR, \f(CW\*(C`cot\*(C'\fR, \f(CW\*(C`asec\*(C'\fR, \f(CW\*(C`acsc\*(C'\fR, \f(CW\*(C`acot\*(C'\fR, \f(CW\*(C`csch\*(C'\fR, \f(CW\*(C`coth\*(C'\fR, | |
246 | \&\f(CW\*(C`asech\*(C'\fR, \f(CW\*(C`acsch\*(C'\fR, the argument cannot be \f(CW0\fR (zero). For the | |
247 | \&\f(CW\*(C`atanh\*(C'\fR, \f(CW\*(C`acoth\*(C'\fR, the argument cannot be \f(CW1\fR (one). For the | |
248 | \&\f(CW\*(C`atanh\*(C'\fR, \f(CW\*(C`acoth\*(C'\fR, the argument cannot be \f(CW\*(C`\-1\*(C'\fR (minus one). For the | |
249 | \&\f(CW\*(C`tan\*(C'\fR, \f(CW\*(C`sec\*(C'\fR, \f(CW\*(C`tanh\*(C'\fR, \f(CW\*(C`sech\*(C'\fR, the argument cannot be \fIpi/2 + k * | |
250 | pi\fR, where \fIk\fR is any integer. | |
251 | .Sh "\s-1SIMPLE\s0 (\s-1REAL\s0) \s-1ARGUMENTS\s0, \s-1COMPLEX\s0 \s-1RESULTS\s0" | |
252 | .IX Subsection "SIMPLE (REAL) ARGUMENTS, COMPLEX RESULTS" | |
253 | Please note that some of the trigonometric functions can break out | |
254 | from the \fBreal axis\fR into the \fBcomplex plane\fR. For example | |
255 | \&\f(CWasin(2)\fR has no definition for plain real numbers but it has | |
256 | definition for complex numbers. | |
257 | .PP | |
258 | In Perl terms this means that supplying the usual Perl numbers (also | |
259 | known as scalars, please see perldata) as input for the | |
260 | trigonometric functions might produce as output results that no more | |
261 | are simple real numbers: instead they are complex numbers. | |
262 | .PP | |
263 | The \f(CW\*(C`Math::Trig\*(C'\fR handles this by using the \f(CW\*(C`Math::Complex\*(C'\fR package | |
264 | which knows how to handle complex numbers, please see Math::Complex | |
265 | for more information. In practice you need not to worry about getting | |
266 | complex numbers as results because the \f(CW\*(C`Math::Complex\*(C'\fR takes care of | |
267 | details like for example how to display complex numbers. For example: | |
268 | .PP | |
269 | .Vb 1 | |
270 | \& print asin(2), "\en"; | |
271 | .Ve | |
272 | .PP | |
273 | should produce something like this (take or leave few last decimals): | |
274 | .PP | |
275 | .Vb 1 | |
276 | \& 1.5707963267949-1.31695789692482i | |
277 | .Ve | |
278 | .PP | |
279 | That is, a complex number with the real part of approximately \f(CW1.571\fR | |
280 | and the imaginary part of approximately \f(CW\*(C`\-1.317\*(C'\fR. | |
281 | .SH "PLANE ANGLE CONVERSIONS" | |
282 | .IX Header "PLANE ANGLE CONVERSIONS" | |
283 | (Plane, 2\-dimensional) angles may be converted with the following functions. | |
284 | .PP | |
285 | .Vb 2 | |
286 | \& $radians = deg2rad($degrees); | |
287 | \& $radians = grad2rad($gradians); | |
288 | .Ve | |
289 | .PP | |
290 | .Vb 2 | |
291 | \& $degrees = rad2deg($radians); | |
292 | \& $degrees = grad2deg($gradians); | |
293 | .Ve | |
294 | .PP | |
295 | .Vb 2 | |
296 | \& $gradians = deg2grad($degrees); | |
297 | \& $gradians = rad2grad($radians); | |
298 | .Ve | |
299 | .PP | |
300 | The full circle is 2 \fIpi\fR radians or \fI360\fR degrees or \fI400\fR gradians. | |
301 | The result is by default wrapped to be inside the [0, {2pi,360,400}[ circle. | |
302 | If you don't want this, supply a true second argument: | |
303 | .PP | |
304 | .Vb 2 | |
305 | \& $zillions_of_radians = deg2rad($zillions_of_degrees, 1); | |
306 | \& $negative_degrees = rad2deg($negative_radians, 1); | |
307 | .Ve | |
308 | .PP | |
309 | You can also do the wrapping explicitly by \fIrad2rad()\fR, \fIdeg2deg()\fR, and | |
310 | \&\fIgrad2grad()\fR. | |
311 | .SH "RADIAL COORDINATE CONVERSIONS" | |
312 | .IX Header "RADIAL COORDINATE CONVERSIONS" | |
313 | \&\fBRadial coordinate systems\fR are the \fBspherical\fR and the \fBcylindrical\fR | |
314 | systems, explained shortly in more detail. | |
315 | .PP | |
316 | You can import radial coordinate conversion functions by using the | |
317 | \&\f(CW\*(C`:radial\*(C'\fR tag: | |
318 | .PP | |
319 | .Vb 1 | |
320 | \& use Math::Trig ':radial'; | |
321 | .Ve | |
322 | .PP | |
323 | .Vb 6 | |
324 | \& ($rho, $theta, $z) = cartesian_to_cylindrical($x, $y, $z); | |
325 | \& ($rho, $theta, $phi) = cartesian_to_spherical($x, $y, $z); | |
326 | \& ($x, $y, $z) = cylindrical_to_cartesian($rho, $theta, $z); | |
327 | \& ($rho_s, $theta, $phi) = cylindrical_to_spherical($rho_c, $theta, $z); | |
328 | \& ($x, $y, $z) = spherical_to_cartesian($rho, $theta, $phi); | |
329 | \& ($rho_c, $theta, $z) = spherical_to_cylindrical($rho_s, $theta, $phi); | |
330 | .Ve | |
331 | .PP | |
332 | \&\fBAll angles are in radians\fR. | |
333 | .Sh "\s-1COORDINATE\s0 \s-1SYSTEMS\s0" | |
334 | .IX Subsection "COORDINATE SYSTEMS" | |
335 | \&\fBCartesian\fR coordinates are the usual rectangular \fI(x, y, | |
336 | z)\fR\-coordinates. | |
337 | .PP | |
338 | Spherical coordinates, \fI(rho, theta, pi)\fR, are three-dimensional | |
339 | coordinates which define a point in three-dimensional space. They are | |
340 | based on a sphere surface. The radius of the sphere is \fBrho\fR, also | |
341 | known as the \fIradial\fR coordinate. The angle in the \fIxy\fR\-plane | |
342 | (around the \fIz\fR\-axis) is \fBtheta\fR, also known as the \fIazimuthal\fR | |
343 | coordinate. The angle from the \fIz\fR\-axis is \fBphi\fR, also known as the | |
344 | \&\fIpolar\fR coordinate. The `North Pole' is therefore \fI0, 0, rho\fR, and | |
345 | the `Bay of Guinea' (think of the missing big chunk of Africa) \fI0, | |
346 | pi/2, rho\fR. In geographical terms \fIphi\fR is latitude (northward | |
347 | positive, southward negative) and \fItheta\fR is longitude (eastward | |
348 | positive, westward negative). | |
349 | .PP | |
350 | \&\fB\s-1BEWARE\s0\fR: some texts define \fItheta\fR and \fIphi\fR the other way round, | |
351 | some texts define the \fIphi\fR to start from the horizontal plane, some | |
352 | texts use \fIr\fR in place of \fIrho\fR. | |
353 | .PP | |
354 | Cylindrical coordinates, \fI(rho, theta, z)\fR, are three-dimensional | |
355 | coordinates which define a point in three-dimensional space. They are | |
356 | based on a cylinder surface. The radius of the cylinder is \fBrho\fR, | |
357 | also known as the \fIradial\fR coordinate. The angle in the \fIxy\fR\-plane | |
358 | (around the \fIz\fR\-axis) is \fBtheta\fR, also known as the \fIazimuthal\fR | |
359 | coordinate. The third coordinate is the \fIz\fR, pointing up from the | |
360 | \&\fBtheta\fR\-plane. | |
361 | .Sh "3\-D \s-1ANGLE\s0 \s-1CONVERSIONS\s0" | |
362 | .IX Subsection "3-D ANGLE CONVERSIONS" | |
363 | Conversions to and from spherical and cylindrical coordinates are | |
364 | available. Please notice that the conversions are not necessarily | |
365 | reversible because of the equalities like \fIpi\fR angles being equal to | |
366 | \&\fI\-pi\fR angles. | |
367 | .IP "cartesian_to_cylindrical" 4 | |
368 | .IX Item "cartesian_to_cylindrical" | |
369 | .Vb 1 | |
370 | \& ($rho, $theta, $z) = cartesian_to_cylindrical($x, $y, $z); | |
371 | .Ve | |
372 | .IP "cartesian_to_spherical" 4 | |
373 | .IX Item "cartesian_to_spherical" | |
374 | .Vb 1 | |
375 | \& ($rho, $theta, $phi) = cartesian_to_spherical($x, $y, $z); | |
376 | .Ve | |
377 | .IP "cylindrical_to_cartesian" 4 | |
378 | .IX Item "cylindrical_to_cartesian" | |
379 | .Vb 1 | |
380 | \& ($x, $y, $z) = cylindrical_to_cartesian($rho, $theta, $z); | |
381 | .Ve | |
382 | .IP "cylindrical_to_spherical" 4 | |
383 | .IX Item "cylindrical_to_spherical" | |
384 | .Vb 1 | |
385 | \& ($rho_s, $theta, $phi) = cylindrical_to_spherical($rho_c, $theta, $z); | |
386 | .Ve | |
387 | .Sp | |
388 | Notice that when \f(CW$z\fR is not 0 \f(CW$rho_s\fR is not equal to \f(CW$rho_c\fR. | |
389 | .IP "spherical_to_cartesian" 4 | |
390 | .IX Item "spherical_to_cartesian" | |
391 | .Vb 1 | |
392 | \& ($x, $y, $z) = spherical_to_cartesian($rho, $theta, $phi); | |
393 | .Ve | |
394 | .IP "spherical_to_cylindrical" 4 | |
395 | .IX Item "spherical_to_cylindrical" | |
396 | .Vb 1 | |
397 | \& ($rho_c, $theta, $z) = spherical_to_cylindrical($rho_s, $theta, $phi); | |
398 | .Ve | |
399 | .Sp | |
400 | Notice that when \f(CW$z\fR is not 0 \f(CW$rho_c\fR is not equal to \f(CW$rho_s\fR. | |
401 | .SH "GREAT CIRCLE DISTANCES AND DIRECTIONS" | |
402 | .IX Header "GREAT CIRCLE DISTANCES AND DIRECTIONS" | |
403 | You can compute spherical distances, called \fBgreat circle distances\fR, | |
404 | by importing the \fIgreat_circle_distance()\fR function: | |
405 | .PP | |
406 | .Vb 1 | |
407 | \& use Math::Trig 'great_circle_distance'; | |
408 | .Ve | |
409 | .PP | |
410 | .Vb 1 | |
411 | \& $distance = great_circle_distance($theta0, $phi0, $theta1, $phi1, [, $rho]); | |
412 | .Ve | |
413 | .PP | |
414 | The \fIgreat circle distance\fR is the shortest distance between two | |
415 | points on a sphere. The distance is in \f(CW$rho\fR units. The \f(CW$rho\fR is | |
416 | optional, it defaults to 1 (the unit sphere), therefore the distance | |
417 | defaults to radians. | |
418 | .PP | |
419 | If you think geographically the \fItheta\fR are longitudes: zero at the | |
420 | Greenwhich meridian, eastward positive, westward negative\*(--and the | |
421 | \&\fIphi\fR are latitudes: zero at the North Pole, northward positive, | |
422 | southward negative. \fB\s-1NOTE\s0\fR: this formula thinks in mathematics, not | |
423 | geographically: the \fIphi\fR zero is at the North Pole, not at the | |
424 | Equator on the west coast of Africa (Bay of Guinea). You need to | |
425 | subtract your geographical coordinates from \fIpi/2\fR (also known as 90 | |
426 | degrees). | |
427 | .PP | |
428 | .Vb 2 | |
429 | \& $distance = great_circle_distance($lon0, pi/2 - $lat0, | |
430 | \& $lon1, pi/2 - $lat1, $rho); | |
431 | .Ve | |
432 | .PP | |
433 | The direction you must follow the great circle can be computed by the | |
434 | \&\fIgreat_circle_direction()\fR function: | |
435 | .PP | |
436 | .Vb 1 | |
437 | \& use Math::Trig 'great_circle_direction'; | |
438 | .Ve | |
439 | .PP | |
440 | .Vb 1 | |
441 | \& $direction = great_circle_direction($theta0, $phi0, $theta1, $phi1); | |
442 | .Ve | |
443 | .PP | |
444 | The result is in radians, zero indicating straight north, pi or \-pi | |
445 | straight south, pi/2 straight west, and \-pi/2 straight east. | |
446 | .PP | |
447 | Notice that the resulting directions might be somewhat surprising if | |
448 | you are looking at a flat worldmap: in such map projections the great | |
449 | circles quite often do not look like the shortest routes\*(-- but for | |
450 | example the shortest possible routes from Europe or North America to | |
451 | Asia do often cross the polar regions. | |
452 | .SH "EXAMPLES" | |
453 | .IX Header "EXAMPLES" | |
454 | To calculate the distance between London (51.3N 0.5W) and Tokyo | |
455 | (35.7N 139.8E) in kilometers: | |
456 | .PP | |
457 | .Vb 1 | |
458 | \& use Math::Trig qw(great_circle_distance deg2rad); | |
459 | .Ve | |
460 | .PP | |
461 | .Vb 3 | |
462 | \& # Notice the 90 - latitude: phi zero is at the North Pole. | |
463 | \& @L = (deg2rad(-0.5), deg2rad(90 - 51.3)); | |
464 | \& @T = (deg2rad(139.8),deg2rad(90 - 35.7)); | |
465 | .Ve | |
466 | .PP | |
467 | .Vb 1 | |
468 | \& $km = great_circle_distance(@L, @T, 6378); | |
469 | .Ve | |
470 | .PP | |
471 | The direction you would have to go from London to Tokyo | |
472 | .PP | |
473 | .Vb 1 | |
474 | \& use Math::Trig qw(great_circle_direction); | |
475 | .Ve | |
476 | .PP | |
477 | .Vb 1 | |
478 | \& $rad = great_circle_direction(@L, @T); | |
479 | .Ve | |
480 | .Sh "\s-1CAVEAT\s0 \s-1FOR\s0 \s-1GREAT\s0 \s-1CIRCLE\s0 \s-1FORMULAS\s0" | |
481 | .IX Subsection "CAVEAT FOR GREAT CIRCLE FORMULAS" | |
482 | The answers may be off by few percentages because of the irregular | |
483 | (slightly aspherical) form of the Earth. The formula used for | |
484 | grear circle distances | |
485 | .PP | |
486 | .Vb 4 | |
487 | \& lat0 = 90 degrees - phi0 | |
488 | \& lat1 = 90 degrees - phi1 | |
489 | \& d = R * arccos(cos(lat0) * cos(lat1) * cos(lon1 - lon01) + | |
490 | \& sin(lat0) * sin(lat1)) | |
491 | .Ve | |
492 | .PP | |
493 | is also somewhat unreliable for small distances (for locations | |
494 | separated less than about five degrees) because it uses arc cosine | |
495 | which is rather ill-conditioned for values close to zero. | |
496 | .SH "BUGS" | |
497 | .IX Header "BUGS" | |
498 | Saying \f(CW\*(C`use Math::Trig;\*(C'\fR exports many mathematical routines in the | |
499 | caller environment and even overrides some (\f(CW\*(C`sin\*(C'\fR, \f(CW\*(C`cos\*(C'\fR). This is | |
500 | construed as a feature by the Authors, actually... ;\-) | |
501 | .PP | |
502 | The code is not optimized for speed, especially because we use | |
503 | \&\f(CW\*(C`Math::Complex\*(C'\fR and thus go quite near complex numbers while doing | |
504 | the computations even when the arguments are not. This, however, | |
505 | cannot be completely avoided if we want things like \f(CWasin(2)\fR to give | |
506 | an answer instead of giving a fatal runtime error. | |
507 | .SH "AUTHORS" | |
508 | .IX Header "AUTHORS" | |
509 | Jarkko Hietaniemi <\fIjhi@iki.fi\fR> and | |
510 | Raphael Manfredi <\fIRaphael_Manfredi@pobox.com\fR>. |