Navigation: Up, Table of Contents, Bibliography, Index, Title Page

All Furthest Neighbors

This section describes a function to compute all furthest neighbors for the vertices of a convex polygon $P$, i.e. for each vertex $v$ of $P$ a vertex $f_v$ of $P$ such that the distance between $v$ and $f_v$ is maximized.

#include <CGAL/all_furthest_neighbors_2.h>

template < class RandomAccessIC, class OutputIterator, class Traits >
OutputIterator
CGAL_all_furthest_neighbors (
RandomAccessIC points_begin,
RandomAccessIC points_end,
OutputIterator o,
Traits t = Default_traits)

computes all furthest neighbors for the vertices of the convex polygon described by the range [points_begin, points_end), writes their indices (relative to points_begin) to o[^1] and returns the past-the-end iterator of this sequence.

Precondition

  1. If t is specified explicitly, Traits satisfies the requirements stated in section reference arrow,
  2. Value type of RandomAccessIC is Traits::Point_2 or - if t is not specified explicitly - CGAL_Point_2<R> for some representation class R,
  3. OutputIterator accepts int as value type and
  4. the points denoted by the non-empty range [points_begin, points_end) form the boundary of a convex polygon P (oriented clock- or counterclockwise).

Implementation

The implementation uses monotone matrix search[AKM+87] (see also section reference arrow). Its runtime complexity is linear in the number of vertices of P.

Example

The following code generates a random convex polygon p with ten vertices, computes all furthest neighbors and writes the sequence of their indices (relative to points_begin) to cout (e.g. a sequence of 4788911224 means the furthest neighbor of points_begin[0] is points_begin[4], the furthest neighbor of points_begin[1] is points_begin[7] etc.).

#include <CGAL/Cartesian.h>
#include <CGAL/Point_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/random_convex_set_2.h>
#include <CGAL/all_furthest_neighbors_2.h>
#include <CGAL/IO/Ostream_iterator.h>
#include <iostream.h>
#include <vector.h>

typedef double                                 FT;
typedef CGAL_Cartesian< FT >                   R;
typedef CGAL_Point_2< R >                      Point_2;
typedef CGAL_Polygon_traits_2< R >             P_traits;
typedef vector< Point_2 >                      Point_cont;
typedef CGAL_Polygon_2< P_traits, Point_cont > Polygon_2;
typedef CGAL_Random_points_in_square_2<
  Point_2,
  CGAL_Creator_uniform_2< FT, Point_2 > >
Point_generator;
typedef CGAL_Ostream_iterator< int, ostream >  Ostream_iterator;

int
main()
{
  // generate random convex polygon:
  Polygon_2 p;
  CGAL_random_convex_set_2( 10,
                            back_inserter( p),
                            Point_generator( 1));

  // compute all furthest neighbors:
  CGAL_all_furthest_neighbors(
    p.vertices_begin(),
    p.vertices_end(),
    Ostream_iterator( cout));
  cout << endl;

} 


Footnotes

  1. i.e. the furthest neighbor of points_begin[i] is points_begin[i-th number written to o]

Next: Class declaration of
Afn_traits
Navigation: Up, Table of Contents, Bibliography, Index, Title Page
The CGAL Project. 22 January, 1999.