Line and Polygon Clipping. Foley & Van Dam, Chapter 3



Similar documents
2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

Largest Fixed-Aspect, Axis-Aligned Rectangle

Scan Conversion of Filled Primitives Rectangles Polygons. Many concepts are easy in continuous space - Difficult in discrete space

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

Shortest Path Algorithms

The Essentials of CAGD

Intersection of a Line and a Convex. Hull of Points Cloud

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

3. Evaluate the objective function at each vertex. Put the vertices into a table: Vertex P=3x+2y (0, 0) 0 min (0, 5) 10 (15, 0) 45 (12, 2) 40 Max

Intersection of Convex Objects: The Method of Separating Axes

CHAPTER SIX IRREDUCIBILITY AND FACTORIZATION 1. BASIC DIVISIBILITY THEORY

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Shortest Inspection-Path. Queries in Simple Polygons

Planar Curve Intersection

Face detection is a process of localizing and extracting the face region from the

INTRODUCTION TO RENDERING TECHNIQUES

Solutions for Review Problems

MATH 10550, EXAM 2 SOLUTIONS. x 2 + 2xy y 2 + x = 2

Basic Problem: Map a 3D object to a 2D display surface. Analogy - Taking a snapshot with a camera

Computer Graphics Lecture Notes

Figure 2.1: Center of mass of four points.

G.H. Raisoni College of Engineering, Nagpur. Department of Information Technology

Vector storage and access; algorithms in GIS. This is lecture 6

3.1 Solving Systems Using Tables and Graphs

The continuous and discrete Fourier transforms

Computer Graphics. Geometric Modeling. Page 1. Copyright Gotsman, Elber, Barequet, Karni, Sheffer Computer Science - Technion. An Example.

MATH 304 Linear Algebra Lecture 20: Inner product spaces. Orthogonal sets.

2.2 Creaseness operator

Transformations in the pipeline

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

1. Prove that the empty set is a subset of every set.

Computer Graphics CS 543 Lecture 12 (Part 1) Curves. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

We can display an object on a monitor screen in three different computer-model forms: Wireframe model Surface Model Solid model

2008 AP Calculus AB Multiple Choice Exam


Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Geometry Chapter Point (pt) 1.1 Coplanar (1.1) 1.1 Space (1.1) 1.2 Line Segment (seg) 1.2 Measure of a Segment

Binary Image Scanning Algorithm for Cane Segmentation

Drawing a histogram using Excel

Sum of Degrees of Vertices Theorem

Section 2.7 One-to-One Functions and Their Inverses

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

a. all of the above b. none of the above c. B, C, D, and F d. C, D, F e. C only f. C and F

160 CHAPTER 4. VECTOR SPACES

Graph Theory Lecture 3: Sum of Degrees Formulas, Planar Graphs, and Euler s Theorem Spring 2014 Morgan Schreffler Office: POT 902

CS 4204 Computer Graphics

AP Calculus AB 2006 Scoring Guidelines

Mean Value Coordinates

Auto-Tuning Using Fourier Coefficients

Contents. 2 Lines and Circles Cartesian Coordinates Distance and Midpoint Formulas Lines Circles...

H.Calculating Normal Vectors

Zabin Visram Room CS115 CS126 Searching. Binary Search

AP Calculus AB 2010 Free-Response Questions Form B

or, put slightly differently, the profit maximizing condition is for marginal revenue to equal marginal cost:

Inverse Functions and Logarithms

Multi-variable Calculus and Optimization

Max-Min Representation of Piecewise Linear Functions

Geometry Module 4 Unit 2 Practice Exam

Visualization of 2D Domains

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Cabri Geometry Application User Guide

NURBS Drawing Week 5, Lecture 10

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

Machine vision systems - 2

Linear Programming I

Math 241, Exam 1 Information.

1. Application of Computer Graphics

5.1 Derivatives and Graphs

Arrangements And Duality

The Heat Equation. Lectures INF2320 p. 1/88

MA107 Precalculus Algebra Exam 2 Review Solutions

5.7 Maximum and Minimum Values

Computational Foundations of Cognitive Science

CSC2420 Spring 2015: Lecture 3

AP Calculus AB 2004 Scoring Guidelines

Review Sheet for Test 1

Geometry Regents Review

Curves and Surfaces. Goals. How do we draw surfaces? How do we specify a surface? How do we approximate a surface?

2013 MBA Jump Start Program

