function voronoi_city ( )

%*****************************************************************************80
%
%% VORONOI_CITY shows how a Voronoi diagram for three points can be drawn.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 June 2016
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'VORONOI_CITY:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Demonstrate the determination of a Voronoi diagram for\n' );
  fprintf ( 1, '  a set of 3 points, which we think of as cities A, B and C.\n' );
  fprintf ( 1, '  Draw a road between each city.\n' );
  fprintf ( 1, '  Draw the perpendicular bisector to each road.\n' );
  fprintf ( 1, '  Each city''s region is built from pieces of bisectors.\n' );
%
%  Define the city locations within [0,10] x [0,10].
%
  p = zeros ( 3, 2 );

  p(1,1:2) = [ 3.0,  4.0 ];
  p(2,1:2) = [ 7.0,  8.0 ];
  p(3,1:2) = [ 7.0,  2.0 ];
%
%  PLOT 1: Cities A and B.
%
  figure ( 1 )
  plot ( p(1:2,1), p(1:2,2), 'r.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Cities A and B' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city01.png';
  print ( '-dpng', filename );
%
%  PLOT 2: Cities A and B and Road Between Them.
%
  figure ( 2 )
  plot ( p(1:2,1), p(1:2,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Add road AB' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city02.png';
  print ( '-dpng', filename );
%
%  PLOT 3: Cities A and B and Road Between Them and Bisector
%
  figure ( 3 )

  plot ( p(1:2,1), p(1:2,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Split road AB' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city03.png';
  print ( '-dpng', filename );
%
%  PLOT 4: Cities A and B and C
%
  figure ( 4 )

  plot ( p(1:3,1), p(1:3,2), 'r.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Add city C' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city04.png';
  print ( '-dpng', filename );
%
%  PLOT 5: Cities A and B and C and road AC
%
  figure ( 5 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.0, 7.0 ], [ 4.0, 2.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Add road AC' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city05.png';
  print ( '-dpng', filename );
%
%  PLOT 6: Cities A and B and C and bisector of AC
%
  figure ( 6 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.0, 7.0 ], [ 4.0, 2.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.5, 8.5 ], [ 0.0, 10.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Split road AC' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city06.png';
  print ( '-dpng', filename );
%
%  PLOT 7: Cities A and B and C and road BC
%
  figure ( 7 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.0, 7.0 ], [ 4.0, 2.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.5, 8.5 ], [ 0.0, 10.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 7.0, 7.0 ], [ 2.0, 8.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Add road BC' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city07.png';
  print ( '-dpng', filename );
%
%  PLOT 8: Cities A and B and C and bisect BC
%
  figure ( 8 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 3.0, 7.0 ], [ 4.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.0, 7.0 ], [ 4.0, 2.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.5, 8.5 ], [ 0.0, 10.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 7.0, 7.0 ], [ 2.0, 8.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 0.0, 10.0 ], [ 5.0, 5.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Split road BC' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city08.png';
  print ( '-dpng', filename );
%
%  PLOT 9: Cities A and B and C, drop roads, keep bisectors.
%
  figure ( 9 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 1.0, 10.0 ], [ 10.0, 1.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 3.5, 8.5 ], [ 0.0, 10.0 ], 'Color', 'b', 'LineWidth', 3 );
  line ( [ 0.0, 10.0 ], [ 5.0, 5.0 ], 'Color', 'b', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Show all splitting lines' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city09.png';
  print ( '-dpng', filename );
%
%  PLOT 10: Regions
%
  figure ( 10 )

  plot ( p(1:3,1), p(1:3,2), 'b.', 'MarkerSize', 40 );
  line ( [ 0.0, 10.0, 10.0, 0.0, 0.0 ], [ 0.0, 0.0, 10.0, 10.0, 0.0 ], ...
    'Color', 'k', 'LineWidth', 3 );
  text ( p(1,1) - 0.25, p(1,2) + 0.5, 'A', 'FontSize', 16 );
  text ( p(2,1) - 0.25, p(2,2) + 0.5, 'B', 'FontSize', 16 );
  text ( p(3,1) - 0.25, p(3,2) + 0.5, 'C', 'FontSize', 16 );
  line ( [ 1.0, 6.0 ], [ 10.0, 5.0 ], 'Color', 'r', 'LineWidth', 3 );
  line ( [ 3.5, 6.0 ], [ 0.0, 5.0 ], 'Color', 'r', 'LineWidth', 3 );
  line ( [ 6.0, 10.0 ], [ 5.0, 5.0 ], 'Color', 'r', 'LineWidth', 3 );
  axis ( [ 0.0, 10.0, 0.0, 10.0 ] )
  title ( 'Voronoi Diagram for A, B, C' );
  axis equal
  axis off
  drawnow
  filename = 'voronoi_city10.png';
  print ( '-dpng', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'voronoi_city():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end

