Professional Documents
Culture Documents
PROGRAMMING CONTESTS
Jaehyun Park
Computational Geometry
Cross Product
Segment-Segment
Intersection
Scan
Cross Product
Applications:
Determining
Cross Product
Define ccw , , =
ccw , , > 0
is a left turn
ccw , , < 0
is a right turn
Proper
Not Proper
, , ccw , , < 0
AND ccw , , ccw , , < 0
Simple
Record
algorithm
the edge
Incremental Construction
Example
8
7
6
new origin
5
2
3
Example
8
7
6
new origin
5
2
3
Example
2
9
8
7
6
new origin
5
2
3
Example
Thats better
9
8
7
6
new origin
Example
3
9
8
7
6
new origin
Example
8
7
6
new origin
4
1
Example
8
7
6
new origin
4
1
Example
8
7
new origin
4
1
Example
Bad corner!
9
8
7
new origin
4
1
Example
8
7
new origin
5
4
1
Example
8
7
new origin
4
1
Example
8
7
new origin
4
1
Example
8
7
new origin
4
1
Example
Done!
9
8
7
new origin
4
1
Pseudocode
Set the leftmost point 0,0 , and sort the rest of the
points in increasing order of /
Initialize stack
For = 1 :
be the second topmost element of , be the
topmost element of , be the th point
If ccw , , < 0, pop and go back
Push to
Let
Example
Sweep line
Example
Example
Example
Example
Example
Example
Example
Example
Example
Example
Pseudopseudocode
Right edge?
Remove
it
Exercise problems
Finding
Intersecting Half-planes
Representing a half-plane: + + 0
The intersection of half-planes is a convex area
If
Intersecting Half-planes
their intersection = ,
Intersecting Half-planes
Time complexity: 3
Pretty
polygon
Dont
Ternary Search
= + ( )/3, 2 = ( )/3
If 1 (2 ), then set to 2
Otherwise, set to 1