in reply to Compute Angles of a Right Triangle

Unless my trig fails me, something like this should work. I converted to degrees, but you could use Math::Trig::Degrees, too.
use strict; use Math::Trig; my @lengths = (3,4,5); my @slengths = sort {$a <=> $b} @lengths; my $a1 = atan($slengths[1]/$slengths[0]) * 180/3.141592653589; my $a2 = 90 - $a1; print "Angles are $a1, $a2\n";
HTH, --traveler

Replies are listed 'Best First'.
Re: Re: Compute Angles of a Right Triangle
by ysth (Canon) on Dec 11, 2003 at 02:54 UTC
    That's a nice solution. To comment on it a little, the sort finds the two shortest sides (so the hypotenuse is ignored). atan computes the the arctangent.

    Math::Trig is bundled with perl, but if you wanted to use a builtin, you could use atan2 instead, passing the two sides as separate arguments.

    That isn't as acurate a value of pi as possible. 3.14159265359 is closer (since the digits following 89 are 7932). You can use 4*atan2(1,1) to get a value with accuracy commensurate with your perl's floating point accuracy.

      You can use 4*atan2(1,1) to get ... [pi]

      Or, since atan2() is properly ranged from -pi to pi, you can use atan2(0,-1) and forego the multiplication