File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
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 355 of file FrechetShortcut.h.

Member Function Documentation

◆ angleVectVect()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 579 of file FrechetShortcut.h.

580 {
582 return acos((double)ic.dotProduct(u,v)/(u.norm()*v.norm()));
583 }
Aim: On-line computation Computation of the longest shortcut according to the Fréchet distance for a ...

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

◆ chainCode2Vect()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 690 of file FrechetShortcut.h.

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

◆ circle_circle_intersection()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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.

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

Referenced by circleTangentPoints().

◆ circleTangentPoints()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 516 of file FrechetShortcut.h.

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

◆ computeAngle()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 541 of file FrechetShortcut.h.

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

◆ computeChainCode()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 590 of file FrechetShortcut.h.

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

◆ computeOctant()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 628 of file FrechetShortcut.h.

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

◆ isBetween()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 366 of file FrechetShortcut.h.

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

◆ rot()

template<typename TIterator, typename TInteger = typename IteratorCirculatorTraits<TIterator>::Value::Coordinate>
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 680 of file FrechetShortcut.h.

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

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