Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Generators for Geometric Objects > Example Polygon Generators


Example Generators for Polygons

The following program shows how to use the generators for rat_polygons. It defines a rat_circle C1 through the rat_points a,b, and c and uses C1 to generate a regular n-gon P1 with 10 points using reg_n_gon(). Then it generates an n-gon P2 using n_gon(). Finally it generates a Hilbert polygon of order 5. The three polygons are displayed in a window.

#include <LEDA/geo/rat_polygon.h>
#include <LEDA/geo/rat_circle.h>
#include <LEDA/geo/rat_point.h>
#include <LEDA/numbers/rational.h>
#include <LEDA/graphics/window.h>

using namespace leda;

int main()
{ 
  rat_point a(0,50),b(50,0), c(100,50);
  rat_circle C1(a,b,c);
  double epsilon1=0.00001;

  rat_polygon P1=reg_n_gon(10,C1,epsilon1);
  P1.normalize();
  std::cout << P1 << std::endl;

  rat_point d(25,50),e(50,25),f(75,50);
  rat_circle C2(d,e,f);
  double epsilon2=10;
  rat_polygon P2=n_gon(10,C2,epsilon2);
  P2.normalize();
  std::cout << P2 << std::endl;

  rational x1=35,y1=35,x2=65,y2=65;

  rat_polygon P3=hilbert(5,x1,y1,x2,y2);
  P3.normalize();
  std::cout << P3 << std::endl;

  window W(500,500);
  W.open();
  W.draw_polygon(P1.to_float());   
  W.draw_polygon(P2.to_float());
  W.draw_polygon(P3.to_float());
    
  W.display();
  W.read_mouse();

  return 0;
}		

See also:

Data Types for 2D Geometry

Windows


Generators for Geometric Objects

Geometry

Advanced Data types for 2-D geometry

Data Types for 3-D Geometry

Geometry Algorithms

GeoWin


Manual Entries:

Manual Page Point Generators




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH