DGtal  0.9.2
Static Public Member Functions
DGtal::FrechetShortcut< TIterator, TInteger >::Tools Struct Reference

#include <DGtal/geometry/curves/FrechetShortcut.h>

Static Public Member Functions

static bool isBetween (double i, double a, double b, double n)
 
static int circle_circle_intersection (double x0, double y0, double r0, double x1, double y1, double r1, double *xi, double *yi, double *xi_prime, double *yi_prime)
 
static int circleTangentPoints (double x, double y, double x1, double y1, double r1, double *xi, double *yi, double *xi_prime, double *yi_prime)
 
static double computeAngle (double x0, double y0, double x1, double y1)
 
static double angleVectVect (Vector u, Vector v)
 
static int computeChainCode (Point p, Point q)
 
static int computeOctant (Point p, Point q)
 
static int rot (int d, int quad)
 
static Vector chainCode2Vect (int d)
 

Detailed Description

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
struct DGtal::FrechetShortcut< TIterator, TInteger >::Tools

Definition at line 346 of file FrechetShortcut.h.

Member Function Documentation

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static double DGtal::FrechetShortcut< TIterator, TInteger >::Tools::angleVectVect ( Vector  u,
Vector  v 
)
inlinestatic

Angle between two vectors

Parameters
uand
vtwo vectors
Returns
an angle

Definition at line 544 of file FrechetShortcut.h.

References DGtal::IntegerComputer< TInteger >::dotProduct().

545  {
546  IntegerComputer<Integer> ic;
547  return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
548  }
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static Vector DGtal::FrechetShortcut< TIterator, TInteger >::Tools::chainCode2Vect ( int  d)
inlinestatic

Converts a chain code into a vector

Parameters
dan int
Returns
a vector

Definition at line 655 of file FrechetShortcut.h.

656  {
657  Vector v;
658  switch(d){
659 
660  case 0:{
661  v[0] = 1;
662  v[1] = 0;
663  break;
664  }
665  case 1:{
666  v[0] = 1;
667  v[1] = 1;
668  break;
669  }
670  case 2:{
671  v[0] = 0;
672  v[1] = 1;
673  break;
674  }
675  case 3:{
676  v[0] = -1;
677  v[1] = 1;
678  break;
679  }
680  case 4:{
681  v[0] = -1;
682  v[1] = 0;
683  break;
684  }
685  case 5:{
686  v[0] = -1;
687  v[1] = -1;
688  break;
689  }
690  case 6:{
691  v[0] = 0;
692  v[1] = -1;
693  break;
694  }
695  case 7:{
696  v[0] = 1;
697  v[1] = -1;
698  break;
699  }
700 
701  }
702 
703  return v;
704  }
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circle_circle_intersection ( double  x0,
double  y0,
double  r0,
double  x1,
double  y1,
double  r1,
double *  xi,
double *  yi,
double *  xi_prime,
double *  yi_prime 
)
inlinestatic

Determine the points where two circles in a common plane intersect Parameters: three doubles per circle (center, radius), pointers to the two intersection points

Returns
0 if the circles do not intersect each other, 1 otherwise

Definition at line 401 of file FrechetShortcut.h.

Referenced by DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circleTangentPoints().

405  {
406  double a, dx, dy, d, h, rx, ry;
407  double x2, y2;
408 
409  /* dx and dy are the vertical and horizontal distances between
410  * the circle centers.
411  */
412  dx = x1 - x0;
413  dy = y1 - y0;
414 
415  /* Determine the straight-line distance between the centers. */
416  //d = sqrt((dy*dy) + (dx*dx));
417  d = hypot(dx,dy); // Suggested by Keith Briggs
418 
419  /* Check for solvability. */
420  if (d > (r0 + r1))
421  {
422  /* no solution. circles do not intersect. */
423  std::cerr << "Warning : the two circles do not intersect -> should never happen" << std::endl;
424  return 0; //I. Sivignon 05/2010 should never happen for our specific use.
425  }
426  if (d < fabs(r0 - r1))
427  {
428  /* no solution. one circle is contained in the other */
429  return 0;
430  }
431 
432  /* 'point 2' is the point where the line through the circle
433  * intersection points crosses the line between the circle
434  * centers.
435  */
436 
437  /* Determine the distance from point 0 to point 2. */
438  a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
439 
440  /* Determine the coordinates of point 2. */
441  x2 = x0 + (dx * a/d);
442  y2 = y0 + (dy * a/d);
443 
444  /* Determine the distance from point 2 to either of the
445  * intersection points.
446  */
447  h = sqrt((r0*r0) - (a*a));
448 
449  /* Now determine the offsets of the intersection points from
450  * point 2.
451  */
452  rx = -dy * (h/d);
453  ry = dx * (h/d);
454 
455  /* Determine the absolute intersection points. */
456  *xi = x2 + rx;
457  *xi_prime = x2 - rx;
458  *yi = y2 + ry;
459  *yi_prime = y2 - ry;
460 
461  return 1;
462  }
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circleTangentPoints ( double  x,
double  y,
double  x1,
double  y1,
double  r1,
double *  xi,
double *  yi,
double *  xi_prime,
double *  yi_prime 
)
inlinestatic

