The perl sin and cos functions take arguments in the form of radians (rather than degrees). 180 degrees = Pi radians so both radians and degrees are measures of angle. You question has no answer per se as sin and cos do not return values that can be expressed as any measure of angle like radians or degrees. Hopefully this code covers what you want. The asin, acos and atan functions return radians and are the inverse functions of sin, cos and tan respectively:
my $pi = 3.14159265358979;
sub deg_to_rad { ($_[0]/180) * $pi }
sub rad_to_deg { ($_[0]/$pi) * 180 }
sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) }
sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) }
sub tan { sin($_[0]) / cos($_[0]) }
sub atan { atan2($_[0],1) };
print 'sin 30 degrees is ', sin(deg_to_rad(30)), "\n";
print 'inverse sin 0.5 is ', rad_to_deg(asin(0.5)), ' degrees';
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|