There are two sorts of TV: Traditional ones that have an aspect ratio of 4:3 and wide screen ones that are 16:9. I am trying to write a function that given the diagonal of a 16:9 TV gives the diagonal of a 4:3 TV with the equivalent height. I know that you can use Pythagoras' theorem to work this out if I know two of the sides, but I only know the diagonal and the ratio.
I have written a function that works by guessing, but I was wondering if there is a better way.
My attempt so far:
// C#
public static void Main()
{
/*
* h = height
* w = width
* d = diagonal
*/
const double maxGuess = 40.0;
const double accuracy = 0.0001;
const double target = 21.5;
double ratio4by3 = 4.0 / 3.0;
double ratio16by9 = 16.0 / 9.0;
for (double h = 1; h < maxGuess; h += accuracy)
{
double w = h * ratio16by9;
double d = Math.Sqrt(Math.Pow(h, 2.0) + Math.Pow(w, 2.0));
if (d >= target)
{
double h1 = h;
double w1 = h1 * ratio4by3;
double d1 = Math.Sqrt(Math.Pow(h1, 2.0) + Math.Pow(w1, 2.0));
Console.WriteLine(" 4:3 Width: {0:0.00} Height: {1:00} Diag: {2:0.00}", w, h, d);
Console.WriteLine("16:9 Width: {0:0.00} Height: {1:00} Diag: {2:0.00}", w1, h1, d1);
return;
}
}
}