polygon.c
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 1k
Development Platform:

MultiPlatform

  1. #include <LEDA/plane.h>
  2. #include <LEDA/window.h>
  3. main()
  4. { window W;
  5.   int grid_mode = 0;
  6.   panel p("polygon");
  7.   p.text_item("This program demonstrates the intersection operation  ");
  8.   p.text_item("for simple polygons (data type polygon). Use the left ");
  9.   p.text_item("mouse button to define the vertex sequence of a simple");
  10.   p.text_item("polygon P in clockwise order. Terminate the input with");
  11.   p.text_item("the middle button. Now, for each next drawn polygon Q ");
  12.   p.text_item("the intersection with P (list of polygons) is computed");
  13.   p.text_item("and displayed. Terminate the program by clicking the  ");
  14.   p.text_item("right button.");
  15.   p.int_item("grid",grid_mode,0,50,10);
  16.   p.button("continue");
  17.   p.open();
  18.   W.init(0,1000,0,grid_mode);
  19.   polygon P;
  20.   W >> P;
  21.   W.draw_polygon(P,blue);
  22.   W.message(string("AREA = %f",P.area()));
  23.   W.set_mode(xor_mode);
  24.   polygon Q;
  25.   while (W >> Q)
  26.   { W << Q;
  27.     list<polygon> L = P.intersection(Q);
  28.     polygon R;
  29.     forall(R,L) W.draw_filled_polygon(R,red);
  30.     W.read_mouse();
  31.     W << Q;
  32.     forall(R,L) W.draw_filled_polygon(R,red);
  33.    }
  34.   W.set_node_width(2);
  35.   for(int i=0; i<1000; i++)
  36.   { point p(rand_int(0,1000),rand_int(0,1000));
  37.     if (P.inside(p)) W.draw_filled_node(p,red);
  38.     if (P.outside(p)) W.draw_point(p,blue);
  39.    }
  40.   W.read_mouse();
  41.  return 0;
  42. }