Computational Geometry - PowerPoint PPT Presentation

Loading...

PPT – Computational Geometry PowerPoint presentation | free to download - id: 1adb81-ZDc1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Computational Geometry

Description:

... q2,p1), and (p2,q2,q1) are all collinear and the ... collinear : ... All the points are collinear. The convex hull is a point. All the points are coincident ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 75
Provided by: csU73
Learn more at: http://www.cs.ucf.edu
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Computational Geometry


1
Computational Geometry
2
What is Computational Geometry?
  • Deals with problems involving geometric
    primitives
  • points
  • lines
  • polygons

3
Geometric Primitives
  • Points
  • a geometric element determined by an ordered set
    of coordinates
  • 2D (x,y)
  • 3D (x,y,z)
  • 4D (x,y,z,w)

4
Geometric Primitives
  • Line
  • a set of points satisfying equation
  • P t A (1-t) B Parametric equation
  • in 2D
  • y m x c Analytic equation
  • Line segment
  • closed subset of a line contained between two
    points a and b which are called end points
  • P t A (1-t) B where 0 ? t ? 1 Parametric
    equation

5
Geometric Primitives
  • Polygons
  • circular sequence (cycle) of points (vertices)
    and segments (edges)

6
Some Geometric Problems
7
Segment Intersection
  • Test whether segments (a,b) and (c,d) intersect.
    How do we do it?

a
d
c
b
  • We could start by writing down the equations of
    the lines through the segments, then test whether
    the lines intersect, then ...
  • An alternative (and simpler) approach is based in
    the notion of orientation of an ordered triplet
    of points in the plane

8
Orientation
  • Clockwise

if slope2 gt slope1 then counterclockwise else
if slope2 lt slope1 clockwise else
colinear
9
Intersection and Orientation
(p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1)
(p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1)
10
Intersection and Orientation
11
Intersection and Orientation
  • Two segments (p1,q1) and (p2,q2) intersect iff
  • general case (p1,q1,p2) and (p1,q1,q2) have
    different orientations and (p2,q2,p1) and
    (p2,q2,q1) have different orientations
  • special case (p1,q1,p2), (p1,q1,q2), (p2,q2,p1),
    and (p2,q2,q1) are all collinear and the
    x-projections of (p1,q1) and (p2,q2) intersect,
    the y-projections of (p1,q1) and (p2,q2) intersect

12
Intersection and Orientation (special cases)
q
2
p
2
q
q
2
1
p
2
(p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1)
p
(p1,q1,p2), (p1,q1,q2), (p2,q2,p1), (p2,q2,q1)
1
13
How to Compute the Orientation?
  • slope of segment (p1,p2) ? (y2-y1) / (x2-x1)
  • slope of segment (p2,p3) ? (y3-y2) / (x3-x2)

p3
p2
  • Orientation test
  • counterclockwise (left turn) ? lt ?
  • clockwise (right turn) ? gt ?
  • collinear ? ?

p1
  • The orientation depends on whether the expression
    (y3-y2) (x2-x1) - (y2-y1) (x3-x2) is positive,
    negative, or zero.

14
Point Inclusion
  • given a polygon and a point
  • is the point inside ?
  • or
  • outside the polygon?

15
Point Inclusion
  • Draw a horizontal line to the right of each point
    and extend it to infinity
  • Count the number of times a line intersects the
    polygon.
  • -even number ? point is outside
  • -odd number ? point is inside

16
Point Inclusion
  • Draw a horizontal line to the right of each point
    and extend it to infinity
  • Count the number of times a line intersects the
    polygon.
  • -even number ? point is outside
  • -odd number ? point is inside

a
b
c
d
e
f
g
What about points d and g ?? Special Case !
17
Segment-Segment Intersection
18
Segment-Segment Intersection
  • Problem Definition
  • Let n of input segments in a plane
  • Find all intersection points among segments.

How many intersections k, possible?
19
Brute Force Intersect Algorithm
  • Algorithm Brute Force Intersect(S)
  • Test all pairs (si, sj), i ? j.
  • If si intersects sj, report si intersects sj.
  • Complexity
  • -Independent of the number of intersections.

20
Goal
  • Spend time depending on the of intersection ?

Idea Avoid testing all pairs. Do not Intersect
if they are far apart.
21
Sweep-line
Sweep line
ab
Status
Event Points
a
b a
a b
a
a1 b1 b2 a2
ab b2 a2
b2 a2
a2
b1 b2 a2
22
Plane Sweeping Algorithm
  • Sweep the L over the plane stopping at events.
  • Three types of events
  • The left end point is reached
  • The right end point is reached
  • An intersection point is reached

