Introduction To Algorithms: 6.046J/18.401J/SMA5503
Introduction To Algorithms: 6.046J/18.401J/SMA5503
6.046J/18.401J/SMA5503
Lecture 12
Prof. Erik Demaine
Computational geometry
Algorithms for solving “geometric problems”
in 2D and higher.
Fundamental objects:
point line segment line
Basic structures:
11 17
17 43
43
66 88 12
12 14
14 26
26 35
35 41
41 42
42 59
59 61
61
11 14
14 35
35 43
43
11 66 12
12 17
17 26
26 41
41 43
43 59
59
66 88 12
12 14
14 26
26 35
35 41
41 42
42 59
59 61
61
11 14
14 35
35 43
43
11 66 12
12 17
17 26
26 41
41 43
43 59
59
66 88 12
12 14
14 26
26 35
35 41
41 42
42 59
59 61
61
RANGE-QUERY([7, 41])
© 2001 by Erik D. Demaine Introduction to Algorithms Day 21 L12.11
General 1D range query
root
split node
Crossproduct v1 × v2 = x1 y2 – y1 x2
= |v1| |v2| sin θ .
Thus, sign(v1 × v2) = sign(sin θ) > 0 if θ convex,
< 0 if θ reflex,
= 0 if θ borderline.
© 2001 by Erik D. Demaine Introduction to Algorithms Day 21 L12.20
Primitive operations:
Orientation test
Given three points p1, p2, p3 are they p3
• in clockwise (cw) order,
• in counterclockwise (ccw) order, or p2
• collinear?
p1
(p2 – p1) × (p3 – p1)
collinear
> 0 if ccw
< 0 if cw p2 p3
= 0 if collinear p1 cw p1 ccw
p3 p2
c
f
b
e
d
a
b f