Computational Geometry Algorithms Library  1.0
Computational Geometry Algorithms Library Documentation
Macros | Functions | Variables
origin.h File Reference
#include <iostream>
#include <bits/stdc++.h>
Include dependency graph for origin.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ull   unsigned long long
 
#define pb   push_back
 
#define mp   make_pair
 
#define COLLINEAR   1
 
#define CLOCKWISE   2
 
#define ANTICLOCKWISE   3
 

Functions

double calcEuclidDistance (pair< double, double > fpoint, pair< double, double > spoint)
 Euclidean Distance. More...
 
int orientation (pair< double, double > a, pair< double, double > b, pair< double, double > c)
 Orientation. More...
 
bool orderedSort (pair< double, double > &f, pair< double, double > &s)
 Comparator Function. More...
 
bool orderedYSort (pair< double, double > &f, pair< double, double > &s)
 Comparator Function Sort by y coordinate. More...
 
bool orderByPolar (pair< double, double > &p1, pair< double, double > &p2)
 Function to order with respect to polar Coordinates. More...
 
void printVectorData (int len, vector< pair< double, double > > v, string s)
 Print Function. More...
 
vector< pair< double, double > > getData (char *filename)
 Extract Data from Input File. More...
 

Variables

vector< int > indices
 
pair< double,double > P0
 a double value which stores the centre about which polar ordering is to be done More...
 

Macro Definition Documentation

#define ANTICLOCKWISE   3

Macro defined for identifying 3 points that rotate anticlockwise

#define CLOCKWISE   2

Macro defined for identifying 3 points that rotate clockwise

#define COLLINEAR   1

Macro defined for identifying 3 collinear points

#define mp   make_pair

Macro for making my typing life easier

#define pb   push_back

Macro for making my typing life easier

#define ull   unsigned long long

Macro for making my typing life easier

Function Documentation

double calcEuclidDistance ( pair< double, double >  fpoint,
pair< double, double >  spoint 
)

Euclidean Distance.

This function is used to calculate the distance between two points which is $\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$.

23  {
24  double dist;
25  dist = sqrt(pow((fpoint.first-spoint.first),2.0) + pow((fpoint.second-spoint.second),2.0));
26  return dist;
27 }
vector<pair<double, double> > getData ( char *  filename)

Extract Data from Input File.

It extracts Data From a file and stores it in a vector for further calculation. Forms the base for getting Data.

113  {
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 }
#define mp
Definition: origin.h:13
bool orderByPolar ( pair< double, double > &  p1,
pair< double, double > &  p2 
)

Function to order with respect to polar Coordinates.

function used by this algorithm to sort an array of points with respect to the first point in the vector.

87  {
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 }
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
bool orderedSort ( pair< double, double > &  f,
pair< double, double > &  s 
)

Comparator Function.

This function basically compares a pair of elements by the values of their x-coordinate and if x-xoordinate is equal then it checks for equality of y-coordinate

52  {
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 }
bool orderedYSort ( pair< double, double > &  f,
pair< double, double > &  s 
)

Comparator Function Sort by y coordinate.

This function basically compares a pair of elements by the values of their y-coordinate and if x-xoordinate is equal then it checks for equality of x-coordinate

66  {
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 }
int orientation ( pair< double, double >  a,
pair< double, double >  b,
pair< double, double >  c 
)

Orientation.

This function is used to calculate orientation of 3 points namely clockwise, anticlockwise and collinear. The idea here is to to get the difference between slopes of 2 lines by assuming a particular direction as a result the result obtained determines the direction of turn of the three points.

33  {
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 }
#define COLLINEAR
Definition: origin.h:15
#define ANTICLOCKWISE
Definition: origin.h:17
#define CLOCKWISE
Definition: origin.h:16
void printVectorData ( int  len,
vector< pair< double, double > >  v,
string  s 
)

Print Function.

Prints content of the vector. Used for output formatting

103  {
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 }

Variable Documentation

vector<int> indices
pair<double ,double > P0

a double value which stores the centre about which polar ordering is to be done