Computational Geometry Algorithms Library  1.0
Computational Geometry Algorithms Library Documentation
origin.h
Go to the documentation of this file.
1 //
2 // Created by shuttle3468 on 8/2/17.
3 //
4 
5 #ifndef COMPUTGEOALGOS_ORIGIN_H
6 #define COMPUTGEOALGOS_ORIGIN_H
7 
8 #include <iostream>
9 #include <bits/stdc++.h>
10 
11 #define ull unsigned long long
12 #define pb push_back
13 #define mp make_pair
15 #define COLLINEAR 1
16 #define CLOCKWISE 2
17 #define ANTICLOCKWISE 3
18 using namespace std;
19 vector<int> indices;
21 
23 double calcEuclidDistance(pair<double, double> fpoint, pair<double, double> spoint) {
24  double dist;
25  dist = sqrt(pow((fpoint.first-spoint.first),2.0) + pow((fpoint.second-spoint.second),2.0));
26  return dist;
27 }
29 
33 int orientation(pair<double, double> a, pair<double, double> b, pair<double, double> c) {
34  double m1, m2, dif;
35  dif = (b.second - a.second)*(c.first-b.first) - (b.first-a.first)* (c.second - b.second);
36  cout << "Difference in Slopes " << dif<<endl;
37  if(dif == 0) {
38  cout << "COLLINEAR\n";
39  return COLLINEAR;
40  } else if (dif > 0 ) {
41  cout << "CLOCKWISE\n";
42  return CLOCKWISE;
43  } else {
44  cout << "ANTICLOCKWISE\n";
45  return ANTICLOCKWISE;
46  }
47 }
49 
52 bool orderedSort(pair<double,double> &f, pair<double,double> &s) {
53  //cout << "Comparing (" << f.first << ", " << f.second <<")" << " (" << s.first << ", " << s.second <<")" << endl;
54  if(f.first < s.first) {
55  return true;
56  }
57  if (f.first > s.first) {
58  return false;
59  }
60  return f.second<s.second;
61 }
63 
66 bool orderedYSort(pair<double,double> &f, pair<double,double> &s) {
67  if(f.second < s.second) {
68  return true;
69  }
70  if (f.second > s.second) {
71  return false;
72  }
73  return f.first<s.first;
74 }
75 
77 
80 pair<double ,double > P0;
82 
84 
87 bool orderByPolar(pair<double,double> &p1, pair<double,double> &p2){
88  int oValue = orientation(P0,p2,p1);
89  cout << "comparing " << "(" << P0.first << ", " << P0.second <<")" << " "
90  << "(" << p1.first << ", " << p1.second <<")" << " "
91  << "(" << p2.first << ", " << p2.second <<")" <<endl;
92  cout << " The orientation value is " << oValue << endl;
93  if(oValue == 1) {
94  cout << "Result :" << (calcEuclidDistance(P0,p2) >= calcEuclidDistance(P0,p1)) <<endl;
95  return (calcEuclidDistance(P0,p2) < calcEuclidDistance(P0,p1));
96  }
97  return (oValue != 3);
98 }
99 
101 
103 void printVectorData(int len, vector<pair<double, double> > v, string s) {
104  int i;
105  cout << s << v.size() << endl;
106  for(i=0;i<len;i++)
107  cout << v[i].first <<" " << v[i].second <<endl;
108 }
110 
113 vector<pair<double, double> > getData(char *filename) {
114  vector<pair<double, double> > input;
115  double a,b;
116  ifstream in_file;
117  in_file.open(filename);
118  while (in_file.is_open()) {
119  int n;
120  in_file >> n;
121  while(in_file >> a >> b) {
122  input.pb(mp(a,b));
123  }
124  in_file.close();
125  }
126  return input;
127 }
128 #endif //COMPUTGEOALGOS_ORIGIN_H
bool orderByPolar(pair< double, double > &p1, pair< double, double > &p2)
Function to order with respect to polar Coordinates.
Definition: origin.h:87
double calcEuclidDistance(pair< double, double > fpoint, pair< double, double > spoint)
Euclidean Distance.
Definition: origin.h:23
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
#define COLLINEAR
Definition: origin.h:15
vector< pair< double, double > > getData(char *filename)
Extract Data from Input File.
Definition: origin.h:113
bool orderedYSort(pair< double, double > &f, pair< double, double > &s)
Comparator Function Sort by y coordinate.
Definition: origin.h:66
vector< int > indices
Definition: origin.h:19
#define mp
Definition: origin.h:13
void printVectorData(int len, vector< pair< double, double > > v, string s)
Print Function.
Definition: origin.h:103
#define ANTICLOCKWISE
Definition: origin.h:17
#define CLOCKWISE
Definition: origin.h:16
bool orderedSort(pair< double, double > &f, pair< double, double > &s)
Comparator Function.
Definition: origin.h:52