Title: CHAPTER 33 Computational Geometry
1CHAPTER 33Computational Geometry
- Is the branch of computer science that studies
algorithms for solving geometric problems. - Has applications in many fields, including
- computer graphics
- robotics,
- VLSI design
- computer aided design
- statistics
- Deals with geometric objects such as points,
line segments, polygons, etc. - Some typical problems considered
- whether intersections occur in a set of lines.
- finding vertices of a convex hull for points.
- whether a line can be drawn separating two sets
of points. - whether one point is visible from a second
point, given some polygons that may block
visibility. - optimal location of fire towers to view a
region. - closest or most distant pair of points.
- whether a point is inside or outside a polygon.
2Cross products
3Cross products (cont.)
4Intersection of two line segments
5Intersection of two line segments (cont.)
6Determining whether any pair of segments
intersect.
7(No Transcript)
8The Algorithm ANY-SEGMENTS-INTERSECTION(S)
- To maintain a total ordering T on the sweep line
as it moves, we need the following operations - INSERT(T,s) insert segment s into T
- DELETE(T,s) delete segment s from T
- ABOVE(T,s) return the segment from T
immediately above segment s - BELOW(T,s) return the segment from T
immediately below segment s - Red-black trees can provide a balanced search
tree which can support above operations in O(log
n) time (see Ch. 13 in CLRS)
- T? emptyset
- Sort segment endpoints from left to right. Break
ties by putting point with lower y-coordinate
first. - For each point p in the sorted list (in order)
- if p is left endpoint of segment s then
- INSERT(T,s)
- if ABOVE(T,s) exists and
it intersects s or - BELOW(T,s) exists and it intersects s
then return TRUE - if p is the right endpoint of segment
then - if both ABOVE(T,s) and
BELOW(T,s) exist and - ABOVE(T,s) intersects BELOW(T,s)
then return TRUE - DELETE(T,s)
- return FALSE
Animated demo http//www.lupinho.de/gishur/html/Sw
eeps.htmlsegment
9Comments and Correctness
10Correctness and Runtime
- In either case, the order of T is correct before
q is processed. - Only two cases are possible.
- Either a or b is inserted into T at z and the
other segment is above or below it. (In this
case, intersection is detected by line (6) .) - Segments a and b are already in T and a segment c
between them is deleted at z. (In this case, an
intersection is detected by line (8).)
- In either case the intersection of a and b at p
is detected, so procedure cannot return a FALSE,
as supposed.
a
p
c
q
b
x
z
- Running Time
- sort on line (2) takes O(n logn) time, using
merge or heap sort. - since there are 2n events (endpoints) where
sweep line stops, the loop iterates at most 2n
times. - each iteration of loop takes O(log n) time,
since red-black tree operations take O(log n)
time. - Total time is O(n logn).
READ Ch. 33.1 and Ch 33.2 in CLRS.
11Convex Hull Algorithms
12The Problem and Approaches
13Gift Wrapping or The Jarvis March Algorithm
14Complexity of Jarvis March
15Graham Scan Algorithm
16Example and Runtime Computation
17Correctness of Graham Scan
18Correctness of Graham Scan (cont.)
19Closest Pair of Points
20Divide and Conquer Steps
21Combine Step and Runtime
d
d
L
d
d
Possible coincident points, one in P and one in
P.
L
Runtime
- The initial preprocessing step costs O(n logn)
- The recurrence relation for the recursive
portion is T(n), - where
- Its solution is T(n) O(n logn). This gives also
the total running time.
READ Ch. 33.3 and 33.4 in CLRS.