Go to the documentation of this file. 1 #ifndef __JGEOMETRY2DTOOLKIT__
2 #define __JGEOMETRY2DTOOLKIT__
40 const double A = a.getX() - b.getX();
41 const double B = a.getY() - b.getY();
42 const double C = c.getX() - b.getX();
43 const double D = c.getY() - b.getY();
45 return (A*D - B*
C) <= 0.0;
104 if (__begin != __end) {
106 for (T i = __begin; i != __end; ++i) {
129 template<
class T,
class JCompare_t>
136 if (__begin != __end) {
138 sort(__begin, __end, compare);
148 for (T
j, k; i != __end; ++i) {
150 for (
j = k = l;
j != __begin &&
getCCW(*i, *
j, *--k); --
j) {}
180 inline bool operator()(
const T& first,
const T& second)
const
182 if (first.getX() == second.getX())
183 return second.getY() > first.getY();
185 return first.getX() > second.getX();
202 inline bool operator()(
const T& first,
const T& second)
const
204 if (first.getX() == second.getX())
205 return second.getY() < first.getY();
207 return first.getX() < second.getX();
238 if (__p == __begin || __p == __end) {
239 return make_pair(__p, __p);
244 reverse(__begin, __p);
253 reverse(__begin, __q);
261 return make_pair(__p, __q);
292 for (++
j, ++(++k); k != __end; ++i, ++
j, ++k) {
293 A +=
j->getX() * (k->getY() - i->getY());
298 A +=
j->getX() * (k->getY() - i->getY());
304 A +=
j->getX() * (k->getY() - i->getY());
306 return 0.5 * fabs(A);
330 T i = __begin,
j = __begin;
332 for (++
j;
j != __end; ++i, ++
j) {
364 if (
distance(__begin,__end2) >= 3) {
366 if (pos.
getX() < __begin->getX()) {
418 static double getDmin(T __begin, T __end,
const double delta)
424 sort(__begin, __end, compareY);
426 for (T i = __begin; i != __end; ++i) {
427 for (T
j = i; ++
j != __end && (
j->getY() - i->getY()) < Dmin; ) {
437 sort(__begin, __end, compareX);
455 const int N =
distance(__begin, __end);
459 double Dmin = numeric_limits<double>::max();
461 for (T i = __begin; i != __end; ++i) {
462 for (T
j = i; ++
j != __end; ) {
480 const double dl = getDmin(__begin, i);
481 const double dr = getDmin(i, __end);
483 const double Dmin = min(dl, dr);
488 while (--il != __begin && i ->getX() - il->getX() < Dmin) {}
489 while (++ir != __end && ir->getX() - i ->getX() < Dmin) {}
491 return min(Dmin, getDmin(++il, ir, Dmin));
508 inline bool operator()(
const T& first,
const T& second)
const
510 return first.getX() < second.getX();
527 inline bool operator()(
const T& first,
const T& second)
const
529 return first.getY() < second.getY();
559 sort(__begin, __end, compareX);
561 return getDmin(__begin, __end);
575 double operator()(T __begin, T __end,
const double delta)
const
581 sort(__begin, __end, compareX);
583 for (T i = __begin; i != __end; ) {
587 for ( ; ++
j != __end && (
j->getX() - i->getX()) < Dmin; ) {}
589 const double d = getDmin(i,
j);
616 sort(__begin, __end, compareX);
618 for (T i = __begin; i != __end; ++i) {
622 while (++
j != __end && (
j->getX() - i->getX()) <= Dmax) {}
629 return make_pair(i,
j);
634 sort(i,
j, compareY);
636 for (T __i = i; __i !=
j; ++__i) {
637 for (T __j = __i; ++__j !=
j && (__j->getY() - __i->getY()) <= Dmax; ) {
642 return make_pair(__i,__j);
647 sort(i,
j, compareX);
652 return make_pair(__end,__end);
std::pair< T, T > operator()(T __begin, T __end) const
Get convex Hull.
Auxiliary class for sorting elements.
JCenter2D(const JVector2D &p0, const JVector2D &p1, const JVector2D &p2)
Constructor.
bool operator()(const T &first, const T &second) const
Compare y-positions of given points.
Auxiliary class for sorting elements.
double operator()(T __begin, T __end, const double delta) const
Get distance beween the closest points within a strip around the median in z.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
bool operator()(const T &first, const T &second) const
Sort criterion for lower hull.
double operator()(T __begin, T __end) const
Get smallest distance between two points.
static const JUpperHull sortUpperHull
Function object for sorting elements.
JVector2D & div(const double factor)
Scale vector.
static double getDmin(T __begin, T __end, const double delta)
Get distance beween the closest points within a strip around the median in x.
double getArea2D(T __begin, T __end)
Get area of a convex polygon.
bool inside2D(T __begin, T __end1, T __end2, const JVector2D &pos)
Check if given point is inside a convex polygon.
JCenter2D(T __begin, T __end)
Constructor.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
static const JCompareX compareX
Function object for sorting elements.
static T getConvexHull2D(T __begin, T __end, JCompare_t compare)
Partition half Hull.
Auxiliary classes and methods for 2D geometrical objects and operations.
JVector2D & add(const JVector2D &vector)
Add vector.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JSmallestDistance2D()
Default constructor.
JCenter2D(const JVector2D &p0, const JVector2D &p1)
Constructor.
bool getCCW(const T &a, const T &b, const T &c)
Check sequence of three points in X-Y plane.
Auxiliary class for sorting elements.
static const JLowerHull sortLowerHull
Function object for sorting elements.
bool operator()(const T &first, const T &second) const
Sort criterion for upper hull.
bool operator()(const T &first, const T &second) const
Compare x-positions of given points.
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
static const JCompareY compareY
Function object for sorting elements.
Auxiliary class for sorting elements.
double getX() const
Get x position.
static const JSmallestDistance2D getSmallestDistance2D
Function object for smallest distance determination.
JConvexHull2D()
Default constructor.
Auxiliary class for determination of smallest distance between pair of 2D points.
Auxiliary class for convex hull determination in X-Y plane.
static double getDmin(T __begin, T __end)
Recursive method to find the smallest distance.
static std::pair< T, T > getPair(T __begin, T __end, const double Dmax)
Get pairs with smaller or equal given maximal distance.
Data structure for vector in two dimensions.