CS 157: Assignment 6

Similar documents
CS 157: Assignment 5

CS F-07 Objects in 2D 1

Today s class. Geometric objects and transformations. Informationsteknologi. Wednesday, November 7, 2007 Computer Graphics - Class 5 1

EXPANDING THE CALCULUS HORIZON. Robotics

Reteaching Golden Ratio

8.6 Three-Dimensional Cartesian Coordinate System

Graphics Output Primitives

Glossary alternate interior angles absolute value function Example alternate exterior angles Example angle of rotation Example

Minimum-Area Rectangle Containing a Set of Points

4.1 Angles and Angle Measure. 1, multiply by

What and Why Transformations?

The Graph Scale-Change Theorem

Lecture 1. Introduction

Two Dimensional Viewing

12.4 The Ellipse. Standard Form of an Ellipse Centered at (0, 0) (0, b) (0, -b) center

NONCONGRUENT EQUIDISSECTIONS OF THE PLANE

2.2 Absolute Value Functions

SECTION 6-8 Graphing More General Tangent, Cotangent, Secant, and Cosecant Functions

Computational Geometry

Section 2.2: Absolute Value Functions, from College Algebra: Corrected Edition by Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a

5 and Parallel and Perpendicular Lines

Polynomials. Math 4800/6080 Project Course

Module 2, Section 2 Graphs of Trigonometric Functions

Lines and Their Slopes

AVL Trees. Reading: 9.2

4.7 INVERSE TRIGONOMETRIC FUNCTIONS

Translations, Reflections, and Rotations

Sum and Difference Identities. Cosine Sum and Difference Identities: cos A B. does NOT equal cos A. Cosine of a Sum or Difference. cos B.

Computational Geometry

4.2 Properties of Rational Functions. 188 CHAPTER 4 Polynomial and Rational Functions. Are You Prepared? Answers

CMSC 425: Lecture 10 Basics of Skeletal Animation and Kinematics

2.4 Polynomial and Rational Functions

High-Dimensional Computational Geometry. Jingbo Shang University of Illinois at Urbana-Champaign Mar 5, 2018

3.2 Polynomial Functions of Higher Degree

Inclination of a Line

Unit 2: Function Transformation Chapter 1

Exponential and Logarithmic Functions

Exponential and Logarithmic Functions

Double Integrals in Polar Coordinates

ABSOLUTE EXTREMA AND THE MEAN VALUE THEOREM

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Spring, 2010

Geometric Algorithms. 1. Objects

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

A Quick Review of Trigonometry

Lecture 4: Viewing. Topics:

Contents. How You May Use This Resource Guide

Common Core Standards Addressed in this Resource

Unit Circle. Project Response Sheet

y = f(x) x (x, f(x)) f(x) g(x) = f(x) + 2 (x, g(x)) 0 (0, 1) 1 3 (0, 3) 2 (2, 3) 3 5 (2, 5) 4 (4, 3) 3 5 (4, 5) 5 (5, 5) 5 7 (5, 7)

12.1. Angle Relationships. Identifying Complementary, Supplementary Angles. Goal: Classify special pairs of angles. Vocabulary. Complementary. angles.

Multiple-choice (35 pt.)

Measurement and Geometry MEASUREMENT AND GEOMETRY

CS 335 Graphics and Multimedia. Geometric Warping

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

Proposal: k-d Tree Algorithm for k-point Matching

dt Acceleration is the derivative of velocity with respect to time. If a body's position at time t is S = f(t), the body's acceleration at time t is

Syllabus Objective: 3.1 The student will solve problems using the unit circle.

Computer Graphics. Modelling in 2D. 2D primitives. Lines and Polylines. OpenGL polygon primitives. Special polygons

Point Enclosure and the Interval Tree

Summer Review for Students Entering Pre-Calculus with Trigonometry. TI-84 Plus Graphing Calculator is required for this course.

Polar Functions Polar coordinates

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

triangles leaves a smaller spiral polgon. Repeating this process covers S with at most dt=e lights. Generaliing the polgon shown in Fig. 1 establishes

Computational Geometry

CS2 Algorithms and Data Structures Note 1

1. Use the Trapezium Rule with five ordinates to find an approximate value for the integral

C URVES AND V ECTORS

Introduction to Algorithms Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson.

Name Honors Geometry Final Exam Review. 1. The following figure is a parallelogram. Find the values of x and y.

Splay Trees. Splay Trees 1

IB SL REVIEW and PRACTICE

