5 #ifndef COMPUTGEOALGOS_JARVISMARCH_H 6 #define COMPUTGEOALGOS_JARVISMARCH_H 9 #include <bits/stdc++.h> 15 void swap(
double &p,
double &q) {
24 void swapElements(pair<double, double> &p, pair<double, double> &q) {
25 swap(p.first, q.first);
26 swap(p.second, q.second);
40 int len, i, current, min = 0, hullLength = 0;
41 len = int(Points.size());
42 double x_min = Points[0].first;
43 pair<double, double> leftMost;
46 for (
int i = 1; i < len; i++)
49 x_min = Points[i].first, min = i;
52 P0 = leftMost = Points[min];
61 for (i = hullLength, current = i; i < len; i++) {
73 }
while (
P0 != leftMost);
75 out_file.open(
"output.ch");
77 out_file << len <<
" " << convex_hull.size() <<
"\n";
78 for (
int i = 0; i < len; i++) {
79 out_file << Points[i].first <<
" " << Points[i].second <<
" 0\n";
81 for (i = 0; i < convex_hull.size(); i++) {
82 out_file << ((i + 1)%len) <<
" ";
bool orderByPolar(pair< double, double > &p1, pair< double, double > &p2)
Function to order with respect to polar Coordinates.
Definition: origin.h:87
void swap(double &p, double &q)
Generic Swap Function.
Definition: JarvisMarch.h:15
vector< int > indices_j
Definition: JarvisMarch.h:13
pair< double,double > P0
a double value which stores the centre about which polar ordering is to be done
Definition: origin.h:80
void swapElements(pair< double, double > &p, pair< double, double > &q)
Point Swap Function.
Definition: JarvisMarch.h:24
vector< pair< double, double > > convex_hull(vector< pair< double, double > > points)
Upper Hull and Lower Hull Algorithm
Definition: Andrews.h:14
void printVectorData(int len, vector< pair< double, double > > v, string s)
Print Function.
Definition: origin.h:103
double execJarvisMarch(vector< pair< double, double > > Points)
Jarvis March Algorithm Implementation
Definition: JarvisMarch.h:39
bool orderedSort(pair< double, double > &f, pair< double, double > &s)
Comparator Function.
Definition: origin.h:52