Algorithmic Solutions > LEDA > LEDA Guide > Geometry Algorithms > Convex Components > Example

Example Convex Components

The following program generates a Hilbert polygon P1 of order 5 (see also Generators for Geometric Objects) and computes the convex components of P1.

Then it draws the polygon and the edges of the convex components.

On the right there is a screenshot of the program. Clicking on the picture shows the window in original size.

Example of Convex Components
#include <LEDA/core/list.h>
#include <LEDA/geo/rat_point.h>
#include <LEDA/geo/rat_segment.h>
#include <LEDA/geo/rat_gen_polygon.h>
#include <LEDA/graphics/window.h>
#include <LEDA/geo/geo_alg.h>

using namespace leda;

int main()
{
  rational x1=10,y1=10,x2=100,y2=100;

  rat_polygon P1=hilbert(5,x1,y1,x2,y2);

  GRAPH<rat_point,rat_segment> G;
  list<edge> inner_edges, boundary_edges, hole_edges;
  edge edgeOnConvexHull
	  =CONVEX_COMPONENTS(P1,G,inner_edges,boundary_edges,hole_edges);

  window W;
  W.init(0,110,0);
  W.open(); W.display();
  W.set_node_width(2);

  W.draw_polygon(P1.to_polygon());
  W.read_mouse();
  
  edge e;
  forall_edges(e,G) {
    point p=G[G.source(e)].to_point();
    point q=G[G.target(e)].to_point();
    W.draw_segment(p,q,red);
  }
  W.read_mouse();

  W.screenshot("convex_components");

  return 0;
}	     

See also:

Convex Components

Data Types for 2-D Geometry

Generators for Geometric Objects

Windows and Panels

Linear Lists


Geometry Algorithms

Geometry

Graphs and Related Data Types

GeoWin

Number Types


Manual Entries

Manual Page of Geometry Algorithms




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