#include –> Counterclockwiseint orientation(int px,int py,int qx,int qy, int

#include #include #include #include#includeusing namespace std; int n;// A globle point needed for  sorting points with reference// to  the first point Used in compare function of qsort()int px;int py;  vector>points;// A utility function to find next to top in a stackvector nextToTop(stack> &S){    vectortemp;    vectorres;    temp = S.top();    S.pop();    res = S.top();    S.push(temp);    return res;}// A utility function to swap two pointsint swap(int &p1, int &p2){    int temp = p1;    p1 = p2;    p2 = temp;}// A utility function to return square of distance// between p1 and p2int distSq(int p2x,int p2y){    return (px – p2x)*(px – p2x) +          (py – p2y)*(py – p2y);}// To find orientation of ordered triplet (p, q, r).// The function returns following values// 0 –> p, q and r are colinear// 1 –> Clockwise// 2 –> Counterclockwiseint orientation(int px,int py,int qx,int qy, int  rx,int ry){    int val = (qy – py) * (rx – qx) –              (qx – px) * (ry – qy);cout<<"val is"< 0)? 1: 2; // clock or counterclock wise}// A function used by library function qsort() to sort an array of// points with respect to the first pointint fn(  vector& p1,                vector& p2 ) { int p1x=p10; int p1y=p11;int p2x=p20;int p2y=p21;   // Find orientation   int o = orientation(px,py,p1x,p1y,p2x,p2y);  if (o == 0){         cout<<" collinear"<= distSq(p1x,p1y))? 1 : 0;  }if(o==2)   return 1;   if(o==1){    return 0;}}// Prints convex hull of a set of n points.void convexHull(){    cout<<"hi";    vectortemp;   // Find the bottommost point   int ymin = points01;   int min = 0;  for (int i = 1; i < n; i++)   {     int y = pointsi1;     // Pick the bottom-most or chose the left     // most point in case of tie     if ((y < ymin) || (ymin == y &&         pointsi0 < pointsmin0))        ymin = pointsi1, min = i;   }   cout<<"min is"< >S;   S.push(points0);   S.push(points1);   S.push(points2);   // Process remaining n-3 points   for (int i = 3; i < m; i++)   {      // Keep removing top while the angle formed by      // points next-to-top, top, and pointsi makes      // a non-left turn      while (orientation(nextToTop(S)0,nextToTop(S)1, S.top()0,S.top()1, pointsi0,pointsi1) != 2)         S.pop();      S.push(pointsi);   }   // Now stack has the output points, print contents of stack   while (!S.empty())   {       temp = S.top();       cout << "(" << temp0 << ", " << temp1<<")" << endl;       S.pop();   }}// Driver program to test above functionsint main(){   int i,j;  // cin>>n;   int t1,t2;n=8;   vectorvec;  // int** points=new int*n;vec.push_back(0);vec.push_back(3);points.push_back(vec);vec.clear();vec.push_back(2);vec.push_back(4);points.push_back(vec);vec.clear();vec.push_back(2);vec.push_back(1);points.push_back(vec);vec.clear();vec.push_back(3);vec.push_back(3);points.push_back(vec);vec.clear();vec.push_back(0);vec.push_back(0);points.push_back(vec);vec.clear();vec.push_back(3);vec.push_back(1);points.push_back(vec);vec.clear();vec.push_back(1);vec.push_back(5);points.push_back(vec);vec.clear();vec.push_back(3);vec.push_back(4);points.push_back(vec);//cout<>t1;    cin>>t2;    vec.push_back(t1);     vec.push_back(t2);     points.push_back(vec);         vec.clear();  }*/   convexHull();    return 0;}


I'm Eileen!

Would you like to get a custom essay? How about receiving a customized one?

Check it out