Inverse Trigonometric Functions:

3 Identify shapes as two-dimensional (lying in a plane, flat ) or three-dimensional ( solid ).

Using Characteristics of a Quadratic Function to Describe Its Graph. The graphs of quadratic functions can be described using key characteristics:

THE INVERSE GRAPH. Finding the equation of the inverse. What is a function? LESSON

Sieving Interior Collinear Points for Convex Hull Algorithms

CS 314H Algorithms and Data Structures Fall 2012 Programming Assignment #6 Treaps Due November 11/14/16, 2012

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

2.8 Distance and Midpoint Formulas; Circles

10.2: Parabolas. Chapter 10: Conic Sections. Conic sections are plane figures formed by the intersection of a double-napped cone and a plane.

Introduction to Algorithms Third Edition

MATH 31A HOMEWORK 9 (DUE 12/6) PARTS (A) AND (B) SECTION 5.4. f(x) = x + 1 x 2 + 9, F (7) = 0

Chapter 8 Sorting in Linear Time

turn counterclockwise from the positive x-axis. However, we could equally well get to this point by a 3 4 turn clockwise, giving (r, θ) = (1, 3π 2

The Sine and Cosine Functions

M O T I O N A N D D R A W I N G

Topic 2 Transformations of Functions

Appendix C: Review of Graphs, Equations, and Inequalities

Introduction to Homogeneous Transformations & Robot Kinematics

Unit 4 Trigonometry. Study Notes 1 Right Triangle Trigonometry (Section 8.1)

4. Two Dimensional Transformations

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

B + -trees. Kerttu Pollari-Malmi

Math 26: Fall (part 1) The Unit Circle: Cosine and Sine (Evaluating Cosine and Sine, and The Pythagorean Identity)

: Find the values of the six trigonometric functions for θ. Special Right Triangles:

4.6 Graphs of Other Trigonometric Functions

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

CSC Computer Graphics

1. The Pythagorean Theorem

Transcription:

CS 7: Assignment Douglas R. Lanman 8 Ma Problem : Evaluating Conve Polgons This write-up presents several simple algorithms for determining whether a given set of twodimensional points defines a conve polgon (i.e., a conve hull). In Section., we introduce the notion of regular polgons and provide eamples of both conve and non-conve point sets. Section. presents an algorithm for ordering a set of points such that a counterclockwise traversal defines the interior of the conve hull. In Section., we appl this method to determine whether a given set of points are the vertices of a conve hull. Finall, in Section., we derive a lower bound for the worst-case running time of all such vete-ordering algorithms..: Eamples of Conve and Non-conve Polgons Give an eample of a conve polgon and a non-conve polgon with,, and vertices. A general n-sided polgon can be described b an ordered sequence of vertices P = {p, p,..., p n }. We define the interior of the polgon to be to the left of the line from p i mod n to p i+ mod n for i n. As a result, the order of vertices within P matters. For this problem, however, we will concentrate on a simple case for P consisting of the set of regular polgons. A regular n-sided polgon has vertices evenl-distributed around a circle of radius r as follows. p i = ( i, i ) = ( r cos ( πi n ), r sin ( πi n )), for i n, r > () Ever regular polgon is also a conve polgon. In general, a conve polgon is one whose verte list P satisfies the following condition: the angle inside P formed b (p i mod n, p i, p i+ mod n ) is strictl less than 8 degrees, i [, n ]. In other words, when traveling along the sequence (p i mod n, p i, p i+ mod n ) one alwas takes a left turn at p i. Eamples of regular, conve polgons for n = {,, } are shown in Figure. A non-conve polgon can be defined as one which contains right turns or internal angles greater than or equal to 8 degrees. In general, if we append the verte (, ) to an regular polgon P............ (a) square (b) pentagon (c) heagon Figure : Eamples of conve polgons

Assignment CS 7 Douglas R. Lanman............ (a) n = (b) n = (c) n = Figure : Eamples of non-conve polgons defined b Equation, then we will create a non-conve polgon P. Eamples of the resulting non-conve polgons are shown in Figure..: Finding a Counterclockwise Ordering Given a set of points {p, p,..., p n } which are the vertices of a conve polgon in arbitrar order, find an ordering σ of the points such that P = {p σ(), p σ(),..., p σ(n ) } is a counterclockwise traversal. Your algorithm should have a running time of O(n log n). High-level Description: While the problem statement originall called for a divide-and-conquer solution, such an approach is needlessl complicated as we can assume for this problem that the input consists of a set of conve points in a randoml-shuffled order. As a result (and with permission from the TA), I propose the following simple solution derived from Graham s Scan [, ]. The inputs to Order-Vertices are the verte coordinates (, ) and the output is the counterclockwise ordering σ. The pseudocode description is provided below. Order-Vertices(, ) Find bottom-left verte. n length[] i for j to n do if [j] < [i] then i j 7 if [j] = [i] and [j] < [i] 8 then i j 9 Determine polar angles. for j to n do if [j] = [i] then if [j] > [i] then θ[j] = π/ else θ[j] = π/ else θ[j] = arctan ( [j] [i] [j] [i] sort θ into monotonicall-increasing order to find σ 7 return σ )

Assignment CS 7 Douglas R. Lanman 9 9 8. 8. 7 7...... (a) input point set (b) ordered point set Figure : Eample of output produced b Order-Vertices for n = Proof of Correctness: Before we prove the overall correctness of Order-Vertices, let s verif the outcome of each section independentl. In the first section (on lines -8), we determine the left-most verte (breaking ties in favor of lower points). The correctness of this section is immediate a linear search through the coordinates returns the desired point. In the second section (on lines 9-), we determine the polar angles each verte makes with respect the the reference verte in the lower-left corner. In general, we can use the following simple trigonometric relationship to determine the angle θ (from the -ais) between points p i and p j. ( ) [j] [i] θ[j] = arctan () [j] [i] The correctness of this solution is also immediate. Similarl, we assume that the sorting routine (on line ) correctl arranges the polar angles into monotonicall-ascending order. Note that we handle the special case of the coordinates of the vertices being equal (e.g., Figure (b)) eplicitl on lines -. In conclusion, the individual sections of Order-Vertices are correct. To prove the overall correctness, consider the eample in Figure (a). If we draw a line from verte (the left-most verte) along the -ais, and if we rotate this line to the right, then it will touch each point in counterclockwise order. This is due to the fact that the input set is conve. As a result, the polar angles of each point uniquel determine their correct order in the output σ. Analsis of Running Time: The asmptotic worst-case running time of Order-Vertices is O(n log n). We can prove this directl b analzing the pseudocode. On lines -8 we search for the left-most verte (breaking ties in favor of lower points). Since this section onl involves constant time comparisons and assignments, then the running time is O(n) corresponding to the order of iterations of the for loop on line. Similarl, the section of code on lines 9- is used to determine the set of polar angles (with respect to the lower-left verte). Once again, this section involves constant time operations and has a running time of O(n) due to the for loop on line. In order to produce the desired counterclockwise traversal σ, we must sort the points b their polar angles. This can be accomplished using a variet of sorting algorithms presented in [] with a running time of O(n log n). As a result, the asmptotic worst-case running time of Order- Vertices is O(n log n). (QED)

Assignment CS 7 Douglas R. Lanman.: Determining if a Point Set is Conve Etend our algorithm to solve the decision problem: given a set of points {p, p,..., p n }, decide whether the are the vertices of a conve polgon. High-level Description: Initiall, one might tr solving this problem using the approach outlined in Problem.- in []. That is, after ordering the points using Order-Vertices, check that each consecutive pair of edges has an internal angle less than 8 degrees (i.e., that we alwas make a left turn when traversing the ordered verte list). While this would work for simple polgons with no self-intersections, one could imagine a comple polgon which intersects itself resulting in a non-conve polgon with all left turns. As a result, we must improve upon this naive approach. Recall the following classic result from planar geometr: the sum of the internal angles of a simple n-sided polgon is equal to (n )π radians for n []. Given this constraint, we can easil verif that a polgon is simple (i.e., is not self-intersecting) and, as a result, we can check that the internal angles are all less than 8 degrees (and that this constraint is satisfied). As a result, we propose Test-Conve below to determine if a set of points represents a conve polgon. The inputs to Test-Conve are the verte coordinates (, ) and the output is a boolean indicating whether or not the points define a conve polgon. (Note that subscript addition is performed modulo n in this pseudocode description.) Test-Conve(, ) σ Order-Vertices(, ) reorder (, ) using σ n length[] A for i to n ( ) ([i + ] [i]) ([i + ] [i]) do C det ([i + ] [i]) ([i + ] [i]) 7 if C 8 then return false 9 a ([i + ] [i]) + ([i + ] [i]) b ([i ] [i]) + ([i ] [i]) c ([i + ] ( [i ]) ) + ([i + ] [i ]) A A + arccos a +b c if A = (n )π then return true else return false ab Proof of Correctness: The correctness of Test-Conve follows from the definition of a conve polgon. That is, a conve polgon must have internal angles strictl less than 8 degrees and the sum of its internal angles must equal (n )π radians. As a result, we must prove that our method for determining the internal angles and their sum is correct. Recall that the cross product can be used to determine how consecutive line segments turn at a point p i, as shown in [] on pages 9 and 9. In general, the sign of the cross product C, where ( ) ([i + ] [i]) ([i + ] [i]) C = det () ([i + ] [i]) ([i + ] [i]) is positive if and onl if the edge turns to the left at p i []. As a result, we check this condition for each verte on lines -8 (returning false if this test fails).

Assignment CS 7 Douglas R. Lanman.. p i+ a c θ b p i.. (a) Law of Cosines illustration p i.8 9. 8. 7... (b) Eample used to prove Ω(n log n) Figure : Law of Cosines used in Test-Conve and the eample from Section.. Assuming that ever pair of consecutive edges makes a left turn, we still must verif that the polgon is simple. We can do this b storing the running sum of the internal angles. In order to compute the internal angles, we simpl appl the Law of Cosines. For the eample shown in Figure (a), the Law of Cosines requires c = a + b ab cos θ () As a result, the internal angle θ is given b ( a + b c ) θ = arccos ab () This operation is performed on lines 9- and the constraint that the sum of internal angles equals (n )π is verified on line. As a result, Test-Conve correctl determines if the input point set represents a conve polgon. Analsis of Running Time: The running time of Test-Conve is clearl O(n log n). We can prove this b direct inspection. Lines,, - all involve constant time operations. Similarl, lines - also involve constant time operations (assuming arccos is implemented b a constant-time lookup table). As a result, the asmptotic worst-case running time for lines - is determined b the for loop on line and is O(n). Since the reordering on line can be accomplished in O(n) given σ, the overall asmptotic worst case running time is due to the call to Order-Vertices on line and is O(n log n). (QED).: A Lower Bound on all Verte-Ordering Algorithms Prove that ever verte-ordering algorithm whose comparison operations are binar (i.e., an test performed has onl two outcomes) must have compleit Ω(n log n) in the worst case. A simple eample illustrates that an algorithm which determines the order of vertices in a conve polgon (e.g., the approach presented in Section.) must have compleit Ω(n log n) in the worst case. Consider the point set shown in Figure (b). In this eample, we have ten points on the parabola given b =. The desired counterclockwise ordering is given b sorting the vertices b their coordinate. Recall Theorem 8. from []: an comparison sort requires Ω(n log n) in

Assignment CS 7 Douglas R. Lanman the worst case. As a result, the verte-ordering task must also have a worst-case compleit of Ω(n log n). As presented in Chaper 8 of [], this lower bound can be understood b considering the decision tree for the verte-ordering task. Unlike one-dimensional (i.e., arra) sorting algorithms, the solution of the verte-ordering task is not unique; that is, the sorted vertices can appear in an cclic permutation. Regardless, we can alwas select a verte to be first in the list. Afterwards, there remaining n vertices which must be ordered. As with arra sorting, the decision tree must contain all (n )! permutations as a leaf. Following the derivation of [], the height h of the decision tree must satisf the following relationship. h (n )! h log ((n )!) = Ω(n log n) () In conclusion, we have demonstrated that all verte-ordering algorithms must have worst-case compleit Ω(n log n) b the eample in Figure (b). It is important to note that this eample was first proposed b Shamos and Preparata []. (QED) Conclusion This write-up reviewed the notion of conve polgons and presented several algorithms for determining whether a given point set represents one. The algorithm presented in Section. (and its analsis in Section.) is of general utilit, however this document has not eplored the larger issue of determining a conve hull for an arbitrar point set. This more general problem is of central importance to the field of computation geometr. Interested readers are referred to Shamos and Preparata [] for a detailed presentation of conve hull algorithms. In addition, see [] for a divide-and-conquer solution to Problem.. References [] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. The MIT Press and McGraw-Hill,. [] Jeff Erickson. Conve hulls. http://compgeom.cs.uiuc.edu/ jeffe/teaching/7/notes/ -convehull.pdf,. [] Michael I. Shamos and Franco P. Preparata. Computational Geometr: An Introduction. Springer-Verlag, 98. [] Wikipedia. Polgon. http://en.wikipedia.org/wiki/polgon,.