Graham Scan Tutorial: Convex Hull of a Set of 2D Points

  Рет қаралды 9,415

Aaron Becker

Aaron Becker

Күн бұрын

Let's talk about the Convex Hull! interactive online code at demonstrations....
In geometry, the convex hull of a set of points is the smallest convex set that contains them. You can also define the convex hull as the intersection of all convex sets containing a given subset of a Euclidean space.
An equivalent definition is the set of all convex combinations of points in the subset. I like to visualize the convex hull as the shape enclosed by a rubber band stretched around the set.
In 1972 Ronald Graham published a delightful paper "An Efficient Algorithm for Determining the Convex Hull of a finite planar set". The paper is just one and half pages long, but it gives an algorithm with time complexity O(n log n) for n points. www.math.ucsd.e...
The first step is to find the point with the lowest y coordinate. This is the starting point of the convex hull. (If more than one point has this y coordinate, the rightmost one is used). Second, all the remaining points are sorted by polar angle to the starting point. This can be accomplished without trigonometry by using the reciprocal of the slope (-run/rise), and using negative infinity if the points have the same y coordinate. Call this list sortedPoints.
The algorithm then considers each sorted point in sequence, which can be animated by moving the slider step. We maintain a stack called the convexHullPts that is initialized with the starting point and the first sorted point. For every additional point in sortedPoints, we calculate if connecting to this point from the convexHullPts required a left turn or a right turn. If a right turn was required, we pop points off the stack convexHullPts until connecting to the current point in sortedPoints requires a left turn (the removed lines from convexHullPts are drawn as dashed red lines). We then add this point to convexHullPts, and repeat until we have stepped through all the points in sortedPoints.
The code is pleasantly simple, and you can see the stack operations for stepping through the sorted points here.
The function isLeftTurn[] returns the signed area of triangle defined by the points p, q, r. If this area is positive, then going from pq to qr is a left turn. If the area is negative, it is a right turn. The area computation is the determinant of a 3x3 matrix, and so requires no trigonometric functions.
Photo of Ronald Graham (1935--2020) by Cheryl Graham, CC BY 3.0 creativecommon..., via Wikimedia Commons
Full Playlist "Intro to Robotics": • Intro2Robotics Lecture...

Пікірлер: 9
@nmay231
@nmay231 3 ай бұрын
I was trying to follow along with the algorithm listed in Wikipedia and couldn't get it to work. This video made it possible for me to do it. Thanks!
@AaronBecker
@AaronBecker 3 ай бұрын
Glad it helped!
@xor_255
@xor_255 3 жыл бұрын
amazing explanation
@AaronBecker
@AaronBecker 3 жыл бұрын
It is delightful when an algorithm is as elegant as this one!
@LeBigPanda
@LeBigPanda 4 ай бұрын
Great video!
@Sleepystranger
@Sleepystranger 10 ай бұрын
Thank you for making this video
@0ia
@0ia 2 жыл бұрын
great video! very useful
@AntiProtonBoy
@AntiProtonBoy 3 жыл бұрын
rip Graham
@dasmaffin1633
@dasmaffin1633 11 ай бұрын
Should I have paid more attention in school to understand more than 20 words in this video?
Convex Hull Algorithm - Graham Scan and Jarvis March tutorial
7:24
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,7 МЛН
Coding a Dubins Car Optimal Path Planner
8:05
Aaron Becker
Рет қаралды 10 М.
Convex hulls: Graham scan - Inside code
7:00
Inside code
Рет қаралды 30 М.
Never install locally
5:45
Coderized
Рет қаралды 1,9 МЛН
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,4 МЛН
Convex Hull: Starting with graph algorithms for interviews
10:02
But what is the Fourier Transform?  A visual introduction.
20:57
3Blue1Brown
Рет қаралды 10 МЛН
The Algorithm Behind Spell Checkers
13:02
b001
Рет қаралды 422 М.
RRT, RRT* & Random Trees
11:14
Aaron Becker
Рет қаралды 74 М.
Jaidarman TOP / Жоғары лига-2023 / Жекпе-жек 1-ТУР / 1-топ
1:30:54