Given a point X and a circle of center X1, compute the two points Xi and Xi' of the circle the tangent of which go through X. Since the triangle XXiX1 is a right triangle on Xi, the middle point M between X and X1 is equidistant to X, X1 and Xi. Thus, Xi belongs to the intersection of the circle (X1,r1) and the circle of center M and radius ||XX1||/2.

Parameters
[in]xthe first coordinate of X.
[in]ythe second coordinate of X.
[in]x1the first coordinate of the circle center X1.
[in]y1the second coordinate of the circle center X1.
[in]r1the circle radius.
[out]xipointer to the first coordinate of the first intersection point.
[out]yipointer to the second coordinate of the first intersection point.
[out]xi_primepointer to the first coordinate of the second intersection point.
[out]yi_primepointer to the second coordinate of the second intersection point.
Returns
result of the call to circle_circle_intersection

Definition at line 485 of file FrechetShortcut.h.

References DGtal::FrechetShortcut< TIterator, TInteger >::Tools::circle_circle_intersection().

487  {
488  double x0 = (x+x1)/2;
489  double y0 = (y+y1)/2;
490  double r0 = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1))/2;
491 
492  int res =
493  circle_circle_intersection(x0,y0,r0,x1,y1,r1,xi,yi,xi_prime,yi_prime);
494 
495  return res;
496 
497  }
static int circle_circle_intersection(double x0, double y0, double r0, double x1, double y1, double r1, double *xi, double *yi, double *xi_prime, double *yi_prime)
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static double DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeAngle ( double  x0,
double  y0,
double  x1,
double  y1 
)
inlinestatic

Compute the angle of the line passing through two points. Angle in [0,2pi]

Parameters
x0x0
y0y0
x1x1
y1y1
Returns
an angle

Definition at line 509 of file FrechetShortcut.h.

510  {
511  double x = x1-x0;
512  double y = y1-y0;
513 
514  if(x!=0)
515  {
516  double alpha = y/x;
517 
518  if(x>0 && y>=0)
519  return atan(alpha);
520  else
521  if(x>0 && y<0)
522  return atan(alpha)+2*M_PI;
523  else
524  if(x<0)
525  return atan(alpha)+M_PI;
526  }
527  else
528  {
529  if(y>0)
530  return M_PI_2;
531  else
532  return 3*M_PI_2;
533  }
534  return -1;
535  }
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeChainCode ( Point  p,
Point  q 
)
inlinestatic

Computes the chain code between two 8-connected pixels

Parameters
pand
qtwo points
Returns
an int

Definition at line 555 of file FrechetShortcut.h.

556  {
557  int d;
558  Coordinate x2 = q[0];
559  Coordinate y2 = q[1];
560  Coordinate x1 = p[0];
561  Coordinate y1 = p[1];
562 
563  if(x2-x1==0)
564  if(y2-y1==1)
565  d=2;
566  else
567  d=6;
568  else
569  if(x2-x1==1)
570  if(y2-y1==0)
571  d=0;
572  else
573  if(y2-y1==1)
574  d=1;
575  else
576  d=7;
577  else
578  if(y2-y1==0)
579  d=4;
580  else
581  if(y2-y1==1)
582  d=3;
583  else
584  d=5;
585  return d;
586  }
Vector::Coordinate Coordinate
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::computeOctant ( Point  p,
Point  q 
)
inlinestatic

Computes the octant of the direction pq

Parameters
pand
qtwo points
Returns
an int

Definition at line 593 of file FrechetShortcut.h.

594  {
595  int d = 0;
596  Coordinate x = q[0]-p[0];
597  Coordinate y = q[1]-p[1];
598 
599  if(x>=0)
600  {
601  if(y>=0)
602  {
603  if(x>y)
604  d=0; // 0 <= y < x
605  else
606  if(x!=0)
607  d=1; // 0 <= x <= y
608  }
609  else
610  {
611  if(x>=abs(y))
612  d=7; // 0 < abs(y) <= x
613  else
614  d=6; // 0 <= x < abs(y)
615  }
616  }
617  if(x<=0)
618  {
619  if(y>0)
620  if(abs(x)>=y)
621  d=3; //
622  else
623  d=2;
624  else
625  {
626  if(abs(x)>abs(y))
627  d=4;
628  else
629  if(x!=0)
630  d=5;
631  }
632  }
633  return d;
634 
635  }
Vector::Coordinate Coordinate
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static bool DGtal::FrechetShortcut< TIterator, TInteger >::Tools::isBetween ( double  i,
double  a,
double  b,
double  n 
)
inlinestatic

Determines if i is between a and b in the oriented toric space modulo n

Parameters
ii
aa
bb
nn
Returns
true if i is between a anb d, false otherwise

Definition at line 357 of file FrechetShortcut.h.

358  {
359  if(a<=b)
360  if(i>=a && i<=b)
361  return true;
362  else
363  return false;
364  else
365  {
366  if((i>=a && i<=n) || (i>=0 && i<=b))
367  return true;
368  else
369  return false;
370 
371  }
372  }
template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
static int DGtal::FrechetShortcut< TIterator, TInteger >::Tools::rot ( int  d,
int  quad 
)
inlinestatic

Rotate the chain code d to put it in the frame where the octant 'quad' is treated as the first octant.

Parameters
da chain code
quadthe octant
Returns
an int (the new chain code)

Definition at line 645 of file FrechetShortcut.h.

646  {
647  return (d-quad+8)%8;
648  }

The documentation for this struct was generated from the following file: