Skip to content

feat: Added Graham Scan Algorithm. #1836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 55 commits into from
Nov 14, 2021
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e53047e
Implementated Grahamscan Algorithm for Convex Hull
Lazeeez Nov 3, 2021
27d349a
Update graham_scan_algorithm.cpp
Lazeeez Nov 3, 2021
4a5987a
Update graham_scan_functions.h
Lazeeez Nov 3, 2021
d06a7b5
Update graham_scan_algorithm.cpp
Lazeeez Nov 3, 2021
f1b83dd
Update graham_scan_functions.h
Lazeeez Nov 3, 2021
95cd2f4
Update graham_scan_algorithm.cpp
Lazeeez Nov 3, 2021
23a5665
Update and rename graham_scan_functions.h to graham_scan_functions.hpp
Lazeeez Nov 3, 2021
17a2e85
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 4, 2021
20f80fc
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 4, 2021
6be4aaf
Merge branch 'master' into Lazeeez
Lazeeez Nov 4, 2021
a16bf9b
Update geometry/graham_scan_functions.hpp
Lazeeez Nov 4, 2021
e89e4c8
Update geometry/graham_scan_functions.hpp
Lazeeez Nov 6, 2021
c88a858
updating DIRECTORY.md
Nov 6, 2021
af70211
clang-format and clang-tidy fixes for e89e4c8c
Nov 6, 2021
7df4778
Merge branch 'master' into Lazeeez
Lazeeez Nov 6, 2021
ea11776
clang-format and clang-tidy fixes for 7df4778f
Nov 6, 2021
3331f18
Fix #1
Lazeeez Nov 6, 2021
6b0a7d0
Merge branch 'Lazeeez' of https://github.com/Lazeeez/C-Plus-Plus into…
Lazeeez Nov 6, 2021
a41612c
Update graham_scan_functions.hpp
Lazeeez Nov 6, 2021
f5ccb3e
Delete composite_simpson_rule.cpp
Lazeeez Nov 6, 2021
2d15e14
Delete inverse_fast_fourier_transform.cpp
Lazeeez Nov 6, 2021
69b6832
Fix #2
Lazeeez Nov 6, 2021
1a4bd72
updating DIRECTORY.md
Nov 6, 2021
e90e0d6
clang-format and clang-tidy fixes for 69b6832b
Nov 6, 2021
e68ba6c
Fix #3
Lazeeez Nov 6, 2021
1c05ca7
Merge branch 'Lazeeez' of https://github.com/Lazeeez/C-Plus-Plus into…
Lazeeez Nov 6, 2021
02696ce
clang-format and clang-tidy fixes for 1c05ca7c
Nov 6, 2021
44fd627
Update graham_scan_functions.hpp
Lazeeez Nov 6, 2021
2957fd2
Fix #4
Lazeeez Nov 7, 2021
9465ef2
clang-format and clang-tidy fixes for 2957fd21
Nov 7, 2021
e79e317
Create composite_simpson_rule.cpp
Panquesito7 Nov 7, 2021
13c3d22
updating DIRECTORY.md
Nov 7, 2021
405d21a
Create inverse_fast_fourier_transform.cpp
Panquesito7 Nov 7, 2021
280cf61
updating DIRECTORY.md
Nov 7, 2021
91d669a
clang-format and clang-tidy fixes for 405d21a5
Nov 7, 2021
333ef5c
Merge branch 'master' into Lazeeez
Panquesito7 Nov 7, 2021
176051b
clang-format and clang-tidy fixes for 333ef5ca
Nov 7, 2021
8577fcf
Update geometry/graham_scan_functions.hpp
Lazeeez Nov 7, 2021
7c3fc8b
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 7, 2021
02ff191
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 7, 2021
7ef02d1
Merge branch 'master' into Lazeeez
Panquesito7 Nov 7, 2021
f7f735b
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 8, 2021
bfe80a0
Update geometry/graham_scan_functions.hpp
Lazeeez Nov 8, 2021
47d3758
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 8, 2021
ee4cb63
Update geometry/graham_scan_algorithm.cpp
Lazeeez Nov 8, 2021
ef83af8
clang-format and clang-tidy fixes for ee4cb635
Nov 8, 2021
d502cfe
Update graham_scan_algorithm.cpp
Lazeeez Nov 8, 2021
f2f6923
Update graham_scan_functions.hpp
Lazeeez Nov 8, 2021
fd92a75
clang-format and clang-tidy fixes for f2f69234
Nov 8, 2021
3b91daa
Update graham_scan_functions.hpp
Lazeeez Nov 8, 2021
cafe74b
Create partition_problem.cpp
Lazeeez Nov 9, 2021
bfa7d06
Update partition_problem.cpp
Lazeeez Nov 9, 2021
3d2c81b
Delete partition_problem.cpp
Lazeeez Nov 9, 2021
b72d427
Merge branch 'master' into Lazeeez
Lazeeez Nov 14, 2021
12e3851
Merge branch 'master' into Lazeeez
Panquesito7 Nov 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update graham_scan_functions.hpp
  • Loading branch information
Lazeeez authored Nov 8, 2021
commit 3b91daa7744adcaa3c64804207d56f8dc9ebc8b7
29 changes: 3 additions & 26 deletions geometry/graham_scan_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
* are sorted, they form a simple closed path.
* The sorting criteria is to use the orientation to compare angles without
* actually computing them (See the compare() function below) because
*computation of actual angles would be inefficient since trigonometric
*functions are not simple to evaluate.
* computation of actual angles would be inefficient since trigonometric
* functions are not simple to evaluate.
*
* Accept or Reject Points
* Once we have the closed path, the next step is to traverse the path and
* remove concave points on this path using orientation. The first two points in
* sorted array are always part of Convex Hull. For remaining points, we keep
* track of recent three points, and find the angle formed by them. Let the
*three points be prev(p), curr(c) and next(n). If orientation of these points
* three points be prev(p), curr(c) and next(n). If orientation of these points
* (considering them in same order) is not counterclockwise, we discard c,
* otherwise we keep it.
*
Expand Down Expand Up @@ -177,29 +177,6 @@ std::vector<Point> convexHull(std::vector<Point> points, uint64_t size) {
return {};
};

// Create an empty stack and push first three points to it.
std::stack<Point> S;
S.push(points[0]);
S.push(points[1]);
S.push(points[2]);

// Process remaining n-3 points
for (int i = 3; i < m; i++) {
// Keep removing top while the angle formed by
// points next-to-top, top, and points[i] makes
// a non-left turn
while (S.size() > 1 &&
orientation(nextToTop(&S), S.top(), points[i]) != 2) {
S.pop();
}
S.push(points[i]);
}
// If modified array of points has less than 3 points, convex hull is not
// possible
if (m < 3) {
return {};
};

// Create an empty stack and push first three points to it.
std::stack<Point> St;
St.push(points[0]);
Expand Down