23
Plane Sweeping Algorithm
  • Sweep the L over the plane stopping at events.
  • Three types of events
  • The left end point is reached Insert segment
  • The right end point is reached Remove segment
  • An intersection point is reached Switch adjacent
    segments

24
Plane Sweeping Algorithm
25
Plane Sweep Algorithm
  • Analysis
  • Total of events 2 n k
  • Event is inserted once and deleted once from
    event queue Q
  • Cost of maintaining Q O((nk) log(nk))
  • k is at most n2.
  • So cost of maintaining Q O((nk) log n)
  • Cost of maintaining segment list is O(n log n)

26
Plane Sweep Algorithm
  • Analysis (contd.)
  • Total cost of maintaining Q O((nk) log n)
  • Cost of maintaining segment list
  • n segments inserted and deleted at O(log n) cost
    each.
  • At every event there are at most 2 new segment
    adjacencies.
  • Total intersection calls O(nk).
  • Thus total cost of maintaining segment list O(n
    log n)
  • Total overall cost O((nk) log n)

27
Simple Closed Path
ProblemGiven a set of points ...
Connect the dots without crossings
28
Simple Closed Path
1. Pick the bottom most point as the anchor
point
2. For each point p, compute the angle(p) of
the segment (a,p) with respect to the x-axis
29
Simple Closed Path
  • Traverse the points by increasing angle

a
30
Simple Closed Path
How do we compute angles?
a
  • Option 1 use trigonometry (e.g., tan-1).
  • the computation is inefficient since
    trigonometric functions are not in the normal
    instruction set of a computer and need a call to
    a math-library routine.

31
Simple Closed Path
How do we compute angles?
a
  • Observation
  • we dont care about the actual values of the
    angles. We just want to sort by angle.
  • Option 2 use orientation to compare angles
    without actually computing them!!

32
Simple Closed Path
  • Orientation to sort by angles ?
  • angle(p) lt angle(q) ? orientation of (a,p,q) is
    counterclockwise
  • We obtain an O(n log n)-time algorithm for the
    simple closed path problem on n points

33
Convex Hull
34
Convex Polygon
  • A convex polygon is a nonintersecting polygon
    whose internal angles are all convex (i.e., less
    than 180º)
  • In a convex polygon, a segment joining two
    vertices of the polygon lies entirely inside the
    polygon

convex
nonconvex
35
Convex Hull
  • Definition The convex hull of a set of points is
    the smallest convex polygon containing the points
  • Think of a rubber band snapping around the points

36
Special Cases
  • The convex hull is a segment
  • All the points are collinear
  • The convex hull is a point
  • All the points are coincident

37
Applications
  • Motion planning
  • Find an optimal route that avoids obstacles for a
    robot
  • Geometric algorithms
  • Convex hull is like a two-dimensional sorting

obstacle
start
end
38
The Package Wrapping Algorithm
Idea Think of wrapping a package. Put the paper
in contact with the package and continue to wrap
around from one surface to the next until you get
all the way around.
39
Package Wrap
  • Question Given the current point, how do we
    compute the next point to be wrapped?
  • Set up an orientation tournament using the
    current point as the anchor-point.
  • The next point is selected as the point that
    beats all other points at CCW orientation, i.e.,
    for any other point, we have orientation(c, p,
    q) CCW

c
40
Time Complexity of Package Wrap
  • For every point on the hull we examine all the
    other points to determine the next point
  • Notation
  • N number of points
  • M number of hull points (M ? N)
  • Time complexity ?(M N)
  • Worst case ?(N2)
  • (All the points are on the hull, and thus M
    N)
  • Average case ?(N log N ) ?(N4/3)
  • for points randomly distributed inside a square,
    M ?(log N) on average
  • for points randomly distributed inside a circle,
    M ?(N1/3) on average

41
Computing the Convex Hull
  • The following method computes the convex hull of
    a set of points
  • Phase 1 Find the lowest point (anchor point)
  • Phase 2 Form a nonintersecting polygon by
    sorting the points counterclockwise around the
    anchor point
  • Phase 3 While the polygon has a nonconvex
    vertex, remove it

42
Removing Nonconvex Vertices
  • Testing whether a vertex is convex can be done
    using the orientation function
  • Let p, q and r be three consecutive vertices of a
    polygon, in counterclockwise order
  • q convex ? orientation(p, q, r) CCW
  • q nonconvex ? orientation(p, q, r) CW or COLL

r
r
q
q
p
p
43
Graham Scan
  • The Graham scan is a systematic procedure for
    removing nonconvex vertices from a polygon
  • The polygon is traversed counterclockwise and a
    sequence H of vertices is maintained
  • for each vertex r of the polygon
  • Let q and p be the last and second last vertex of
    H
  • while orientation(p, q, r) CW or COLL remove q
    from H q ? p p ? vertex preceding p in H
  • Add r to the end of H

