DGtal  1.5.beta
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 354 of file FrechetShortcut.h.

Member Function Documentation

◆ angleVectVect()

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 578 of file FrechetShortcut.h.

579  {
580  IntegerComputer<Integer> ic;
581  return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
582  }

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

◆ chainCode2Vect()

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 689 of file FrechetShortcut.h.

690  {
691  Vector v;
692  switch(d){
693 
694  case 0:{
695  v[0] = 1;
696  v[1] = 0;
697  break;
698  }
699  case 1:{
700  v[0] = 1;
701  v[1] = 1;
702  break;
703  }
704  case 2:{
705  v[0] = 0;
706  v[1] = 1;
707  break;
708  }
709  case 3:{
710  v[0] = -1;
711  v[1] = 1;
712  break;
713  }
714  case 4:{
715  v[0] = -1;
716  v[1] = 0;
717  break;
718  }
719  case 5:{
720  v[0] = -1;
721  v[1] = -1;
722  break;
723  }
724  case 6:{
725  v[0] = 0;
726  v[1] = -1;
727  break;
728  }
729  case 7:{
730  v[0] = 1;
731  v[1] = -1;
732  break;
733  }
734 
735  }
736 
737  return v;
738  }
DigitalPlane::Point Vector

◆ circle_circle_intersection()

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 400 of file FrechetShortcut.h.

404  {
405  // I. Sivignon 05/2024: fix to handle the case where r0=0 or
406  // r1=0. Enables the case where error=0.
407  // Other special cases where circles are tangent are treated
408  // below.
409  if(r0==0)
410  {
411  *xi = x0; *yi = y0;
412  *xi_prime = x0 ; *yi_prime = y0;
413  return 1;
414  }
415  else
416  if(r1==0)
417  {
418  *xi = x1; *yi = y1;
419  *xi_prime = x1 ; *yi_prime = y1;
420  return 1;
421  }
422 
423  double a, dx, dy, d, h, rx, ry;
424  double x2, y2;
425 
426  /* dx and dy are the vertical and horizontal distances between
427  * the circle centers.
428  */
429  dx = x1 - x0;
430  dy = y1 - y0;
431 
432  /* Determine the straight-line distance between the centers. */
433  //d = sqrt((dy*dy) + (dx*dx));
434  d = hypot(dx,dy); // Suggested by Keith Briggs
435 
436  if((r0+r1)*(r0+r1)-((dy*dy)+(dx*dx)) < PRECISION)
437  { // I. Sivignon 05/2024: fix to handle the case where
438  // circles are tangent but radii are non zero.
439 
440  double alpha= r0/d;
441  *xi = x0 + dx*alpha;
442  *yi = y0 + dy*alpha;
443  *xi_prime = *xi; *yi_prime = *yi;
444  return 1;
445  }
446 
447  /* Check for solvability. */
448  if (d > (r0 + r1))
449  {
450  /* no solution. circles do not intersect. */
451  std::cerr << "Warning : the two circles do not intersect -> should never happen" << std::endl;
452  return 0; //I. Sivignon 05/2010 should never happen for our specific use.
453  }
454  if (d < fabs(r0 - r1))
455  {
456  /* no solution. one circle is contained in the other */
457  return 0;
458  }
459 
460  // }
461  /* 'point 2' is the point where the line through the circle
462  * intersection points crosses the line between the circle
463  * centers.
464  */
465 
466  /* Determine the distance from point 0 to point 2. */
467  a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
468 
469  /* Determine the coordinates of point 2. */
470  x2 = x0 + (dx * a/d);
471  y2 = y0 + (dy * a/d);
472 
473 
474  /* Determine the distance from point 2 to either of the
475  * intersection points.
476  */
477  h = sqrt((r0*r0) - (a*a));
478 
479  /* Now determine the offsets of the intersection points from
480  * point 2.
481  */
482  rx = -dy * (h/d);
483  ry = dx * (h/d);
484 
485  /* Determine the absolute intersection points. */
486  *xi = x2 + rx;
487  *xi_prime = x2 - rx;
488  *yi = y2 + ry;
489  *yi_prime = y2 - ry;
490 
491  return 1;
492  }

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

◆ circleTangentPoints()

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 515 of file FrechetShortcut.h.

517  {
518  double x0 = (x+x1)/2;
519  double y0 = (y+y1)/2;
520  double r0 = sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1))/2;
521 
522  int res =
523  circle_circle_intersection(x0,y0,r0,x1,y1,r1,xi,yi,xi_prime,yi_prime);
524 
525 
526  return res;
527 
528  }
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)

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

◆ computeAngle()

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 540 of file FrechetShortcut.h.

541  {
542  double x = x1-x0;
543  double y = y1-y0;
544 
545  if(x!=0)
546  {
547  double alpha = y/x;
548 
549  if(x>0 && y>=0)
550  return atan(alpha);
551  else
552  if(x>0 && y<0)
553  return atan(alpha)+2*M_PI;
554  else
555  if(x<0)
556  return atan(alpha)+M_PI;
557  }
558  else
559  {
560  if(y==0)
561  return 0;
562  else
563  if(y>0)
564  return M_PI_2;
565  else
566  return 3*M_PI_2;
567  }
568  return -1;
569  }

◆ computeChainCode()

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 589 of file FrechetShortcut.h.

590  {
591  int d;
592  Coordinate x2 = q[0];
593  Coordinate y2 = q[1];
594  Coordinate x1 = p[0];
595  Coordinate y1 = p[1];
596 
597  if(x2-x1==0)
598  if(y2-y1==1)
599  d=2;
600  else
601  d=6;
602  else
603  if(x2-x1==1)
604  if(y2-y1==0)
605  d=0;
606  else
607  if(y2-y1==1)
608  d=1;
609  else
610  d=7;
611  else
612  if(y2-y1==0)
613  d=4;
614  else
615  if(y2-y1==1)
616  d=3;
617  else
618  d=5;
619  return d;
620  }
Vector::Coordinate Coordinate

◆ computeOctant()

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 627 of file FrechetShortcut.h.

628  {
629  int d = 0;
630  Coordinate x = q[0]-p[0];
631  Coordinate y = q[1]-p[1];
632 
633  if(x>=0)
634  {
635  if(y>=0)
636  {
637  if(x>y)
638  d=0; // 0 <= y < x
639  else
640  if(x!=0)
641  d=1; // 0 <= x <= y
642  }
643  else
644  {
645  if(x>=abs(y))
646  d=7; // 0 < abs(y) <= x
647  else
648  d=6; // 0 <= x < abs(y)
649  }
650  }
651  if(x<=0)
652  {
653  if(y>0)
654  if(abs(x)>=y)
655  d=3; //
656  else
657  d=2;
658  else
659  {
660  if(abs(x)>abs(y))
661  d=4;
662  else
663  if(x!=0)
664  d=5;
665  }
666  }
667  return d;
668 
669  }

◆ isBetween()

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 365 of file FrechetShortcut.h.

366  {
367  if(a<=b)
368  return (i>=a && i<=b);
369  else
370  return ((i>=a && i<=n) || (i>=0 && i<=b));
371  }

◆ rot()

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 679 of file FrechetShortcut.h.

680  {
681  return (d-quad+8)%8;
682  }

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