Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the vecotr that holds all input points
- std::vector<Point2d> inputPoints;
- // initialize edge points with any point in the point set
- Point2d mostTopPoint = inputPoints[0];
- Point2d mostRightPoint = inputPoints[0];
- Point2d mostBottomPoint = inputPoints[0];
- Point2d mostLeftPoint = inputPoints[0];
- // first loop over all points from first to last
- for(unsigned int i = 0; i < inputPoints.size(); ++i)
- {
- // the current point that is checked
- Point2d currentPoint = inputPoints[i];
- // check if the point is more top than any other found point
- if(currentPoint.y < mostTopPoint.y)
- mostTopPoint = currentPoint;
- // check if the point is more right than any other found point
- if(currentPoint.x > mostRightPoint.x)
- mostRightPoint = currentPoint;
- // check if the point is more bottom than any other found point
- if(currentPoint.y > mostBottomPoint.y)
- mostBottomPoint = currentPoint;
- // check if the point is more left than any other found point
- if(currentPoint.x < mostLeftPoint.x)
- mostLeftPoint = currentPoint;
- }
- // now the most top/right/bottom/left point should have been found
- // still have to find out which is which corner
- Point2d upLeftCorner;
- Point2d upRightCorner;
- Point2d lowRightCorner;
- Point2d lowLeftCorner;
- // if the mostLeftPoint y coordinate is smaller than the mostRightCorner y coordinate
- // --> the checkerboard is tilted to right (viewers point)
- // --> means most mostTopPoint must be the upLeftCorner
- if(mostLeftPoint.y < mostRightPoint.y)
- {
- upLeftCorner = mostTopPoint;
- // also means the mostRightPoint is the upRightCorner
- upRightCorner = mostRightPoint;
- // also means the mostBottomPoint is the lowRightCorner
- lowRightCorner = mostBottomPoint;
- // also means the mostLeftPoint must be the lowLeftCorner
- lowLeftCorner = mostLeftPoint;
- }
- // otherwise it is tilted to left (viewers point)
- // --> means mostLeftPoint is the upLeftCorner
- else
- {
- upLeftCorner = mostLeftPoint;
- // also means the mostTopPoint is the upRightCorner
- upRightCorner = mostTopPoint;
- // also means the mostRightPoint is the lowRightCorner
- lowRightCorner = mostRightPoint;
- // also means the mostBottomPoint must be the lowLeftCorner
- lowLeftCorner = mostBottomPoint;
- }
Add Comment
Please, Sign In to add comment