You should be able to do this with just the atan2() function.
I just found
this on google. It explains the math pretty well.
Perldoc has this ...
perldoc -f atan2
atan2 Y,X
Returns the arctangent of Y/X in the range -PI to
PI.
For the tangent operation, you may use the
"Math::Trig::tan" function, or use the familiar
relation:
sub tan { sin($_[0]) / cos($_[0]) }
Here's the start of a script you could use ...
bash-2.03$ cat ./atan2.pl
#!/usr/local/bin/perl -w
use strict;
my $x = defined($_=shift) ? $_ : die "Enter X\n";
my $y = defined($_=shift) ? $_ : die "Enter Y\n";
my $r = atan2( $y, $x );
print "angle = $r radians\n";
bash-2.03$ ./atan2.pl 4 3
angle = 0.643501108793284 radians
| Plankton: 1% Evil, 99% Hot Gas. |
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.