There are two types of TV: traditional, having a 4: 3 aspect ratio and widescreen, which are 16: 9. I am trying to write a function that, given the 16: 9 TV diagonal, gives a 4: 3 TV diagonal with an equivalent height. I know that you can use the Pythagorean theorem for this if I know two sides, but I only know the diagonal and the ratio.
I wrote a function that works wondering, but I was wondering if there is a better way.
My attempt:
public static void Main()
{
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;
}
}
}
source
share