title: How to best sort the corners of a rectangle without knowing the width or height?
body: <p>I have four coordinates of a detected rectangle. I want to find out which of these is the top left, top right , bottom left and bottom right points.
  The method I have written myself is (unnecessarily) long and hasn't actually worked (possibly because I made a mistake somewhere). Either way I'm sure there is an easier way but I can't find a method using google. So any help would be appreciated.</p>
  
  <p>My method is to find the corners with max y(most-top), min y(most-bottom), max x(most-right), min x (most-left). And then if the most-left.y > the most-right.y then the top left point is most-left, top right is most-top etc.
  Is this method correct? And is there an easier way?</p>
  
  <p>My code, sorry its messy and confusing... squareX[0] is first x coordinate squareY[0] is first y coordinate etc. </p>
  
  <p>Edit: Turns out my method is fine its just max() doesn't do what I thought it did (return the max number out off all the numbers entered).</p>
  
  <pre><code>            maxx = max(squareX[0], squareX[1], squareX[2], squareX[3]);
              maxy = max(squareY[0], squareY[1], squareY[2], squareY[3]);
              minx = min(squareX[0], squareX[1], squareX[2], squareX[3]);
              miny = min(squareY[0], squareY[1], squareY[2], squareY[3]);
  
              if (squareX[0] == maxx)
              {
                  mx = 0;
              }
              if (squareX[1] == maxx)
              {
                  mx = 1;
              }
              if (squareX[2] == maxx)
              {
                  mx = 2;
              }
              if (squareX[3] == maxx)
              {
                  mx =3;
              }
  
              if (squareX[0] == minx)
              {
                  mix = 0;
              }
              if (squareX[1] == minx)
              {
                  mix = 1;
              }
              if (squareX[2] == minx)
              {
                  mix = 2;
              }
              if (squareX[3] == minx)
              {
                  mix = 3;
              }
  
              if (squareY[0] == maxy)
              {
                  my = 0;
              }
              if (squareY[1] == maxy)
              {
                  my = 1;
              }
              if (squareY[2] == maxy)
              {
                  my = 2;
              }
              if (squareY[3] == maxy)
              {
                  my = 3;
              }
  
              if (squareY[0] == miny)
              {
                  miy = 0;
              }
              if (squareY[1] == miny)
              {
                  miy = 1;
              }
              if (squareY[2] == miny)
              {
                  miy = 2;
              }
              if (squareY[3] == miny)
              {
                  miy = 3;
              }
  
              if (squareY[mix] &gt; squareY[mx])
              {
                  Pt1.x = squareX[mix];
                  Pt1.y = squareY[mix];
                  Pt2.x = squareX[my];
                  Pt2.y = squareY[my];
                  Pt3.x = squareX[mx];
                  Pt3.y = squareY[mx];
                  Pt4.x = squareX[miy];
                  Pt4.y = squareY[miy];
              }
              else
              {
                  Pt1.x = squareX[my];
                  Pt1.y = squareY[my];
                  Pt2.x = squareX[mx];
                  Pt2.y = squareY[mx];
                  Pt3.x = squareX[miy];
                  Pt3.y = squareY[miy];
                  Pt4.x = squareX[mix];
                  Pt4.y = squareY[mix];
              }
  </code></pre>
  
  <p>Thanks</p>