Polygon Clipping and Filling Week 3, Lecture 5

Similar documents
NURBS Drawing Week 5, Lecture 10

NURBS Drawing Week 5, Lecture 10

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

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

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

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

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

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

Shortest Path Algorithms

39 Symmetry of Plane Figures

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

Triangulation by Ear Clipping

INTRODUCTION TO RENDERING TECHNIQUES

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

1. Application of Computer Graphics

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

Computational Geometry. Lecture 1: Introduction and Convex Hulls

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.

Cabri Geometry Application User Guide

Baltic Way Västerås (Sweden), November 12, Problems and solutions

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

COMPUTER GRAPHICS IMPORTANT QUESTION AND ANSWERS. Computer graphics

Largest Fixed-Aspect, Axis-Aligned Rectangle

Solving Geometric Problems with the Rotating Calipers *

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

Session 5 Dissections and Proof

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

PYTHAGOREAN TRIPLES KEITH CONRAD

Introduction Week 1, Lecture 1

Selected practice exam solutions (part 5, item 2) (MAT 360)

Inversion. Chapter Constructing The Inverse of a Point: If P is inside the circle of inversion: (See Figure 7.1)

A HYBRID APPROACH FOR AUTOMATED AREA AGGREGATION

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

Computer Graphics Lecture Notes

Angles that are between parallel lines, but on opposite sides of a transversal.

Introduction to CATIA V5

INCIDENCE-BETWEENNESS GEOMETRY

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

To draw a line. To create a construction line by specifying two points

Introduction to Computer Graphics

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

Class One: Degree Sequences

Figure 2.1: Center of mass of four points.

CS 4204 Computer Graphics

The Essentials of CAGD

The GeoMedia Fusion Validate Geometry command provides the GUI for detecting geometric anomalies on a single feature.

Chapter 6 Notes: Circles

Reflection and Refraction

ME 111: Engineering Drawing

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

GeoGebra. 10 lessons. Gerrit Stols

Chapters 6 and 7 Notes: Circles, Locus and Concurrence

Tutorial 1: The Freehand Tools

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

SOLIDS, NETS, AND CROSS SECTIONS

11.3 Curves, Polygons and Symmetry

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

Visualization of 2D Domains

4. How many integers between 2004 and 4002 are perfect squares?

5.1 Bipartite Matching

CHAPTER 8, GEOMETRY. 4. A circular cylinder has a circumference of 33 in. Use 22 as the approximate value of π and find the radius of this cylinder.

2. If C is the midpoint of AB and B is the midpoint of AE, can you say that the measure of AC is 1/4 the measure of AE?

Essential Mathematics for Computer Graphics fast

Planar Curve Intersection

Marist School Computational Media. Processing Exercise 01 Bouncing Ball Animation. Description:

Jiří Matas. Hough Transform

1. A student followed the given steps below to complete a construction. Which type of construction is best represented by the steps given above?

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

ON TORI TRIANGULATIONS ASSOCIATED WITH TWO-DIMENSIONAL CONTINUED FRACTIONS OF CUBIC IRRATIONALITIES.

Picture Maze Generation by Successive Insertion of Path Segment

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

How To Draw In Autocad

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Art Tuts Learn how to draw, animate, etc. Inkscape tutorials How to draw a candle. Candle

Lecture Notes, CEng 477

CMPSCI611: Approximating MAX-CUT Lecture 20

Linear Programming I

ME 111: Engineering Drawing

Chapter Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

Sum of Degrees of Vertices Theorem

28 Closest-Point Problems

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Persistent Data Structures

DEFINITIONS. Perpendicular Two lines are called perpendicular if they form a right angle.

Quickstart for Desktop Version

Canterbury Maps Quick Start - Drawing and Printing Tools

Intermediate Tutorials Modeling - Trees. 3d studio max. 3d studio max. Tree Modeling Matthew D'Onofrio Page 1 of 12

Basic controls of Rhinoceros 3D software

Pro/ENGINEER Wildfire 4.0 Basic Design

Computer Animation: Art, Science and Criticism

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Solutions to Homework 6

Constrained Tetrahedral Mesh Generation of Human Organs on Segmented Volume *

IMO Geomety Problems. (IMO 1999/1) Determine all finite sets S of at least three points in the plane which satisfy the following condition:

Discrete Optimization

Gerrit Stols

CSE 167: Lecture 13: Bézier Curves. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Outline. Quantizing Intensities. Achromatic Light. Optical Illusion. Quantizing Intensities. CS 430/585 Computer Graphics I

