Jpp
Classes | Typedefs | Functions | Variables
JGEOMETRY2D Namespace Reference

Auxiliary classes and methods for 2D geometrical objects and operations. More...

Classes

class  JAngle2D
 Data structure for angle in two dimensions. More...
 
class  JAxis2D
 Axis object. More...
 
class  JCenter2D
 Center. More...
 
class  JCircle2D
 Data structure for circle in two dimensions. More...
 
class  JConvexHull2D
 Auxiliary class for convex hull determination in X-Y plane. More...
 
class  JDirection2D
 Data structure for direction in two dimensions. More...
 
class  JEigenValues2D
 Eigen values in 2D. More...
 
class  JOmega2D
 Direction set covering (part of) circle. More...
 
struct  JOmega2D_t
 Base class for direction set. More...
 
class  JPosition2D
 Data structure for position in two dimensions. More...
 
class  JRotation2D
 Rotation matrix. More...
 
class  JRotator2D
 Rotation set. More...
 
class  JSegment2D
 Line segment in two dimensions. More...
 
class  JSmallestDistance2D
 Auxiliary class for determination of smallest distance between pair of 2D points. More...
 
class  JVector2D
 Data structure for vector in two dimensions. More...
 
class  JVersor2D
 Data structure for normalised vector in two dimensions. More...
 

Typedefs

typedef std::vector< JRotation2DJRotator2D_t
 Type definition of rotation set. More...
 
typedef std::pair< JPosition2D, JPosition2DJSegment2D_t
 Type definition of line segment in two dimensions. More...
 
typedef JTOOLS::JRange< double > JRangeX
 Type definition of range along x-axis. More...
 
typedef JTOOLS::JRange< double > JRangeY
 Type definition of range along y-axis. More...
 

Functions

void randomize (JPosition2D *p)
 Randomize position. More...
 
template<class T >
bool getCCW (const T &a, const T &b, const T &c)
 Check sequence of three points in X-Y plane. More...
 
template<class T >
double getArea2D (T __begin, T __end)
 Get area of a convex polygon. More...
 
template<class T >
bool inside2D (T __begin, T __end, const JVector2D &pos)
 Check if given point is inside a convex polygon. More...
 
template<class T >
bool inside2D (T __begin, T __end1, T __end2, const JVector2D &pos)
 Check if given point is inside a convex polygon. More...
 
bool getCCW (const JVector2D &a, const JVector2D &b, const JVector2D &c)
 Check sequence of three points. More...
 

Variables

static const JConvexHull2D getConvexHull2D
 Function object for convex hull determination. More...
 
static const JSmallestDistance2D getSmallestDistance2D
 Function object for smallest distance determination. More...
 
static const JVersor2D JVersor2X_t (1, 0)
 unit x-vector More...
 
static const JVersor2D JVersor2Y_t (0, 1)
 unit y-vector More...
 

Detailed Description

Auxiliary classes and methods for 2D geometrical objects and operations.

Author
mdejong

Typedef Documentation

◆ JRotator2D_t

Type definition of rotation set.

Definition at line 23 of file JRotator2D.hh.

◆ JSegment2D_t

Type definition of line segment in two dimensions.

Definition at line 29 of file JSegment2D.hh.

◆ JRangeX

Type definition of range along x-axis.

Definition at line 22 of file JVector2D.hh.

◆ JRangeY

Type definition of range along y-axis.

Definition at line 23 of file JVector2D.hh.

Function Documentation

◆ randomize()

void JGEOMETRY2D::randomize ( JPosition2D p)
inline

Randomize position.

Parameters
ppointer to valid object

Definition at line 28 of file JGeometry2DTestkit.hh.

29  {
30  new (p) JPosition2D(getRandom<double>(-1.0, +1.0),
31  getRandom<double>(-1.0, +1.0));
32  };

◆ getCCW() [1/2]

template<class T >
bool JGEOMETRY2D::getCCW ( const T &  a,
const T &  b,
const T &  c 
)
inline

Check sequence of three points in X-Y plane.

Parameters
a1st point
b2nd point
c3rd point
Returns
true if points a, b, c are counter clockwise; else false

Definition at line 36 of file JGeometry2DToolkit.hh.

39  {
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();
44 
45  return (A*D - B*C) <= 0.0;
46  }

◆ getArea2D()

template<class T >
double JGEOMETRY2D::getArea2D ( __begin,
__end 
)
inline

Get area of a convex polygon.

Parameters
__beginbegin of data
__endend of data
Returns
area

Definition at line 280 of file JGeometry2DToolkit.hh.

