% Largest triangle given n points on a unit circle
% Writing efficient code

% Part 1
  for n=100:50:200
      theta = rand(n,1)*2*pi;  % Angle of random pts on the unit circle
      % Determine how long it takes to compute the largest
      % possible triangle obtained by selecting vertices from the
      % points represented by theta
      A = 0;
      for i=1:n
          for j=1:n
              for k=1:n
                  % theta --> Cartesian
                  c1 = cos(theta(i));
                  s1 = sin(theta(i));
                  c2 = cos(theta(j));
                  s2 = sin(theta(j));
                  c3 = cos(theta(k));
                  s3 = sin(theta(k));
                  % Area using Heron's Formula
                  a = sqrt((c1-c2)^2 + (s1-s2)^2);
                  b = sqrt((c1-c3)^2 + (s1-s3)^2);
                  c = sqrt((c2-c3)^2 + (s2-s3)^2);
                  s = (a+b+c)/2;
                  Aijk = sqrt((s-a)*(s-b)*(s-c)*s);
                  A = max(A,Aijk);
              end
          end
      end
  end
  
% Part 2


% Part 3


% Part 4