





































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






































































David Galles
Department of Computer Science
University of San Francisco
Given any two points
p
1
x
, y 1
1
and
p
2
x
2
, y
Cross Product:
p
1
p
2
x
y 1
2
x
2
y
1
p
1
p
2
x
1
y
2
x
y 2
1
x
y 2
1
x
y 1
p
2
p
1
Given two vectors that share an origin:
p
p 0
1
and
p
0
p
2
Is
−→p^0
p
2
clockwise or counterclockwise relative to
p
p 0
2
?
24-3:
Given two line segments
p
p 0
1
and
p
1
p
2
, which
direction does angle
p
p 0
p 1
2
turn?
p^1
p^0
Left Turn
p^2
p^1
p^0 Right Turn
p^2
Given two line segments
p
p 0
1
and
p
1
p
2
, which
direction does angle
p
p 0
p 1
2
turn?
p
2
p
p
1
p
0
is positive, left turn
p
2
p
p
1
p
0
is negative, right turn
p
2
p
p
1
p
0
is zero, no turn (colinear)
Graham’s Scan Algorithm
Go through all the points in order Push points onto a stack Pop off points that don’t form part of the convexhull When we’re done, stack contains the points inthe convex hull
Gram-Scan
Let
p
0
be the point with the minimum
y
-coordinate
Sort the points by increasing polar angle around
p
0
Push
p
, 0 p
1
, and
p
2
on the stack
for
i
3 to
n
do
while angle formed by top two points on
doesn’t turn left do
Pop
Push(
p
)i
return
- p - p - p - p - p - p