Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Advanced Data Types for 2-Dimensional Geometry > Point Sets > Examples

Examples Point Location and Drawing Operations for POINT_SET

The following program illustrates point location and the drawing functions for POINT_SET. A window and functions draw_node() and draw_edge() are defined globally. Inside main() a rat_point_set T is defined using a list S of random rat_points. Then the point (2,3) is located in T. The result is an edge of the face containing (2,3). T, the point (2,3), and the face containing (2,3) are then drawn in a window.

#include <LEDA/core/list.h>
#include <LEDA/geo/rat_point.h>
#include <LEDA/geo/rat_point_set.h>
#include <LEDA/graphics/window.h>

using namespace leda;

static window W;

void draw_node(const rat_point& p) 
{ W.draw_filled_node(p.to_point(),black); }

void draw_edge(const rat_point& p, const rat_point& q) 
{ W.draw_edge(p.to_point(),q.to_point(),black); }

int main()
{
  list<rat_point> S;
  random_points_in_square(10,10,S);

  rat_point_set T(S); //define rat_point_set

  rat_point p(2,3);
  edge e=T.locate(p); //locate rat_point(2,3)

  //open window
  W.init(-11,11,-11);W.open();W.display();

  //draw T using draw_node() and draw_edge()
  T.draw_nodes(draw_node);
  T.draw_edges(draw_edge,draw_edge,draw_edge);
  W.read_mouse();

  //draw p and face containing p
  rat_point p1=T[T.source(e)],p2=T[T.target(e)];
  W.draw_filled_node(p.to_point(),red);

  W.draw_edge(p1.to_point(),p2.to_point(),red);
  edge f=T.face_cycle_succ(e);
  while (f!=e) {
     p1=T[T.source(f)]; p2=T[T.target(f)];
     W.draw_edge(p1.to_point(),p2.to_point(),red);
	 f=T.face_cycle_succ(f);
  }
  W.read_mouse();
 
  return 0;
}

See also:

Point Sets

Data Types for 2D Geometry

Linear Lists

Generators for Geometric Objects

Dictionaries

Windows and Panels

Convex Hulls


Example POINT_SET Functionality


Graphs and Related Data Types

Geometry

Geometry Algorithms


Manual Entries:

Manual Page Point Sets




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