Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. rhoThetaToImageMaxMinLine(const double rho,double theta,number& x1, number& y1,number& x2,number& y2) {
  2.    
  3.   const double  x_orig_mid = rho * std::cos(theta + M_PI);
  4.   const double  y_orig_mid = rho * std::sin(theta + M_PI);
  5.  
  6.   int x = (this->width  / 2)+(x_orig_mid);
  7.   int y = (this->height / 2)+(y_orig_mid);
  8.  
  9.   int top,right,bottom,left = 0;
  10.  
  11.   top    = x + ceil(y           * std::tan( theta ) );
  12.   right  = y + ceil(int(this->width  - x)   * std::tan( theta - (M_PI / 2) ));
  13.   bottom = x - floor(int(this->height - y)  * std::tan( theta - M_PI ));
  14.   left   = y - floor(x          * std::tan( theta - ((M_PI) + (M_PI / 2)) ) );
  15.  
  16.  
  17.  
  18.   this->height--;
  19.   this->width--;//why is this necessary??
  20.  
  21.   if ( top >= 0 && top <= this->width ) {
  22.     x1 = top;
  23.     y1 = 0;
  24.    
  25.     if ( right >= 0 && right <= this->height ) {
  26.      x2 = this->width;
  27.      y2 = right;
  28.     } else {
  29.       if ( bottom < 0 ) {
  30.     x2 = 0;
  31.     y2 = left;
  32.       } else {
  33.         x2 = bottom;
  34.         y2 = this->height;
  35.       }
  36.     }
  37.     #ifdef DEBUGON
  38.     std::cout << "top" << std::endl;
  39.     #endif
  40.   }
  41.  
  42.   if ( right >= 0 && right <= this->height ) { //three quaters
  43.     x1 = this->width;
  44.     y1 = right;
  45.  
  46.     if ( bottom >= 0 && bottom <= this->width ) {
  47.       x2 = bottom;
  48.       y2 = this->height;
  49.     } else {
  50.       if ( left < 0 ) {
  51.     x2 = top;
  52.     y2 = 0;
  53.       } else {
  54.         x2 = 0;
  55.         y2 = left;// + 1;//This gives pixel perfect lines as a result from rouding.
  56.       }
  57.     }
  58.     #ifdef DEBUGON
  59.     std::cout << "right" << std::endl;
  60.     #endif
  61.   }
  62.  
  63.   if ( bottom >= 0 && bottom <= this->width ) {
  64.     x1 = bottom;
  65.     y1 = this->height;
  66.  
  67.     if ( left >= 0 && left <= this->height ) {
  68.       x2 = 0;
  69.       y2 = left;
  70.     } else {
  71.       if ( top > this->width ) {
  72.         x2 = this->width;
  73.     y2 = right ; //+1 else a but arises at rho:245 theta:3.67683 x1:568 y1:767 x2:1023 y2:4294967295
  74.       } else {
  75.     x2 = top;
  76.     y2 = 0;
  77.       }
  78.     }
  79.     #ifdef DEBUGON
  80.     std::cout << "bottom" << std::endl;
  81.     #endif
  82.   }
  83.  
  84.   if ( left >= 0 && left <= this->height ) {
  85.     x1 = 0;
  86.     y1 = left;// - 1;//This gives pixel perfect lines as a result from rouding errors.
  87.  
  88.     if ( top >= 0 && top <= this->width ) {
  89.       x2 = top;
  90.       y2 = 0;
  91.     } else {
  92.       if ( right > this->height ) {
  93.     x2 = bottom;
  94.     y2 = this->height;
  95.       } else {
  96.         x2 = this->width;
  97.         y2 = right;
  98.       }
  99.     }
  100.     #ifdef DEBUGON
  101.     std::cout << "left" << std::endl;
  102.     #endif
  103.   }
  104.  
  105.   if (x2 > this->height ) {
  106.    x2  = this->height - 1;
  107.   }
  108.  
  109.   this->height++;
  110.   this->width++;
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement