Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Graham scan
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Pseudocode == The pseudocode below uses a function ccw: ccw > 0 if three points make a counter-clockwise turn, ccw < 0 if clockwise, and ccw = 0 if collinear. (In real applications, if the coordinates are arbitrary real numbers, the function requires exact comparison of floating-point numbers, and one has to beware of numeric singularities for "nearly" collinear points.) Then let the result be stored in the <code>stack</code>. '''let''' points '''be''' the list of points '''let''' stack = empty_stack() '''find''' the lowest y-coordinate and leftmost point, called P0 '''sort''' points by polar angle with P0, if several points have the same polar angle then only keep the farthest '''for''' point '''in''' points: # pop the last point from the stack if we turn clockwise to reach this point '''while''' '''count''' stack > 1 and '''ccw'''(next_to_top(stack), top(stack), point) <= 0: '''pop''' stack '''push''' point '''to''' stack '''end''' Now the stack contains the convex hull, where the points are oriented counter-clockwise and P0 is the first point. Here, <code>next_to_top()</code> is a function for returning the item one entry below the top of stack, without changing the stack, and similarly, <code>top()</code> for returning the topmost element. This pseudocode is adapted from ''[[Introduction to Algorithms]]''.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)