xo-sweepline - Algorithms Non-Lecture O: Line Segment...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Algorithms Non-Lecture O: Line Segment Intersection Spengler: There’s something very important I forgot to tell you. Venkman: What? Spengler: Don’t cross the streams. Venkman: Why? Spengler: It would be bad. Venkman: I’m fuzzy on the whole good/bad thing. What do you mean, “bad"? Spengler: Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light. Stantz: Total protonic reversal. Venkman: Right. That’s bad. Okay. All right. Important safety tip. Thanks, Egon. — Ghostbusters (1984) O Line Segment Intersection O.1 Introduction In this lecture, I’ll talk about detecting line segment intersections. A line segment is the convex hull of two points, called the endpoints (or vertices ) of the segment. We are given a set of n line segments, each specified by the x- and y-coordinates of its endpoints, for a total of 4 n real numbers, and we want to know whether any two segments intersect. To keep things simple, just as in the previous lecture, I’ll assume the segments are in general position . • No three endpoints lie on a common line. • No two endpoints have the same x-coordinate. In particular, no segment is vertical, no segment is just a point, and no two segments share an endpoint. This general position assumption lets us avoid several annoying degenerate cases. Of course, in any real implementation of the algorithm I’m about to describe, you’d have to handle these cases. Real-world data is full of degeneracies! Degenerate cases of intersecting segments that we’ll pretend never happen: Overlapping colinear segments, endpoints inside segments, and shared endpoints. O.2 Two segments The first case we have to consider is n = 2. (The problem is obviously trivial when n ≤ 1!) How do we tell whether two line segments intersect? One possibility, suggested by a student in class, is to construct the convex hull of the segments. Two segments intersect if and only if the convex hull is a quadrilateral whose vertices alternate between the two segments. In the figure below, the first pair of segments has a triangular convex hull. The last pair’s convex hull is a quadrilateral, but its vertices don’t alternate. Some pairs of segments. 1 Algorithms Non-Lecture O: Line Segment Intersection Fortunately, we don’t need (or want!) to use a full-fledged convex hull algorithm just to test two segments; there’s a much simpler test. Two segments ab and cd intersect if and only if • the endpoints a and b are on opposite sides of the line ←→ cd , and • the endpoints c and d are on opposite sides of the line ←→ ab . To test whether two points are on opposite sides of a line through two other points, we use the same counterclockwise test that we used for building convex hulls. Specifically, a and b are on opposite sides of line ←→ cd if and only if exactly one of the two triples a , c , d and b , c , d is in counterclockwise order. So we have the following simple algorithm.we have the following simple algorithm....
View Full Document

This note was uploaded on 12/15/2009 for the course 942 cs taught by Professor A during the Spring '09 term at University of Illinois at Urbana–Champaign.

Page1 / 5

xo-sweepline - Algorithms Non-Lecture O: Line Segment...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online