Clear questions and runnable codeget the best and fastest answer PerlMonks

### OT: ASA formula

by rpike (Scribe)
 on Apr 19, 2011 at 15:12 UTC Need Help??
rpike has asked for the wisdom of the Perl Monks concerning the following question:

I have a right triangle (left bottom corner), the bottom side's length, and the right bottom corner's angle. I need to find out what the height of the triangle is. I've been trying a few formulas I found off the web but after calculating I sometimes get negative values returned. Any help would be appreciated. Thanks.

Replies are listed 'Best First'.
Re: OT: ASA formula
by moritz (Cardinal) on Apr 19, 2011 at 15:27 UTC
I guess you're after
```use POSIX qw/tan/;
\$height = \$width * tan \$angle;
[download]```

given an \$angle in radians between 0 and pi/2 (excluding the boundaries).

Re: OT: ASA formula
by wind (Priest) on Apr 20, 2011 at 05:03 UTC

For a general example of the ASA problem, I just used the formula documented here: Area of Triangles

```use strict;
use warnings;

my \$pi = atan2 0, -1;

my \$angle1 = 90 * \$pi / 180;
my \$angle2 = 30 * \$pi / 180;
my \$side = 6;

my \$angle3 = \$pi - \$angle1 - \$angle2;

my \$height = \$side * sin(\$angle1) * sin(\$angle2) / sin(\$angle3);

print "height = \$height\n";

my \$area = 1/2 * \$side * \$height;

print "area = \$area\n";
[download]```
Re: OT: ASA formula
by rpike (Scribe) on Apr 19, 2011 at 15:56 UTC
Hmmm POSIX..... does that come installed with Perl? If not, how can I tell if it is already installed? If not installed where can I grab it from, etc..,? Right now when I try including use POSIX qw/tan/; the Perl cgi app I have comes back with a cgi error page.
POSIX should be installed because it is a Core module, and has been for a long time:
```\$ perl -MPOSIX=tan -e 1

\$ corelist POSIX

POSIX was first released with perl 5
[download]```

There is of course also Math::Trig (in fact the POSIX entry for tan() also references this).

It also is part of Perl's core distribution, but if your administrator has been doing things to the distribution (which might account for your error), then all bets are off.

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://900137]
Approved by philipbailey
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-11-24 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (353 votes). Check out past polls.

Notices?