Grade 7 & 8 Math Circles Circles, Circles, Circles March 19/20, 2013

PRACTICE FINAL. Problem 1. Find the dimensions of the isosceles triangle with largest area that can be inscribed in a circle of radius 10cm.

A characterization of trace zero symmetric nonnegative 5x5 matrices

NURBS Drawing Week 5, Lecture 10

Choice under Uncertainty

Calculus AB 2014 Scoring Guidelines

Geometry Unit 6 Areas and Perimeters

Lesson 16 Analog-to-Digital Converter (ADC)

AP Calculus BC 2006 Free-Response Questions

Microeconomic Theory: Basic Math Concepts

Proximal mapping via network optimization

minimal polyonomial Example

2D Geometrical Transformations. Foley & Van Dam, Chapter 5

Solutions to Homework 10

Math 115 Extra Problems for 5.5

Solutions to old Exam 1 problems

6.1 Add & Subtract Polynomial Expression & Functions

MATH 425, PRACTICE FINAL EXAM SOLUTIONS.

The Math Circle, Spring 2004

Transcription:

Line and Polygon Clipping Foley & Van Dam, Chapter 3

Topics Viewing Transformation Pipeline in 2D Line and polygon clipping Brute force analytic solution Cohen-Sutherland Line Clipping Algorithm Cyrus-Beck Line Clipping Algorithm Sutherland-Hodgman Polygon Clipping Sampling Theorem (Nyquist Frequency)

Viewing Transformation in 2D y world y view y view x view x world World and Viewing Coordinates Clipping x view 1 Device Coordinates 1 Normalized Device Coordinates

Viewing Transformation in 2D Objects are given in world coordinates The world is viewed through a window The window is mapped onto a device viewport A scene in World-Coordinates WC World-Coordinates to Viewing Coordinates VC Viewing Coordinates to Normalized Device Coordinates NDC Normalized Device Coordinates to Device Coordinates DC Clipping

Line and Polygon Clipping The problem: Given a set of 2D lines or polygons and a window, clip the lines or polygons to their regions that are inside the window

Motivations Efficiency Display in portion of a screen Occlusions clip rectangle

Line Clipping We will deal only with lines (segments) Our window can be described by two extreme points: (x min,y min ) and (x max,y max ) A point (x,y) is in the window iff: x min x x max and y min y y max

Brute Force Analytic Solution S S S W W W 0, 1, or 2 intersections between a line and a window The intersection of convex regions is always convex Since both W and S are convex, their intersection is convex, i.e a single connected segment of S Question: Can the boundary of two convex shapes intersect more than twice?

Pseudo Code for Midpoint Line Drawing Line(x 0,y 0,x 1,y 1 ) begin int dx, dy, x, y, d, E, ΝE ; x:= x 0 ; y=y 0 ; dx := x 1 -x 0 ; dy := y 1 -y 0 ; d := 2*dy-dx; E := 2*dy; ΝΕ := 2*(dy-dx); PlotPixel(x,y); while(x < x 1 ) do if (d < 0) then d:=d+ E ; x:=x+1; end; else d:=d+ ΝE ; x:=x+1; y:=y+1; end; PlotPixel(x,y); end; end; Assume x 1 >x 0 and 0 < slope 1

Line Clipping Midpoint Algorithm: Intersection with a vertical edge x = x min (x min,round(mx min +B)) (x min, mx min +B) M Q NE E y = y min

Line Clipping Midpoint Algorithm: Intersection with a horizontal edge x = x min B A y = y min y = y min -1/2

Cohen-Sutherland for Line Clipping Clipping is performed by computing intersections with four boundary segments of the window: L i, i=1,2,3,4 Purpose: Fast treatment of lines that are trivially inside/outside the window Let P=(x,y) be a point to be classified against window W Idea: Assign P a binary code consisting of a bit for each edge of W. The bit is 1 if the pixel is in the half-plane that does not contain W

Cohen-Sutherland for Line Clipping bit 1 0 1 y < y min y y min 2 y > y max y y max 3 x > x max x x max 4 x < x min x x min y max y min 0101 0001 1001 4 x min 0100 0000 1000 x max 3 0110 0010 1010 2 1

Cohen-Sutherland for Line Clipping 0101 0001 1001 0100 0000 1000 0110 0010 1010 Given a line segment S from p 0 =(x 0,y 0 ) to p 1 =(x 1,y 1 ) to be clipped against a window W If code(p 0 ) AND code(p 1 ) is not zero, then S is trivially rejected If code(p 0 ) OR code(p 1 ) is zero, then S is trivially accepted

Cohen-Sutherland for Line Clipping Otherwise: let assume w.l.o.g. that p 0 is outside W Find the intersection of S with the edge corresponding to the MSB in code(p 0 ) that is equal to 1. Call the intersection point p 2. Run the procedure for the new segment (p 1, p 2 ). D 4 3 C B A F G H I 2 1 E

Cyrus-Beck Line Clipping N U V 1 inside V 0 Inside/Outside Test: Assume WLOG that V=(V 1 -V 0 ) is the border vector where "inside" is to its right If V=(V x,v y ), N is the normal to V, pointing outside, defined by N=(-V y,v x ) Vector U points "outside" if N U > 0 Otherwise U points "inside"

Cyrus-Beck Line Clipping N V(t) Q P 1 inside P 0 L The parametric line P(t)=P 0 +(P 1 -P 0 )t The parametric vector V(t)=P(t)-Q The segment P 0 P 1 intersects the line L at t 0 satisfying V(t 0 ) N=0 The intersection point is P(t 0 ) =P 1 -P 0 points inside if (P 1 -P 0 ) N<0. Otherwise it points outside If L is vertical, intersection can be computed using the explicit equation

Cyrus-Beck Line Clipping Ni Qi p 0 p 1 Denote p(t)=p 0 +(p 1 -p 0 )t t [0..1] Let Q i be a point on the edge L i with outside pointing normal N i V(t) = p(t)-q i is a parameterized vector from Q i to the segment P(t) N i V(t) = 0 iff V(t) N i We are looking for t satisfying N i V(t) = 0

Cyrus-Beck Line Clipping 0 = N i V(t) = N i (p(t)-q i ) = N i (p 0 +(p 1 -p 0 )t-q i ) = N i (p 0 -Q i ) + N i (p 1 -p 0 )t Solving for t we get: N i (p 0 -Q i ) t = -N i (p 1 -p 0 ) where =(p 1 -p 0 ) = N i (p 0 -Q i ) -N i Comment: If N i =0, t has no solution (V(t) N i )

Cyrus-Beck Line Clipping p 1 PE p 1 PL PL PL p 0 PE PE PL p 1 PE p 0 p 0

Cyrus-Beck Line Clipping The intersection of p(t) with all four edges L i is computed, resulting in up to four t i values If t i <0 or t i >1, t i can be discarded Based on the sign of N i, each intersection point is classified as PE (potentially entering) or PL (potentially leaving) PE with the largest t and PL with the smallest t provide the domain of p(t) inside W The domain, if inverted, signals that p(t) is totally outside

Sutherland-Hodgman Polygon-Clipping Algorithm

Sutherland-Hodgman Polygon-Clipping Algorithm Idea: Clip a polygon by successively clipping against each (infinite) clip edge After each clipping a new set of vertices is produced. right clip boundary bottom clip boundary left clip boundary top clip boundary

Sutherland-Hodgman Polygon-Clipping Algorithm For each clip edge - scan the polygon and consider the relation between successive vertices of the polygon Each iteration adds 0, 1 or 2 new vertices Assume vertex s has been dealt with, vertex p follows: inside s outside inside outside inside outside p inside p i outside s p clip boundary p added to output list s i p clip boundary i added to output list s clip boundary no output clip boundary i and p added to output list

Sutherland-Hodgman Polygon-Clipping Algorithm V 2 V' 2 Window V 3 V 2 V 1 V 3 V 1 Left Clipping Right Clipping Bottom Clipping Top Clipping V 1 V 2 V 3 V 1 V 2 V 2 V 3 V 1 V 2 V 2 V 3 V 1 V 2 V 2 V 2

Sampling Theorem Question: How dense should be the pixel grid in order to draw properly a drawn object? Given a sampling at intervals equal to d then one may recover frequencies of wavelength > 2d Aliasing: If the sampling interval is more than 1/2 the wavelength, erroneous frequencies may be produced

Sampling Theorem 1D Example: 0 π 2π 3π 4π 5π 6π Rule of Thumb: To observe details of size d one must sample at d/2 intervals To observe details at frequency f (=1/d) one must sample at frequency 2f. The Frequency 2f is the NYQUIST frequency

Sampling Theorem 2D Example: Moire Effect