44
Analysis
  • Computing the convex hull of a set of points
    takes O(n log n) time
  • Finding the anchor point takes O(n) time
  • Sorting the points counterclockwise around the
    anchor point takes O(n log n) time
  • Use the orientation comparator and any sorting
    algorithm that runs in O(n log n) time (e.g.,
    heap-sort or merge-sort)
  • The Graham scan takes O(n) time
  • Each point is inserted once in sequence H
  • Each vertex is removed at most once from sequence
    H

45
Quick Hull Algorithm
46
Quick Hull Example
J
O
K
P
A
L
N
A B C D E F G H I J K L M N O P
47
Quick Hull Example
J
O
K
P
A
L
N
A B C D E F G H I J K L M N O P
48
Quick Hull Example
J
O
K
P
A
L
N
A B D F G H J K M O P
49
Quick Hull Example - Maximum
J
O
K
P
A
L
N
A B D F G H J K M O P
50
Quick Hull Example - Filter
J
O
K
P
A
L
N
A B F J J O P
51
Quick Hull Example - Maximum
J
O
B
K
P
A
L
N
A B F J J O P
52
Quick Hull Example - Base Case
J
O
B
K
P
A
L
N
A B B J J O P
53
Quick Hull Example - Done
J
O
B
K
P
A
L
N
A B B J J O O P
54
Divide and Conquer Algorithm
55
Divide and Conquer Algorithm
B
A
56
Divide and Conquer Algorithm
B
A
57
Divide and Conquer Algorithm
Upper Tangent
B
A
Lower Tangent
58
Divide and Conquer Algorithm
Upper Tangent
B
A
Lower Tangent
59
Divide and Conquer Algorithm -Find Lower Tangent-
b
B
A
a
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
60
Divide and Conquer Algorithm -Find Lower Tangent-
b
a1
B
A
a
a
a-1
a-1
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
61
Divide and Conquer Algorithm -Find Lower Tangent-
b
b-1
b1
b
B
A
a
a
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
62
Divide and Conquer Algorithm -Find Lower Tangent-
b
B
A
a
a-1
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
63
Divide and Conquer Algorithm -Find Lower Tangent-
B
b
A
a
a-1
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
64
Divide and Conquer Algorithm -Find Lower Tangent-
B
b
A
a
a-1
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
65
Divide and Conquer Algorithm -Find Lower Tangent-
B
A
b
a
a-1
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
66
Divide and Conquer Algorithm -Find Lower Tangent-
B
A
b
b1
a
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
67
Divide and Conquer Algorithm -Find Lower Tangent-
B
A
b
a
ab is a lower tangent if (a-1) and (a1) are
above/isLeftOn ab and (b-1) and (b1) are
above/isLeftOn ab
68
Dynamic Convex Hull
  • The basic convex hull algorithms were fairly
    interesting, but you may have noticed that you
    cant draw the hull until after all of the points
    have been specified.
  • Is there an interactive way to add points to the
    hull and redraw it while maintaining an optimal
    time complexity?

69
Two Halves One Hull
  • For this algorithm, we consider a convex hull as
    being two parts
  • An upper hull...

and a lower hull...
70
Adding points Case 1
  • Case 1 the new point is within the horizontal
    span of the hull
  • Upper Hull 1a
  • If the new point is above the upper hull,
    then it should be added to the upper hull and
    some upper-hull points may be removed.
  • .

Upper Hull 1b If the new point is below
the upper hull, no changes need to be made
71
Case 1 (cont.)
  • The cases for the lower hull are similar.
  • Lower Hull 1a
  • If the new point is below the lower hull,
    then it is added to the lower hull and some
    lower-hull points may be removed.

Lower Hull 1b If the added point is above
the existing point, it is inside the existing
lower hull, and no changes need be made.
72
Adding Points Case 2
  • Case 2 the new point is outside the horizontal
    span of the hull
  • We must modify both the upper and lower hulls
    accordingly.

73
Hull Modification
  • In Case 1, we determine the vertices l and r of
    the upper or lower hulls immediately
    preceding/following the new point p in the
    x-order.

If p has been added to the upper hull, examine
the upper hull rightward starting at r. If p
makes a CCW turn with r and its right neighbor,
remove r. Continue until there are no more CCW
turns. Repeat for point l examining the upper
hull leftward. The computation for the bottom
hull is similar
Bad
74
Analysis
  • Let n be the current size of the convex hull
  • Operation locate takes O(log n) time
  • Operation insert takes O((1 k)log n) time,
    where k is the number of vertices removed
  • Operation hull takes O(n) time
  • The amortized running time of operation insert is
    O(log n)
About PowerShow.com