Class which can be called from main and is globally available throughout the code
Definition at line 55 of file jarvis_algorithm.cpp.
◆ Convexhull()
geometry::jarvis::Convexhull::Convexhull |
( |
const std::vector< Point > & | pointList | ) |
|
|
inlineexplicit |
Constructor of given class
- Parameters
-
pointList | list of all points in the space |
n | number of points in space |
Definition at line 66 of file jarvis_algorithm.cpp.
66 {
67 points = pointList;
68 size = points.size();
69 }
◆ getConvexHull()
std::vector< Point > geometry::jarvis::Convexhull::getConvexHull |
( |
| ) |
const |
|
inline |
Creates convex hull of a set of n points. There must be 3 points at least for the convex hull to exist
- Returns
- an vector array containing points in space which enclose all given points thus forming a hull
Definition at line 78 of file jarvis_algorithm.cpp.
78 {
79
80 std::vector<Point> hull;
81
82
83 int leftmost_point = 0;
84 for (int i = 1; i < size; i++) {
85 if (points[i].x < points[leftmost_point].x) {
86 leftmost_point = i;
87 }
88 }
89
90
91
92 int p = leftmost_point, q = 0;
93 do {
94
95 hull.push_back(points[p]);
96
97
98
99
100
101
102 q = (p + 1) % size;
103 for (int i = 0; i < size; i++) {
104
105
106 if (
orientation(points[p], points[i], points[q]) == 2) {
107 q = i;
108 }
109 }
110
111
112
113
114 p = q;
115
116 } while (p != leftmost_point);
117
118 return hull;
119 }
static int orientation(const Point &p, const Point &q, const Point &r)
◆ orientation()
static int geometry::jarvis::Convexhull::orientation |
( |
const Point & | p, |
|
|
const Point & | q, |
|
|
const Point & | r ) |
|
inlinestatic |
This function returns the geometric orientation for the three points in a space, ie, whether they are linear ir clockwise or anti-clockwise
- Parameters
-
p | first point selected |
q | adjacent point for q |
r | adjacent point for q |
- Returns
- 0 -> Linear
-
1 -> Clock Wise
-
2 -> Anti Clock Wise
Definition at line 133 of file jarvis_algorithm.cpp.
133 {
134 int val = (q.y - p.
y) * (r.x - q.x) - (q.x - p.x) * (r.
y - q.y);
135
136 if (val == 0) {
137 return 0;
138 }
139 return (val > 0) ? 1 : 2;
140 }
int y
Point respect to x coordinate.
◆ points
std::vector<Point> geometry::jarvis::Convexhull::points |
|
private |
◆ size
int geometry::jarvis::Convexhull::size |
|
private |
The documentation for this class was generated from the following file: