import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

class Solution {
  public static void main(String[] args) {
    Solution s = new Solution();
    double[][] points = new double[][] {{10,1},{10,-1},{-10,1},{-10,-1}};
    points = new double[][] {{-1, -1},{1, -1},{1, 1},{-1, 1}};
    System.out.print(s.find(points));
  }
  public double find(double[][] points) {
    double l = 0;
    double h = Math.PI/2;

    while (l + 0.0000000001< h) {
      //System.out.println(l+","+h);
      double mid1 = l - (l - h) / 2;
      double mid2 = mid1 - (mid1 - h) / 2;
      if (f(points,mid1) < f(points,mid2)) {
        h = mid2;
      } else {
        l = mid1;
      }
    }
    return f(points,h)*f(points,h);
  }

  private double f(double[][] points, double theta) {
    double minx = Double.MAX_VALUE;
    double maxx = Double.MIN_VALUE;
    double miny = Double.MAX_VALUE;
    double maxy = Double.MIN_VALUE;
    for (int i = 0; i < points.length; i++) {
      double x = points[i][0] * Math.cos(theta) - points[i][1] * Math.sin(theta);
      double y = points[i][0] * Math.sin(theta) + points[i][1] * Math.cos(theta);
      minx = Math.min(minx, x);
      miny = Math.min(miny, y);
      maxx = Math.max(maxx, x);
      maxy = Math.max(maxy, y);
    }
    return Math.max(maxx - minx,maxy-miny);
  }

}

results matching ""

    No results matching ""