require Exporter;
package Math::Trig;
+use 5.005_64;
use strict;
use Math::Complex qw(:trig);
-use vars qw($VERSION $PACKAGE
- @ISA
- @EXPORT @EXPORT_OK %EXPORT_TAGS);
+our($VERSION, $PACKAGE, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
@ISA = qw(Exporter);
%EXPORT_TAGS = ('radial' => [ @rdlcnv ]);
-use constant pi2 => 2 * pi;
-use constant pip2 => pi / 2;
+sub pi2 () { 2 * pi } # use constant generates warning
+sub pip2 () { pi / 2 } # use constant generates warning
use constant DR => pi2/360;
use constant RD => 360/pi2;
use constant DG => 400/360;
=head1 SYNOPSIS
use Math::Trig;
-
+
$x = tan(0.9);
$y = acos(3.7);
$z = asin(2.4);
-
+
$halfpi = pi/2;
$rad = deg2rad(120);
details like for example how to display complex numbers. For example:
print asin(2), "\n";
-
+
should produce something like this (take or leave few last decimals):
1.5707963267949-1.31695789692482i
$radians = deg2rad($degrees);
$radians = grad2rad($gradians);
-
+
$degrees = rad2deg($radians);
$degrees = grad2deg($gradians);
-
+
$gradians = deg2grad($degrees);
$gradians = rad2grad($radians);
If you think geographically the I<theta> are longitudes: zero at the
Greenwhich meridian, eastward positive, westward negative--and the
-I<phi> are latitudes: zero at North Pole, northward positive,
+I<phi> are latitudes: zero at the North Pole, northward positive,
southward negative. B<NOTE>: this formula thinks in mathematics, not
-geographically: the I<phi> zero is at the Nort Pole, not on the
-west coast of Africa (Bay of Guinea). You need to subtract your
-geographical coordinates from I<pi/2> (also known as 90 degrees).
+geographically: the I<phi> zero is at the North Pole, not at the
+Equator on the west coast of Africa (Bay of Guinea). You need to
+subtract your geographical coordinates from I<pi/2> (also known as 90
+degrees).
$distance = great_circle_distance($lon0, pi/2 - $lat0,
$lon1, pi/2 - $lat1, $rho);
$km = great_circle_distance(@L, @T, 6378);
The answer may be off by few percentages because of the irregular
-(slightly aspherical) form of the Earth.
+(slightly aspherical) form of the Earth. The used formula
+
+ lat0 = 90 degrees - phi0
+ lat1 = 90 degrees - phi1
+ d = R * arccos(cos(lat0) * cos(lat1) * cos(lon1 - lon01) +
+ sin(lat0) * sin(lat1))
+
+is also somewhat unreliable for small distances (for locations
+separated less than about five degrees) because it uses arc cosine
+which is rather ill-conditioned for values close to zero.
=head1 BUGS
=head1 AUTHORS
Jarkko Hietaniemi <F<jhi@iki.fi>> and
-Raphael Manfredi <F<Raphael_Manfredi@grenoble.hp.com>>.
+Raphael Manfredi <F<Raphael_Manfredi@pobox.com>>.
=cut