Math-Complex
view release on metacpan or search on metacpan
lib/Math/Complex.pm view on Meta::CPAN
exponential form, which is:
rho * exp(i * theta)
where I<i> is the famous imaginary number introduced above. Conversion
between this form and the cartesian form C<a + bi> is immediate:
a = rho * cos(theta)
b = rho * sin(theta)
which is also expressed by this formula:
z = rho * exp(i * theta) = rho * (cos theta + i * sin theta)
In other words, it's the projection of the vector onto the I<x> and I<y>
axes. Mathematicians call I<rho> the I<norm> or I<modulus> and I<theta>
the I<argument> of the complex number. The I<norm> of C<z> is
marked here as C<abs(z)>.
The polar notation (also known as the trigonometric representation) is
much more handy for performing multiplications and divisions of
lib/Math/Trig.pm view on Meta::CPAN
$halfpi = pi/2;
$rad = deg2rad(120);
# Import constants pi2, pip2, pip4 (2*pi, pi/2, pi/4).
use Math::Trig ':pi';
# Import the conversions between cartesian/spherical/cylindrical.
use Math::Trig ':radial';
# Import the great circle formulas.
use Math::Trig ':great_circle';
=head1 DESCRIPTION
C<Math::Trig> defines many trigonometric functions not defined by the
core Perl which defines only the C<sin()> and C<cos()>. The constant
B<pi> is also defined as are a few convenience functions for angle
conversions, and I<great circle formulas> for spherical movement.
=head1 TRIGONOMETRIC FUNCTIONS
The tangent
=over 4
=item B<tan>
=back
lib/Math/Trig.pm view on Meta::CPAN
$distance = great_circle_distance($theta0, $phi0, $theta1, $phi1, [, $rho]);
The I<great circle distance> is the shortest distance between two
points on a sphere. The distance is in C<$rho> units. The C<$rho> is
optional, it defaults to 1 (the unit sphere), therefore the distance
defaults to 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 the North Pole, northward positive,
southward negative. B<NOTE>: this formula thinks in mathematics, not
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);
=head2 great_circle_direction
lib/Math/Trig.pm view on Meta::CPAN
Where the $way is a value from zero ($theta0, $phi0) to one ($theta1,
$phi1). Note that antipodal points (where their distance is I<pi>
radians) do not have waypoints between them (they would have an an
"equator" between them), and therefore C<undef> is returned for
antipodal points. If the points are the same and the distance
therefore zero and all waypoints therefore identical, the first point
(either point) is returned.
The thetas, phis, direction, and distance in the above are all in radians.
You can import all the great circle formulas by
use Math::Trig ':great_circle';
Notice that the resulting directions might be somewhat surprising if
you are looking at a flat worldmap: in such map projections the great
circles quite often do not look like the shortest routes -- but for
example the shortest possible routes from Europe or North America to
Asia do often cross the polar regions. (The common Mercator projection
does B<not> show great circles as straight lines: straight lines in the
Mercator projection are lines of constant bearing.)
lib/Math/Trig.pm view on Meta::CPAN
print cos(1e-6)**2+sin(1e-6)**2 - 1,"\n";
printf "%.20f", cos(1e-6)**2+sin(1e-6)**2,"\n";
which will print something like this
-1.11022302462516e-16
0.99999999999999988898
even though the expected results are of course exactly zero and one.
The formulas used to compute asin() and acos() are quite sensitive to
this, and therefore they might accidentally slip into the complex
plane even when they should not. To counter this there are two
interfaces that are guaranteed to return a real-valued output.
=over 4
=item asin_real
use Math::Trig qw(asin_real);
lib/Math/Trig.pm view on Meta::CPAN
Saying C<use Math::Trig;> exports many mathematical routines in the
caller environment and even overrides some (C<sin>, C<cos>). This is
construed as a feature by the Authors, actually... ;-)
The code is not optimized for speed, especially because we use
C<Math::Complex> and thus go quite near complex numbers while doing
the computations even when the arguments are not. This, however,
cannot be completely avoided if we want things like C<asin(2)> to give
an answer instead of giving a fatal runtime error.
Do not attempt navigation using these formulas.
L<Math::Complex>
=head1 AUTHORS
Jarkko Hietaniemi <F<jhi!at!iki.fi>>,
Raphael Manfredi <F<Raphael_Manfredi!at!pobox.com>>,
Zefram <zefram@fysh.org>
=head1 LICENSE
( run in 0.257 second using v1.01-cache-2.11-cpan-26ccb49234f )