Geometry 1. Unit 3: Perpendicular and Parallel Lines

Transcription:

CS 430/536 Computer Graphics I Polygon Clipping and Filling Week 3, Lecture 5 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http://gicl.cs.drexel.edu Outline Polygon clipping Sutherland-Hodgman, Weiler-Atherton Polygon filling Scan filling polygons Flood filling polygons Introduction and discussion of homework # Polygon Ordered set of vertices (points) Usually counter-clockwise Two consecutive vertices define an edge Left side of edge is inside Right side is outside Last vertex implicitly connected to first In 3D vertices are co-planar 3 Polygon Clipping Lots of different cases Issues Edges of polygon need to be tested against clipping rectangle May need to add new edges Edges discarded or divided Multiple polygons can result from a single polygon 4 The Sutherland-Hodgman Polygon-Clipping Algorithm Divide and Conquer Idea: Clip single polygon using single infinite clip edge Repeat 4 times Note the generality: D convex n-gons can clip arbitrary n-gons 3D convex polyhedra can clip arbitrary polyhedra 5 Input: v, v, v n the vertices defining the polygon Single infinite clip edge w/ inside/outside info Output: v, v, v m, vertices of the clipped polygon Do this 4 (or n e ) times Traverse vertices (edges) Add vertices one-at-a-time to output polygon Use inside/outside info Edge intersections 6

Can be done incrementally If first point inside add. If outside, don t add Move around polygon from v to v n and back to v Check v i,v i+ wrt the clip edge Need v i,v i+ s inside/outside status Add vertex one at a time. There are 4 cases: 7 foreach polygon P P = P foreach clipping edge (there are 4) { Clip polygon P to clipping edge foreach edge in polygon P» Check clipping cases (there are 4)» Case : Output v i+» Case : Output intersection point» Case 3 : No output» Case 4 : Output intersection point & v i+ } 8 Animated by Max Peysakhov @ Drexel University 9 Final Result Note: Edges XY and ZW! Issues with Sutherland- Hodgman Algorithm Clipping a concave polygon Can produce two CONNECTED areas 0 Animated by Max Peysakhov @ Drexel University

Weiler-Atherton Algorithm General clipping algorithm for concave polygons with holes Produces multiple polygons (with holes) Make linked list data structure Traverse to make new polygon(s) Weiler-Atherton Algorithm Given polygons A and B as linked list of vertices (counter-clockwise order) Find all edge intersections & place in list Insert as intersection nodes Nodes point to A & B Determine in/out status of vertices Intersection Special Cases If intersecting edges are parallel, ignore Intersection point is a vertex Vertex of A lies on a vertex or edge of B Edge of A runs through a vertex of B Replace vertex with an intersection node 3 4 5 Weiler-Atherton Algorithm: Union Find a vertex of A outside of B Traverse linked list At each intersection point switch to other polygon Do until return to starting vertex All visited vertices and nodes define union ed polygon 6 Weiler-Atherton Algorithm: Intersection Start at intersection point If connected to an inside vertex, go there Else step to an intersection point If neither, stop Traverse linked list At each intersection point switch to other polygon and remove intersection point from list Do until return to starting intersection point If intersection list not empty, pick another one All visited vertices and nodes define and ed polygon 7 Boolean Special Cases If polygons don t intersect Union If one inside the other, return polygon that surrounds the other Else, return both polygons Intersection If one inside the other, return polygon inside the other Else, return no polygons 8 3

Point P Inside a Polygon? Connect P with another point P` that you know is outside polygon Intersect segment PP` with polygon edges Watch out for vertices! If # intersections is even (or 0) Outside If odd Inside Edge clipping Re-use line clipping from HW Similar triangles method Cyrus-Beck line clipping Yet another technique Intersecting Two Edges () Edge 0 : (P 0,P ) Edge : (P,P 3 ) E 0 = P 0 + t 0 *(P -P 0 ) D 0 (P -P 0 ) E = P + t *(P 3 -P ) D (P 3 -P ) P 0 + t 0 *D 0 = P + t *D x 0 +dx 0 * t 0 = x +dx * t y 0 +dy 0 * t 0 = y +dy * t 9 0 4 Intersecting Two Edges () Solve for t s t 0 = ((x 0 - x ) * dy + (y - y 0 ) * dx ) / (dy 0 * dx - dx 0 * dy ) t = ((x - x 0 ) * dy 0 + (y 0 - y ) * dx 0 ) / (dy * dx 0 - dx * dy 0 ) See http://www.vb-helper.com/howto_intersect_lines.html for derivation Edges intersect if 0 t 0,t Edges are parallel if denominator = 0 5 Filling Primitives: Rectangles, Polygons & Circles Two part process Which pixels to fill? What values to fill them with? Idea: Coherence Spatial: pixels are the same from pixel-to-pixel and scan-line to scan line; Span: all pixels on a span get the same value Scan-line: consecutive scan lines are the same Edge: pixels are the same along edges 6 Scan Filling Primitives: Rectangles Easy algorithm Fill from x min to x max Fill from y min to y max Issues What if two adjacent rectangles share an edge? Color the boundary pixels twice? Rules: Color only interior pixels Color left and bottom edges 7 4