281  {
282  using namespace std;
283 
284  if (distance(__begin,__end) >= 3) {
285 
286  double A = 0.0;
287 
288  T i, j, k;
289 
290  i = j = k = __begin;
291 
292  for (++j, ++(++k); k != __end; ++i, ++j, ++k) {
293  A += j->getX() * (k->getY() - i->getY());
294  }
295 
296  k = __begin;
297 
298  A += j->getX() * (k->getY() - i->getY());
299 
300  ++i;
301  j = k;
302  ++k;
303 
304  A += j->getX() * (k->getY() - i->getY());
305 
306  return 0.5 * fabs(A);
307 
308  } else {
309 
310  return 0.0;
311  }
312  }

◆ inside2D() [1/2]

template<class T >
bool JGEOMETRY2D::inside2D ( __begin,
__end,
const JVector2D pos 
)
inline

Check if given point is inside a convex polygon.

Parameters
__beginbegin of data
__endend of data
posposition
Returns
true if inside; else false

Definition at line 324 of file JGeometry2DToolkit.hh.

325  {
326  using namespace std;
327 
328  if (distance(__begin,__end) >= 2) {
329 
330  T i = __begin, j = __begin;
331 
332  for (++j; j != __end; ++i, ++j) {
333 
334  if (!getCCW(*i, *j, pos)) {
335  return false;
336  }
337  }
338 
339  j = __begin;
340 
341  return getCCW(*i, *j, pos);
342 
343  } else {
344 
345  return false;
346  }
347  }

◆ inside2D() [2/2]

template<class T >
bool JGEOMETRY2D::inside2D ( __begin,
__end1,
__end2,
const JVector2D pos 
)
inline

Check if given point is inside a convex polygon.

Parameters
__beginbegin of data
__end1end of lower hull
__end2end of upper hull
posposition
Returns
true if inside; else false

Definition at line 360 of file JGeometry2DToolkit.hh.

361  {
362  using namespace std;
363 
364  if (distance(__begin,__end2) >= 3) {
365 
366  if (pos.getX() < __begin->getX()) {
367  return false;
368  }
369 
370  T i = lower_bound(__begin, __end1, pos, JConvexHull2D::sortUpperHull);
371 
372  if (i == __end1) {
373  return false;
374  }
375 
376  T j = i--;
377 
378  if (!getCCW(*i, *j, pos)) {
379  return false;
380  }
381 
382  i = lower_bound(__end1, __end2, pos, JConvexHull2D::sortLowerHull);
383  j = i--;
384 
385  if (j == __end2) {
386  j = __begin;
387  }
388 
389  return getCCW(*i, *j, pos);
390 
391  } else {
392 
393  return false;
394  }
395  }

◆ getCCW() [2/2]

bool JGEOMETRY2D::getCCW ( const JVector2D a,
const JVector2D b,
const JVector2D c 
)
inline

Check sequence of three points.

Parameters
a1st point
b2nd point
c3rd point
Returns
true if points a, b, c are counter clockwise; else false

Definition at line 269 of file JVector2D.hh.

272  {
273  const double A = a.getX() - b.getX();
274  const double B = a.getY() - b.getY();
275  const double C = c.getX() - b.getX();
276  const double D = c.getY() - b.getY();
277 
278  return (A*D - B*C) <= 0.0;
279  }

Variable Documentation

◆ getConvexHull2D

const JConvexHull2D JGEOMETRY2D::getConvexHull2D
static

Function object for convex hull determination.

Definition at line 269 of file JGeometry2DToolkit.hh.

◆ getSmallestDistance2D

const JSmallestDistance2D JGEOMETRY2D::getSmallestDistance2D
static

Function object for smallest distance determination.

Definition at line 660 of file JGeometry2DToolkit.hh.

◆ JVersor2X_t

const JVersor2D JGEOMETRY2D::JVersor2X_t(1, 0)
static

unit x-vector

◆ JVersor2Y_t

const JVersor2D JGEOMETRY2D::JVersor2Y_t(0, 1)
static

unit y-vector

JTOOLS::j
int j
Definition: JPolint.hh:634
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JTOOLS::C
static const double C
Speed of light in vacuum [m/ns].
Definition: JConstants.hh:22
JGEOMETRY2D::JPosition2D
Data structure for position in two dimensions.
Definition: JPosition2D.hh:30
JGEOMETRY2D::getCCW
bool getCCW(const T &a, const T &b, const T &c)
Check sequence of three points in X-Y plane.
Definition: JGeometry2DToolkit.hh:36
std
Definition: jaanetDictionary.h:36
JGEOMETRY2D::JVector2D::getX
double getX() const
Get x position.
Definition: JVector2D.hh:62
JGEOMETRY2D::JVector2D::getY
double getY() const
Get y position.
Definition: JVector2D.hh:73