Title: CMPUT 301 Convex Hulls in 2D
1CMPUT 301 Convex Hulls in 2D
- Lecturer Sherif Ghali
- Department of Computing Science
- University of Alberta
2Geometric Problems
3Convexity of a region in 2D
- A region is convex iff pq is wholly inside the
region for each p,q in the region. - A convex hull is the smallest such convex set.
4The Convex Hull
5The Input and Output of aConvex Hull Computation
6Characterization of Points on the Convex Hull
two points p and q are on the convex hull if and
only if none of the other points lies on the left
side of pq
7Convex HullFirst Algorithm
8Implementation Details - time
r1
r2
pqr1 is a left turn
q
pqr2 is a right turn
p
what is the time complexity?
9Handling Degeneracy
two points p and q are on the convex hull if and
only if none of the other points lies on the left
side of pq
10Reliability of floating point
Conclusion SlowConvexHull can succumb to
degenerate inputs
11Incremental algorithms
- We know the solution for Si p1, p2, pi
- Insert pi1
- We compute the solution for Si1 p1, p2, pi
,pi1
12Types of Polygons
- Simple polygon edges intersect only at endpoints
- Convex polygon
- pq wholly inside
- turns are only right turns
13Upper and Lower Hull
14Incremental Insertion
15(No Transcript)
16Lexicographic Sorting
- bool xcompare(Point a, Point b)
- return a.x lt b.x
-
- bool xycompare(Point a, Point b)
- if (a.x b.x)
- return a.y lt b.y
- else
- return a.x lt b.x
1
6
3
4
2
5
5
3
6
1
2
4
17Degeneracy
- Potential problems
- a hull point is mistakenly removed
- an interior point is not removed
- small dents in the hull
- Conclusion output not necessarily correct, but
the program will not crash - Perils of floating point
18Correctness
- Induction hypothesis assume the Hull Hi-1
- Hi-1 Hull(p1, p2, pi -1)
- is the upper hull
- Base case H2 Hull(p1, p2)
- is trivially correct
- Could a point be above the hull Hi
- Hi Hull(p1, p2, pi )
- after adding pi ?
19Time
- Lexicographic sorting O(n log n)
- A point is deleted at most once
20Degeneracies
- General position assumption
- Binary vs. ternary branching
- If affordable, use exact arithmetic (integers,
rationals, algebraic numbers) - Correctness of an algorithm is with respect to
the definition
21Application Domains
- Computer Graphics
- Modeling and rendering, collision detection
- Robotics
- Motion planning, optimal robot arm placement
- Geographic Information Systems
- Maps, overlaying maps, terrains, nearness
- CAD/CAM
- prototyping, manufacturing, assembly
- Other
- molecular modeling, character/fingerprint
recognition, database queries
22Reference
Chap. 1