mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Update graham_scan_algorithm.cpp
This commit is contained in:
parent
ef83af8370
commit
d502cfe371
@ -1,8 +1,8 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* @file
|
* @file
|
||||||
* @brief Implementation of the [Convex
|
* @brief Implementation of the [Convex
|
||||||
*Hull](https://en.wikipedia.org/wiki/Convex_hull) implementation using [Graham
|
* Hull](https://en.wikipedia.org/wiki/Convex_hull) implementation using [Graham
|
||||||
*Scan](https://en.wikipedia.org/wiki/Graham_scan)
|
* Scan](https://en.wikipedia.org/wiki/Graham_scan)
|
||||||
* @details
|
* @details
|
||||||
* In geometry, the convex hull or convex envelope or convex closure of a shape
|
* In geometry, the convex hull or convex envelope or convex closure of a shape
|
||||||
* is the smallest convex set that contains it. The convex hull may be defined
|
* is the smallest convex set that contains it. The convex hull may be defined
|
||||||
@ -10,7 +10,7 @@
|
|||||||
* Euclidean space, or equivalently as the set of all convex combinations of
|
* Euclidean space, or equivalently as the set of all convex combinations of
|
||||||
* points in the subset. For a bounded subset of the plane, the convex hull may
|
* points in the subset. For a bounded subset of the plane, the convex hull may
|
||||||
* be visualized as the shape enclosed by a rubber band stretched around the
|
* be visualized as the shape enclosed by a rubber band stretched around the
|
||||||
*subset.
|
* subset.
|
||||||
*
|
*
|
||||||
* The worst case time complexity of Jarvis’s Algorithm is O(n^2). Using
|
* The worst case time complexity of Jarvis’s Algorithm is O(n^2). Using
|
||||||
* Graham’s scan algorithm, we can find Convex Hull in O(nLogn) time.
|
* Graham’s scan algorithm, we can find Convex Hull in O(nLogn) time.
|
||||||
@ -23,17 +23,17 @@
|
|||||||
* are sorted, they form a simple closed path.
|
* are sorted, they form a simple closed path.
|
||||||
* The sorting criteria is to use the orientation to compare angles without
|
* The sorting criteria is to use the orientation to compare angles without
|
||||||
* actually computing them (See the compare() function below) because
|
* actually computing them (See the compare() function below) because
|
||||||
*computation of actual angles would be inefficient since trigonometric
|
* computation of actual angles would be inefficient since trigonometric
|
||||||
*functions are not simple to evaluate.
|
* functions are not simple to evaluate.
|
||||||
*
|
*
|
||||||
* Accept or Reject Points
|
* Accept or Reject Points
|
||||||
* Once we have the closed path, the next step is to traverse the path and
|
* 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
|
* 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
|
* 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
|
* 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 the orientation of these
|
* three points be prev(p), curr(c) and next(n). If the orientation of these
|
||||||
*points (considering them in the same order) is not counterclockwise, we
|
* points (considering them in the same order) is not counterclockwise, we
|
||||||
*discard c, otherwise we keep it.
|
* discard c, otherwise we keep it.
|
||||||
*
|
*
|
||||||
* @author [Lajat Manekar](https://github.com/Lazeeez)
|
* @author [Lajat Manekar](https://github.com/Lazeeez)
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user