# EECE522 - PowerPoint PPT Presentation

PPT – EECE522 PowerPoint presentation | free to download - id: 149d0d-ZjVlZ

The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
Title:

## EECE522

Description:

### We can easily find the convex hull of three points. ... Find the next hull vertex p1, which has the smallest polar angle with respect to ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 27
Provided by: poste5
Category:
Tags:
Transcript and Presenter's Notes

Title: EECE522

1
EECE522 ???? ??? ??
• Chapter 33
• Computational Geometry

2
Cross products
y
x
(0,0)
3
Collinear
y
p1 and p2 are collinear if p1xp20.
x
(0,0)
4
Clockwise
y
p1 is clockwise from p2 with respect to the
origin if p1xp2gt0.
x
(0,0)
5
Counterclockwise
y
p1 is counterclockwise from p2 with respect to
the origin if p1xp2lt0.
x
(0,0)
6
Turn left of right
turn right
turn left
p0p2 is clockwise with respect to from p0p1 if
(p2-p0)x(p1-p0)gt0.
p0p2 is counterclockwise with respect to from
p0p1 if (p2-p0)x(p1-p0)lt0.
7
Direction
p2 lies on the left side of p0p1 if
(p2-p0)x(p1-p0)lt0.
turn left
Direction(pi,pj,pk) return (pk-pi)x(pj-pi)
p0p2 is counterclockwise with respect to from
p0p1 if (p2-p0)x(p1-p0)lt0.
8
Line intersection
Determine if p1p2 and p3p4 intersect.
• For the two lines to intersect,
• p3 and p4 are on the different sides of p1p2, and
• p1 and p2 are on the different sides of p3p2.

9
Line intersection
Determine if p1p2 and p3p4 intersect.
• d1?Direction(p3,p4,p1)
• d2?Direction(p3,p4,p2)
• d3?Direction(p1,p2,p3)
• d4?Direction(p1,p2,p4)
• if d1d2lt0 and d3d4lt0 then return true
• if d10 and On-Segment(p3,p4,p1) then return true
• if d20 and On-Segment(p3,p4,p2) then return true
• if d30 and On-Segment(p1,p2,p3) then return true
• if d40 and On-Segment(p1,p2,p4) then return true
• return false

10
Line sweeping
• Assumptions
• An imaginary vertical sweep line
• No vertical line segments
• No 3 segments intersecting at a single point

11
Notations and terminology
• s1 and s2 are comparable at x if the vertical
sweep line with x-coordinate x intersects both of
them.
• s1 is above s2 at x, written if s1
and s2 are comparable at x and the intersection
of s1 with the sweep line at x is higher than the
intersection of s2 with the same sweep line.

12
Example
d is not comparable with any other segment.
13
Moving the sweep line
• From left to right
• The sweep-line status
• The event-point schedule
• Each segment point is an event point.
• sorted by increasing x-coordinate
• covertical points
• Left covertical points first
• Lower y-coordinates first
• A segment is inserted when its left endpoint is
encountered.
• A segment is deleted when its right endpoint is
encountered.

14
Sweep-line status
• Operations on a total order T
• Insert(T,s) insert segment s into T
• Delete(T,s) delete segment s form T
• Above(T,s) return the segment immediately above
segment s in T
• Below(T,s) return the segment immediately below
segment s in T

All these operations run in O(lgn) time.
15
Segment-intersection
Input a set S of line segments
• T?Ø
• Sort the endpoints of the segments S
• for each point p in the sorted list
• do if p is the left endpoint of a segment s
• then Insert(T,s)
• if ((Above(T,s) or Below(T,s))
intersect s)
• then return true
• if p is the right endpoint of a segment s
• then if (Above(T,s) intersects Below(T,s))
• then return true
• Delete(T,s)
• return false

16
Example
The intersection of segment d and b is found when
segment c is deleted.
17
Convex hull
The convex hull --- the smallest convex polygon
enclosing all the points
The problem Compute the convex hull of n given
points.
18
A straightforward approach
• We can easily find the convex hull of three
points.
• Assume that we know how to compute the convex
hull of n-1 points.
• Find the convex hull of n points. --- How?

19
Find the convex hull of n points from the convex
hull of n-1 points
• 2 cases
• The n-th point is inside the convex hull. ---
the hull is unchanged.
• The n-th point is outside the hull.
--- the hull is stretched to reach that point.

20
Determining whether a point is inside a polygon
• Draw a long line from the point.
• If the number of intersections is odd, the point
is inside the polygon.

21
Hull stretching
.
22
Operations used in Grahams scan
• Top(S) return the point on the top of stack S
without changing S
• Next-to-Top(S) return the point one entry below
the top of stack S without changing S
• Pop(S) remove the point on the top of stack S
• Push(p,S) push p into stack S

23
Grahams scan
Input a set S of points
• Let p0 be the points in Q with the minimum
y-coordinate.
• Let ltp1,p2,,pmgt be the remaining points in Q
sorted by polar angle in counterclockwise order.
• Push(p0,S)
• Push(p1,S)
• Push(p2,S)
• for i?3 to m
• do while the angle formed by points
Next-to-Top(S), Top(S), and pi makes
a nonleft turn
• do pop(S)
• push(pi,S)
• return S

24
Jarviss march
• Let p0 be the points in Q with the minimum
y-coordinate.
• Find the next hull vertex p1, which has the
smallest polar angle with respect to p0.
• Find the next hull vertex p2, which has the
smallest polar angle with respect to p1.
• Continue finding the hull vetices until we come
back to our original vertex p0.

25
Jarviss march
26
Area calculation
y
x
0