title: Function for calculating variance of aspect ratio of rectangles
body: <p>How to implement a function that evaluates the variance of the aspect ratio of two given rectangles</p>
  <p>The attached picture has some rectangles.</p>
  <p>To me as a person it seems that the difference in aspect ratio between rectangle <code>B</code> and rectangle <code>C</code> is the same as the variance between rectangle <code>C</code> and rectangle <code>D</code>, but numerically the difference between <code>B</code> and <code>C</code> is <code>0.34</code> while the difference between <code>C</code> and <code>D</code> is <code>0.5</code>.</p>
  <p>How can one know in a programming and mathematical way that rectangle <code>B</code> is similar to rectangle C and equally rectangle <code>D</code> is similar to rectangle <code>C</code>?</p>
  <p>It can also be said that rectangle <code>A</code> is similar to rectangle <code>B</code> in the same way that rectangle <code>D</code> is similar to rectangle <code>E</code>, because the variance of their aspect ratio is the same, But numerically it does not work out, because the difference between <code>A</code> and <code>B</code> is <code>0.16</code>, and the difference between <code>D</code> and <code>E</code> is <code>0.5</code>.</p>
  <p><a href="https://i.stack.imgur.com/jL2cR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jL2cR.png" alt="enter image description here" /></a></p>
  <p>This is the code I was trying to write, there are two approaches here, that I knew how to start but I do not know how to continue to implement them.</p>
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Rectangle A, B, C, D, E;
                
          // First approach
          double maxDiff = ???;
          Console.WriteLine(IsSimilar(B, C, maxDiff)); // True
  
          // Second approach
          Console.WriteLine(GetDifference(B, C) == GetDifference(C, D)); // True
      }
  
      // -------------- First approach --------------
      public static bool IsSimilar(Rectangle rectangle1, Rectangle rectangle2, double maxDiff)
      {
          var score1 = GetRatioScore(rectangle1);
          var score2 = GetRatioScore(rectangle2);
          return Math.Abs(score1 - score2) &lt;= maxDiff;
      }
  
      private static double GetRatioScore(Rectangle rectangle)
      {
          ...
          return ...
      }
  
      // -------------- Second approach --------------
      public static double GetDifference(Rectangle rectangle1, Rectangle rectangle2)
      {
          var ratio1 = rectangle1.Width / rectangle1.Height;
          var ratio2 = rectangle2.Width / rectangle2.Height;
          ...
          return ...
      }
  }
  </code></pre>
  <p><strong>EDIT</strong></p>
  <p>Note that the direction of the rectangle is involved in the calculation, so that rectangle <code>A</code> and rectangle <code>E</code> are completely different and not equal in their aspect ratio.</p>