DGtal  0.9.4beta
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 345 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 534 of file FrechetShortcut.h.

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

535  {
536  IntegerComputer<Integer> ic;
537  return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
538  }
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 645 of file FrechetShortcut.h.

646  {
647  Vector v;
648  switch(d){
649 
650  case 0:{
651  v[0] = 1;
652  v[1] = 0;
653  break;
654  }
655  case 1:{
656  v[0] = 1;
657  v[1] = 1;
658  break;
659  }
660  case 2:{
661  v[0] = 0;
662  v[1] = 1;
663  break;
664  }
665  case 3:{
666  v[0] = -1;
667  v[1] = 1;
668  break;
669  }
670  case 4:{
671  v[0] = -1;
672  v[1] = 0;
673  break;
674  }
675  case 5:{
676  v[0] = -1;
677  v[1] = -1;
678  break;
679  }
680  case 6:{
681  v[0] = 0;
682  v[1] = -1;
683  break;
684  }
685  case 7:{
686  v[0] = 1;
687  v[1] = -1;
688  break;
689  }
690 
691  }
692 
693  return v;
694  }
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 391 of file FrechetShortcut.h.

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

395  {
396  double a, dx, dy, d, h, rx, ry;
397  double x2, y2;
398 
399  /* dx and dy are the vertical and horizontal distances between
400  * the circle centers.
401  */
402  dx = x1 - x0;
403  dy = y1 - y0;
404 
405  /* Determine the straight-line distance between the centers. */
406  //d = sqrt((dy*dy) + (dx*dx));
407  d = hypot(dx,dy); // Suggested by Keith Briggs
408 
409  /* Check for solvability. */
410  if (d > (r0 + r1))
411  {
412  /* no solution. circles do not intersect. */
413  std::cerr << "Warning : the two circles do not intersect -> should never happen" << std::endl;
414  return 0; //I. Sivignon 05/2010 should never happen for our specific use.
415  }
416  if (d < fabs(r0 - r1))
417  {
418  /* no solution. one circle is contained in the other */
419  return 0;
420  }
421 
422  /* 'point 2' is the point where the line through the circle
423  * intersection points crosses the line between the circle
424  * centers.
425  */
426 
427  /* Determine the distance from point 0 to point 2. */
428  a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
429 
430  /* Determine the coordinates of point 2. */
431  x2 = x0 + (dx * a/d);
432  y2 = y0 + (dy * a/d);
433 
434  /* Determine the distance from point 2 to either of the
435  * intersection points.
436  */
437  h = sqrt((r0*r0) - (a*a));
438 
439  /* Now determine the offsets of the intersection points from
440  * point 2.
441  */
442  rx = -dy * (h/d);
443  ry = dx * (h/d);
444 
445  /* Determine the absolute intersection points. */
446  *xi = x2 + rx;
447  *xi_prime = x2 - rx;
448  *yi = y2 + ry;
449  *yi_prime = y2 - ry;
450 
451  return 1;
452  }
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 475 of file FrechetShortcut.h.

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

477  {
478  double x0 = (x+x1)/2;
479  double y0 = (y+y1)/2;
480  double r0 = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1))/2;
481 
482  int res =
483  circle_circle_intersection(x0,y0,r0,x1,y1,r1,xi,yi,xi_prime,yi_prime);
484 
485  return res;
486 
487  }
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 499 of file FrechetShortcut.h.

500  {
501  double x = x1-x0;
502  double y = y1-y0;
503 
504  if(x!=0)
505  {
506  double alpha = y/x;
507 
508  if(x>0 && y>=0)
509  return atan(alpha);
510  else
511  if(x>0 && y<0)
512  return atan(alpha)+2*M_PI;
513  else
514  if(x<0)
515  return atan(alpha)+M_PI;
516  }
517  else
518  {
519  if(y>0)
520  return M_PI_2;
521  else
522  return 3*M_PI_2;
523  }
524  return -1;
525  }
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 545 of file FrechetShortcut.h.

546  {
547  int d;
548  Coordinate x2 = q[0];
549  Coordinate y2 = q[1];
550  Coordinate x1 = p[0];
551  Coordinate y1 = p[1];
552 
553  if(x2-x1==0)
554  if(y2-y1==1)
555  d=2;
556  else
557  d=6;
558  else
559  if(x2-x1==1)
560  if(y2-y1==0)
561  d=0;
562  else
563  if(y2-y1==1)
564  d=1;
565  else
566  d=7;
567  else
568  if(y2-y1==0)
569  d=4;
570  else
571  if(y2-y1==1)
572  d=3;
573  else
574  d=5;
575  return d;
576  }
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 583 of file FrechetShortcut.h.

584  {
585  int d = 0;
586  Coordinate x = q[0]-p[0];
587  Coordinate y = q[1]-p[1];
588 
589  if(x>=0)
590  {
591  if(y>=0)
592  {
593  if(x>y)
594  d=0; // 0 <= y < x
595  else
596  if(x!=0)
597  d=1; // 0 <= x <= y
598  }
599  else
600  {
601  if(x>=abs(y))
602  d=7; // 0 < abs(y) <= x
603  else
604  d=6; // 0 <= x < abs(y)
605  }
606  }
607  if(x<=0)
608  {
609  if(y>0)
610  if(abs(x)>=y)
611  d=3; //
612  else
613  d=2;
614  else
615  {
616  if(abs(x)>abs(y))
617  d=4;
618  else
619  if(x!=0)
620  d=5;
621  }
622  }
623  return d;
624 
625  }
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 356 of file FrechetShortcut.h.

357  {
358  if(a<=b)
359  return (i>=a && i<=b);
360  else
361  return ((i>=a && i<=n) || (i>=0 && i<=b));
362  }
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 635 of file FrechetShortcut.h.

636  {
637  return (d-quad+8)%8;
638  }

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