#Triangles By Dale Swanson April 14 2007
#Given the diagonal distance and ratio of width to length of a rectangle this will give the length and width
#Mainly used for finding the screen size from the diagonal size
use strict;
use warnings;
my $x; #general varibles
my $y;
my $z;
my $dia; #the diagonal distance
my $sdia; #the square of the diagonal
my $ratio; #ratio between width and length
my $sratio; #square of the ratio between width and length
my $wid; #width
my $len; #length
my $swid; #square of width
my $slen; #square of length
print "\nThis will give you the width and length of a rectangle, given the diagonal, and the ratio of the sides.";
print "\nThe ratio is in the form of w * r = l, common ratios are:
5:4, 1280x1024 = 1.25
4:3, 800x600, 1024x768 = 1.33
16:10, 1280x800 = 1.6
16:9, 1280x720, 1920x1080 = 1.78";
print "\nEnter the diagonal ";
$dia = ;
print "\nEnter the ratio ";
$ratio = ;
#the following forumlas are used to figure out the length and width from the diagonal and ratio
# a^2 + b^2 = c^2
#x + y = z
#x * r = y
#x = z / (r + 1)
#this last one is key, you can find the width by dividing the sum of the width and length by the ratio plus 1
$sratio = $ratio ** 2; #gets the square ratio, which is just the ratio sqaure, but it is still the ratio between the squared width and length
$sdia = $dia ** 2; #gets the square diagonal
$swid = $sdia / ($sratio + 1); #as in the last forumla, the width is found by dividing the diagonal (sum), by the ratio plus 1
$slen = $sdia - $swid; #the length is whatever the sum minus the width is
$wid = sqrt($swid); #now we have the squares of the length and width, get the square roots to get our answers
$len = sqrt($slen);
printf "\nWidth is %.2f and length is %.2f ", $wid, $len;