4 #ifndef COMPUTGEOALGOS_GRAHAMSCANS_H 5 #define COMPUTGEOALGOS_GRAHAMSCANS_H 8 #include <bits/stdc++.h> 12 pair<double , double >
next_to_top(stack<pair<double , double > > S) {
13 pair<double , double > point = S.top();
15 pair<double , double > res = S.top();
30 len = int(Points.size());
31 double y_min = Points[0].second;
32 pair<double, double> temp;
33 for (
int i = 1; i < len; i++)
35 double y = Points[i].second;
36 if ((y < y_min) || (y_min == y &&
37 Points[i].first < Points[min].first))
38 y_min = Points[i].second, min = i;
42 Points[min] = Points[0];
45 out_file.open(
"output.ch");
47 out_file << len <<
" ";
50 Points.erase(Points.begin());
53 len = int(Points.size());
58 convex_hull.push(Points[0]);
59 convex_hull.push(Points[1]);
63 for (i = 2; i < len; i++) {
65 if (convex_hull.size() < 3) {
break;}
69 convex_hull.push(Points[i]);
70 indices_g.push(i + 1);
72 cout << convex_hull.size() << endl;
73 out_file << convex_hull.size() <<
"\n";
74 out_file <<
P0.first <<
" " <<
P0.second << endl;
75 for(
int i=0;i < len;i++) {
76 out_file << Points[i].first <<
" " << Points[i].second <<
" 0\n";
78 while (!indices_g.empty()) {
79 out_file << indices_g.top() <<
" ";
82 while (!convex_hull.empty())
84 pair<double , double > point = convex_hull.top();
85 cout << point.first <<
" " << point.second << endl;
pair< double, double > next_to_top(stack< pair< double, double > > S)
Definition: GrahamScans.h:12
bool orderByPolar(pair< double, double > &p1, pair< double, double > &p2)
Function to order with respect to polar Coordinates.
Definition: origin.h:87
int orientation(pair< double, double > a, pair< double, double > b, pair< double, double > c)
Orientation.
Definition: origin.h:33
pair< double,double > P0
a double value which stores the centre about which polar ordering is to be done
Definition: origin.h:80
double execGrahamScans(vector< pair< double, double > > Points)
Graham Scans Algorithm Implementation
Definition: GrahamScans.h:26
vector< pair< double, double > > convex_hull(vector< pair< double, double > > points)
Upper Hull and Lower Hull Algorithm
Definition: Andrews.h:14