http://www.perlmonks.org?node_id=900137

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
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";
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

      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.