Guest User

Untitled

a guest
Jul 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1.  
  2. // the vecotr that holds all input points
  3. std::vector<Point2d> inputPoints;
  4.  
  5. // initialize edge points with any point in the point set
  6. Point2d mostTopPoint = inputPoints[0];
  7. Point2d mostRightPoint = inputPoints[0];
  8. Point2d mostBottomPoint = inputPoints[0];
  9. Point2d mostLeftPoint = inputPoints[0];
  10.  
  11.  
  12. // first loop over all points from first to last
  13. for(unsigned int i = 0; i < inputPoints.size(); ++i)
  14. {
  15.     // the current point that is checked
  16.     Point2d currentPoint = inputPoints[i];
  17.    
  18.     // check if the point is more top than any other found point
  19.     if(currentPoint.y < mostTopPoint.y)
  20.         mostTopPoint = currentPoint;
  21.  
  22.     // check if the point is more right than any other found point
  23.     if(currentPoint.x > mostRightPoint.x)
  24.         mostRightPoint = currentPoint;
  25.  
  26.     // check if the point is more bottom than any other found point
  27.     if(currentPoint.y > mostBottomPoint.y)
  28.         mostBottomPoint = currentPoint;
  29.  
  30.     // check if the point is more left than any other found point
  31.     if(currentPoint.x < mostLeftPoint.x)
  32.         mostLeftPoint = currentPoint;
  33.  
  34. }
  35.  
  36. // now the most top/right/bottom/left point should have been found
  37.  
  38. // still have to find out which is which corner
  39. Point2d upLeftCorner;
  40. Point2d upRightCorner;
  41. Point2d lowRightCorner;
  42. Point2d lowLeftCorner;
  43.  
  44.  
  45.  
  46. // if the mostLeftPoint y coordinate is smaller than the mostRightCorner y coordinate
  47. // --> the checkerboard is tilted to right (viewers point)
  48. // --> means most mostTopPoint must be the upLeftCorner
  49. if(mostLeftPoint.y < mostRightPoint.y)
  50. {
  51.     upLeftCorner = mostTopPoint;
  52.     // also means the mostRightPoint is the upRightCorner
  53.     upRightCorner = mostRightPoint;
  54.     // also means the mostBottomPoint is the lowRightCorner
  55.     lowRightCorner = mostBottomPoint;
  56.     // also means the mostLeftPoint must be the lowLeftCorner
  57.     lowLeftCorner = mostLeftPoint;
  58. }
  59. // otherwise it is tilted to left (viewers point)
  60. // --> means mostLeftPoint is the upLeftCorner
  61. else
  62. {
  63.     upLeftCorner = mostLeftPoint;
  64.     // also means the mostTopPoint is the upRightCorner
  65.     upRightCorner = mostTopPoint;
  66.     // also means the mostRightPoint is the lowRightCorner
  67.     lowRightCorner = mostRightPoint;
  68.     // also means the mostBottomPoint must be the lowLeftCorner
  69.     lowLeftCorner = mostBottomPoint;
  70. }
Add Comment
Please, Sign In to add comment