function TR = icosahedron_mesh ( )

%*****************************************************************************80
%
%% icosahedron_mesh() generates a triangular surface mesh of an icosahedron.
%
%  Discussion:
%
%    Generate a triangular surface mesh of an icosahedron whose vertices lie
%    on the surface of a zero-centered unit sphere.
%
%  Modified:
%
%    11 December 2021
%
%  Author:
%
%    Anton Semechko (a.semechko@gmail.com)
%
%  Output:
%
%   - TR    : 'triangulation' object representing an icosahedron
%

% Get the vertex coordinates

%
%  T = golden ratio.
%
  t = ( 1.0 + sqrt ( 5.0 ) ) / 2.0;

  X = [0 1 t];
  s = [1 1 1; 1 1 -1; 1 -1 -1; 1 -1 1];
  X = repmat(X,[4 1]).*s;
  X = [ X; ...
        circshift(X,[0 -1]); ...
        circshift(X,[0 -2])];
  x_L2 = sqrt(sum(X.^2,2));
  X = bsxfun(@rdivide,X,x_L2);
%
% Triangulate the points.
%
  Tri = convhull(X);
  if ( closed_mesh_volume({Tri X}) < 0 )
    Tri = fliplr ( Tri ); 
  end
  TR = triangulation ( Tri, X );

  return
end

