diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 1998-06-29 19:28:53 +0300 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-06-30 05:34:06 +0000 |
commit | d54bf66f316184872ac87c4594ab8c34b6dedc9e (patch) | |
tree | 6aa44a3805971b2a53dc364b208a2df7bbee51bf /t | |
parent | f1192ceea6b2a126a4ff3254f91c2bc47c361c71 (diff) | |
download | perl-d54bf66f316184872ac87c4594ab8c34b6dedc9e.tar.gz |
add patch to integrate Math::Trig::Radial into Math::Trig
Message-Id: <199806291328.QAA16916@alpha.hut.fi>
Subject: [PATCH] 5.004_68 (or 5.004_04): radial trig
p4raw-id: //depot/perl@1267
Diffstat (limited to 't')
-rwxr-xr-x | t/lib/trig.t | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/t/lib/trig.t b/t/lib/trig.t index c2bc2a8b5b..09147112c7 100755 --- a/t/lib/trig.t +++ b/t/lib/trig.t @@ -25,7 +25,7 @@ sub near ($$;$) { abs($_[0] - $_[1]) < (defined $_[2] ? $_[2] : $eps); } -print "1..7\n"; +print "1..20\n"; $x = 0.9; print 'not ' unless (near(tan($x), sin($x) / cos($x))); @@ -54,4 +54,103 @@ print "ok 6\n"; print 'not ' unless (near(rad2deg(pi), 180)); print "ok 7\n"; +use Math::Trig ':radial'; + +{ + my ($r,$t,$z) = cartesian_to_cylindrical(1,1,1); + + print 'not ' unless (near($r, sqrt(2))) and + (near($t, deg2rad(45))) and + (near($z, 1)); + print "ok 8\n"; + + ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z); + + print 'not ' unless (near($x, 1)) and + (near($y, 1)) and + (near($z, 1)); + print "ok 9\n"; + + ($r,$t,$z) = cartesian_to_cylindrical(1,1,0); + + print 'not ' unless (near($r, sqrt(2))) and + (near($t, deg2rad(45))) and + (near($z, 0)); + print "ok 10\n"; + + ($x,$y,$z) = cylindrical_to_cartesian($r, $t, $z); + + print 'not ' unless (near($x, 1)) and + (near($y, 1)) and + (near($z, 0)); + print "ok 11\n"; +} + +{ + my ($r,$t,$f) = cartesian_to_spherical(1,1,1); + + print 'not ' unless (near($r, sqrt(3))) and + (near($t, deg2rad(45))) and + (near($f, atan2(sqrt(2), 1))); + print "ok 12\n"; + + ($x,$y,$z) = spherical_to_cartesian($r, $t, $f); + + print 'not ' unless (near($x, 1)) and + (near($y, 1)) and + (near($z, 1)); + print "ok 13\n"; + + ($r,$t,$f) = cartesian_to_spherical(1,1,0); + + print 'not ' unless (near($r, sqrt(2))) and + (near($t, deg2rad(45))) and + (near($f, deg2rad(90))); + print "ok 14\n"; + + ($x,$y,$z) = spherical_to_cartesian($r, $t, $f); + + print 'not ' unless (near($x, 1)) and + (near($y, 1)) and + (near($z, 0)); + print "ok 15\n"; +} + +{ + my ($r,$t,$z) = cylindrical_to_spherical(spherical_to_cylindrical(1,1,1)); + + print 'not ' unless (near($r, 1)) and + (near($t, 1)) and + (near($z, 1)); + print "ok 16\n"; + + ($r,$t,$z) = spherical_to_cylindrical(cylindrical_to_spherical(1,1,1)); + + print 'not ' unless (near($r, 1)) and + (near($t, 1)) and + (near($z, 1)); + print "ok 17\n"; +} + +{ + use Math::Trig 'great_circle_distance'; + + print 'not ' + unless (near(great_circle_distance(0, 0, 0, pi/2), pi/2)); + print "ok 18\n"; + + print 'not ' + unless (near(great_circle_distance(0, 0, pi, pi), pi)); + print "ok 19\n"; + + # London to Tokyo. + my @L = (deg2rad(-0.5), deg2rad(90 - 51.3)); + my @T = (deg2rad(139.8),deg2rad(90 - 35.7)); + + my $km = great_circle_distance(@L, @T, 6378); + + print 'not ' unless (near($km, 9605.26637021388)); + print "ok 20\n"; +} + # eof |