Scan Filling Primitives: Polygons Observe: FA, DC intersections are integer FE, ED intersections are not integer For each scan line, how to figure out which pixels are inside the polygon? Scan Filling Polygons Idea #: use midpoint algo on each edge, fill in between extrema points Note: many extrema pixels lie outside the polygon Why: midpoint algo has no sense of in/out Scan Filling Polygons Idea #: draw pixels only strictly inside Find intersections of scan line with edges Sort intersections by increasing x coordinate Fill pixels on inside based on a parity bit B p initially even (off) Invert at each intersect Draw with odd, do not draw when even 8 9 30 Scan Filling Polygons How to handle vertices? How to handle horizontal edges? Issues with Idea #: If at a fractional x value, how to pick which pixels are in interior? Intersections at integer vertex coordinates? Shared vertices? Vertices that define a horizontal edge? 3 Problem: vertices are counted twice Solution: If both neighboring vertices are on the same side of the scan line, don t count it If both neighboring vertices are on different sides of a scan line, count it once Compare current y value with y value of neighboring vertices Y Y Y Y 3 Idea: don t count their vertices Apply open and closed status to vertices to other edges y min vertex closed y max vertex is open On AB, A is at y min for JA; AB does not contribute, B p is odd and draw AB Edge BC has y min at B, but AB does not contribute, B p becomes even and drawing stops 33 5

How to handle horizontal edges? Start drawing at IJ (B p becomes odd). C is y max (open) for BC. B p doesn t change. Ignore CD. D is y min (closed) for DE. B p becomes even. Stop drawing. I is y max (open) for IJ. No drawing. Ignore IH. H is y min (closed) for GH. B p becomes odd. Draw to FE. Ignore GF. No drawing 34 Polygon Filling Algorithm For each polygon For each edge, mark each scan-line that the edge crosses by examining its y min and y max If edge is horizontal, ignore it If y max on scan-line, ignore it If y min <= y < y max add edge to scan-line y s edge list For each scan-line between polygon s y min and y max Calculate intersections with edges on list Sort intersections in x Perform parity-bit scan-line filling Check for double intersection special case Clear scan-lines edge list 36 How to handle slivers? When the scan area does not have an interior Solution: use anti-aliasing But, to do so will require softening the rules about drawing only interior pixels 37 Scan-Filling a Polygon Scan Filling Curved Objects Hard in general case Easier for circles and ellipses. Use midpoint Alg to generate boundary points. Fill in horizontal pixel spans Use symmetry Boundary-Fill Algorithm Start with some internal point (x,y) Color it Check neighbors for filled or border color Color neighbors if OK Continue recursively 38 Animated by Max Peysakhov @ Drexel University 39 40 6

4 Connected Boundary-Fill Alg Void BoundaryFill4( int x, int y, int fill, int bnd) { If Color(x,y)!= fill and Color(x,y)!= bnd { SetColor(x,y) = fill; BoundaryFill4(x+, y, fill, bnd); BoundaryFill4(x, y +, fill, bnd); BoundaryFill4(x-, y, fill, bnd); BoundaryFill4(x, y -, fill, bnd); } Boundary-Fill Algorithm Issues with recursive boundary-fill algorithm: May make mistakes if parts of the space already filled with the Fill color Requires very big stack size More efficient algorithms First color contiguous span along one scan line Only stack beginning positions of neighboring scan lines Course Status So far everything straight lines! How to model D curved objects? Representation Circles Types of D Curves Parametric Cubic Curves Bézier Curves, (non)uniform, (non)rational NURBS Drawing of D Curves Line drawing algorithms for complex curves DeCasteljeau, Subdivision, De Boor } 4 4 44 Homework # Modify homework # Add moveto and lineto commands They define closed polygons Clip polygons against window with Sutherland-Hodgman algorithm Display edges with HW line-drawing code 45 7