Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PETR FELKEL
FEL CTU PRAGUE
felkel@fel.cvut.cz
https://cw.felk.cvut.cz/doku.php/courses/a4m39vg/start
www.cguu.com
Interior point r
p
Exterior point p
S
Border point
Bounded (ohraničená)
Goes to
infinity
Unbounded
= .
S
Open
[Mount]
point
segment
polygon
pn
p1
lower hull
pop H pop H
pop
CHi-1 CHi
Points on stack H
= CH ({ , , … , })
pk
[Mount]
3. hull( points P )
4. if |P| 3 then
Lower tangent
5. compute CH by brute force,
6. return
7. Partition P into two sets L and R (with lower & higher coords x)
8. Recursively compute HL = hull(L), HR = hull(R)
9. H = Merge hulls(HL, HR) by computing
10. Upper_tangent( HL, HR) // find nearest points, HL CCW, HR CW
11. Lower_tangent( HL, HR) // (HL CW, HR CCW)
12. discard points between these two tangents
13. return H
Lower tangent
3. while( ab is not the upper tangent for HL, HR ) do
4. while( ab is not the upper tangent for HL) a = a.succ // move CCW
5. while( ab is not the upper tangent for HR) b = b.pred // move CW
6. Return ab
Where: (ab is not the upper tangent for HL) => orient(a, b, a.succ) 0
which means a.succ is left from line ab
m = |HL|+ |HR| |L| + |R| => Upper Tangent: O(m) = O(n)
Felkel: Computational geometry
(23)
Convex hull by D&C complexity
Initial sort O(n log(n))
Function hull()
– Upper and lower tangent O(n)
– Merge hulls O(1) O(n)
– Discard points between tangents O(n)
Overall complexity
– Recursion
1 … if n 3
T(n) =
2T(n/2) + O(n) … otherwise
– Overall complexity of CH by D&C: => O(n log(n))
[Mount]
Jarvis
[Mount]
Chan
[Mount]
1. Partition P into r = n/m disjoint subsets {p1, p2, …, pr} of size at most m
2. for i=1 to r do
a) Convex hull by GrahamsScan(Pi), store vertices in ordered array
3. let p1 = the bottom most point of P and p0 = (–, p1.y)
4. for k = 1 to m do // compute merged hull points O(log m)
a) for i = 1 to r do // angle to all r subsets => points qi
Compute the point qi P that maximizes the angle pk-1, pk, qi
Jarvis
b) let pk+1 be the point q {q1, q2, …, qr} that maximizes pk-1, pk, q
(pk+1 is the new point in CH)
c) if pk+1 = p1 then return {p1, p2, …, pk}
5. return “Fail, m was too small”
1. for t = 1, 2, … , lg lg ℎ do {
a) let m = min(22^t, n)
b) L = PartialHull( P, m)
c) if L “Fail, m was too small” then return L
}
Sequence of choices of m are { 4, 16, 256,…, 22^t ,…, n } … squares
i 0
2 k 1
1
t iterations
lg lg h lg lg h
n2 n 2 n2
t 1
t
t 1
t 1 lg lg h
2n lg h O(n log h)