The Width of a Point SetWhat is the Width of a Point Set?The width of a setL of points is the minimal stripe containing all
points in L . A stripe is the region between two parallel lines.
The function RAT_TYPE WIDTH(const list<POINT>& L, LINE& l1, LINE& l2) assumes that We use the notation The algorithm essentially computes the convex
hull to compute the width of Running Time: The asymptotic running time is the same as for computing
the convex hull of Example
#include <LEDA/core/list.h> #include <LEDA/geo/rat_point.h> #include <LEDA/geo/random_rat_point.h> #include <LEDA/graphics/window.h> #include <LEDA/geo/geo_alg.h> using namespace leda; int main() { list<rat_point> L;random_points_in_square(100,50,L); rat_line l1, l2; rational w=WIDTH(L,l1,l2); window W;W.init(-150,110,-150); W.open(); W.display(); W.set_line_width(3); W.set_node_width(3); rat_point p; //draw points in L forall(p,L) {W.draw_filled_node(p.to_point());} W.read_mouse(); //draw l1 and l2 in red W.draw_line(l1.to_line(),red); W.draw_line(l2.to_line(),red); W.read_mouse(); W.screenshot("width"); return 0; } |
See also:Writing Kernel Independent Code Manual Entries |