Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computational Geometry Algorithms

Similar presentations


Presentation on theme: "Computational Geometry Algorithms"— Presentation transcript:

1 Computational Geometry Algorithms
Week 10

2 Introduction Query 1: Do any of the lines intersect?
Query 2: Is P0P1 clockwise or counterclockwise from P0P2? Query 3: What is the turning direction from P0P1 to P1P2 or if you traverse P0P1 and then P1P2, which direction do you turn? The input to a computational geometry problem is typically a description of a set of geometric objects, e.g., a set of points, a set of line segments, vertices of a polygon, etc. The output is often a response to a query about the object.

3 Real World Applications
graphics robotics (e.g., path planning, object avoidance) VLSI design (e.g., component placement, packaging) statistics (e.g., nearest neighbor) simulations (e.g., moving particles) architecture (e.g., roof design) collision detection application read the Ghostbusters and Ghosts problem (33-3) on page 963 of your textbook . Ghost busters armed with proton pack shoots a stream at a ghost.

4 Copyright © The McGraw-Hill Companies, Inc
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

5 Copyright © The McGraw-Hill Companies, Inc
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

6 Computing Cross Products
Cross Product p1 (x1,y1) x p2 (x2,y2) = the determinant of the matrix = x1 y2 – x2 y1 P1 = (4, 0) p 2 = (2,4) P1 x p2 = 4.4 –2.0 = 16 If the cross product, p1 x p2, is positive then p1 is clockwise from p2. If the cross product, p1 x p2, is negative then p1 is counterclockwise from p2. A boundary condition arises if the cross product is 0, i.e., the vectors are pointing in the same or opposite directions (collinear

7 Computing Cross Products
Example 1: p1 = (2,4) and p2 = (-2,-4), the cross product, p1 x p2, = (-2.4) = -8 - (-8) = 0. Example 2: P1 = 4,5 P2 = 3,5 p3 = 5,3 p1 x p2 = X1Y2 - X2Y1 = = +8 Therefore, p1 is clockwise from p2. p1 x p3 = X1Y3 - X3Y1 = = -8 Therefore, p1 is counterclockwise from p3.

8 Computing Cross Products
Query: whether consecutive line segments turn left or right If p1 x p2 > 0 then P1P3 turns left, i.e., p1 is clockwise from p3. If p1 x p2 < 0 then P1P2 turns right i.e., p1 is counterclockwise from p2.

9 Line Intersection Two lines segment intersect if and only if either of the following conditions hold: Each segment straddles the line containing the other. A segment P1P2 straddles a line if point p1 lies one side of the line and point p2 lies on the other side. 2. An end point of one segment lies on the other segment. P1 P4 P4 P1 P3 P3 P2 P2

10 Line Intersection Contd.
Segment p3p4 straddles the line containing p1p2, but p1p2 does not straddle the line containing p3p4. p4 p1 p2 p3 Point P3 is collinear with p1p2, but is not between p1 and p2. The segments do not intersect. p4 p1 p3 p2

11 Copyright © The McGraw-Hill Companies, Inc
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

12 Copyright © The McGraw-Hill Companies, Inc
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

13 Copyright © The McGraw-Hill Companies, Inc
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

14 Finding the Convex Hull
The convex hull, CH(Q), of a set Q of points is the smallest convex polygon P for which each point in Q is either on the boundary of P or in its interior Think of the points as pegs or nails sticking out of a board. The convex hull would be the shape formed by a tight string or rubber band being placed around the pegs so that all pegs are surrounded

15 Graham's Scan GRAHAM-SCAN(Q) Start with the lowest point p0 (Q(n)).
Sort the remaining points based on the polar angle from p0 (Q(nlogn)). p1,p2,p3 … pn are the sorted points. Push (p0,S), Push(p1,S), Push(p2,S) for i = 3 to m while the angle formed by points NEXT-TO-TOP(S), TOP(S) and pi makes a non-left turn pop(S) push (pi,S) Return(S) Example: Text book Page 950 Time Complexity: (n logn)

16 Graham-Scan Example The sequence p1, p2, p3, .. P12 of points are numbered in increasing order of polar angles relative to p0. The initial stack containing p0, p1, p2.

17 Graham-Scan Example Contd.
Stack S after each iteration of the for loop. Dashed lines show non-left turn which cause points to be popped from the stack.

18 Graham-Scan Example Contd.
Stack S after each iteration of the for loop. Dashed lines show non-left turn which cause points to be popped from the stack.

19 Graham-Scan Example Contd.

20 Graham-Scan Example Contd.

21 Graham-Scan Example Contd.
The convex hull returned by the procedure.

22 Jarvis' March Simulates wrapping a taut piece of paper around the set Q Start by taping the paper to the lowest point p0 Pull the paper to the right to make it taut (tight), you then pull it higher until the paper touches a point. This point must be a vertex on the convex hull Keeping the paper taut, you continue in this way around the set of vertices until you come back to the original point, p0. Time Complexity = (n h) h = number of vertices in CH. Faster than Graham’s Scan Figure 33.9 Page 956

23 Jarvis' March Jarvis-March(P) P = {p0, ..., pn-1} points
p=p0, the lowest point while p not highest point find point pm with minimum polar angle from p add pm to convex hull p=pm while p!= p0

24 Example of Jarvis March
The first vertex chosen is the lowest point p0. The next vertex, p1, has the smallest polar angle with respect to p0.Then P2 has the smallest polar angle with respect to p1. The right chain goes as high as the highest point p3. Then, the left chain is constructed by finding smallest polar angle with respect to negative x-axis. P3 P2 P4 P1 P0


Download ppt "Computational Geometry Algorithms"

Similar presentations


Ads by Google