title: Get center of a square based on the 4 corners
body: <p>I have a problem with my code, which should give me the center of a square. The square is saved as it's corners in an double[][] array. </p>
  
  <pre><code>static double[] getMid(double[][] points){
      double[] mid = new double[2];
      double a = Math.sqrt( (points[0][0] - points[1][0]) * (points[0][0] - points[1][0]) 
                          + (points[0][1] - points[1][1]) * (points[0][1] - points[1][1]) );
      a/=2;
      double c = a / Math.sin(Math.toRadians(45));
  
      mid[0] = Math.sin(Math.toRadians(45)) * c + points[1][0];
      mid[1] = Math.cos(Math.toRadians(45)) * c + points[1][1];
  
      StdDraw.point(mid[0], mid[1]);
  
      return mid;
  }
  </code></pre>
  
  <p>My initial idea was to calculate the distance of the center and the corner and then calculate the centerpoint with the distance and the angle. 
  This works fine when the square is in a normal position, but once it's rotated the center is way off. </p>
  
  <p><img src="https://i.stack.imgur.com/xQk9Y.png" alt="The dots represent the calculated centers."></p>
  
  <p>The dots represent the calculated centers.</p>