MODULE - 9. Subject: Computer Science. Module: Line Clipping. Module No: CS/CGV/9

Similar documents
Clipping Lines. Dr. Scott Schaefer

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics: Two Dimensional Viewing

Two-Dimensional Viewing. Chapter 6

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Part 3: 2D Transformation

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

Computer Graphics Viewing Objective

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

MODULE - 4. e-pg Pathshala

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

3D Rendering Pipeline (for direct illumination)

Part IV. 2D Clipping

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

Viewing Transformation. Clipping. 2-D Viewing Transformation

CS 325 Computer Graphics

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

Clipping and Intersection

2D Viewing. Viewing Pipeline: Window-Viewport Transf.

Chapter 8: Implementation- Clipping and Rasterization

Illumination Models III: Ray Tracing (View Dependent Global Illumination)

From Vertices To Fragments-1

MODULE - 7. Subject: Computer Science. Module: Other 2D Transformations. Module No: CS/CGV/7

Unit 3 Transformations and Clipping

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

UNIT -8 IMPLEMENTATION

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Each point P in the xy-plane corresponds to an ordered pair (x, y) of real numbers called the coordinates of P.

window World space (Object space)

About Graphing Lines

Intro. To Graphing Linear Equations

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Section 7D Systems of Linear Equations

FLC Ch 3. Ex 1 Plot the points Ex 2 Give the coordinates of each point shown. Sec 3.2: Solutions and Graphs of Linear Equations

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Fast Algorithms for Line Segment and Line Clipping in E 2

State the domain and range of the relation. EX: {(-1,1), (1,5), (0,3)} 1 P a g e Province Mathematics Southwest TN Community College

Set the Viewport. Set the Viewport Clipping. Set the Viewport. Set the Viewport. Set the Viewport. Resizing the Viewport W = H

Vertical Line Test a relationship is a function, if NO vertical line intersects the graph more than once

Graphics Pipeline. CS535 Fall Daniel G. Aliaga Department of Computer Science Purdue University

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

0,0 is referred to as the end point.

Realtime 3D Computer Graphics Virtual Reality

Lesson 20: Every Line is a Graph of a Linear Equation

The Coordinate System and Graphs

Section 18-1: Graphical Representation of Linear Equations and Functions

Section 1.1 The Distance and Midpoint Formulas; Graphing Utilities; Introduction to Graphing Equations

(a) rotating 45 0 about the origin and then translating in the direction of vector I by 4 units and (b) translating and then rotation.

Two Dimensional Viewing

Geometry Unit 2: Linear. Section Page and Problems Date Assigned

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

A Procedure to Clip Line Segment

Sec 4.1 Coordinates and Scatter Plots. Coordinate Plane: Formed by two real number lines that intersect at a right angle.

Review for Mastery Using Graphs and Tables to Solve Linear Systems

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

Chapter 12: Quadratic and Cubic Graphs

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Math 1313 Prerequisites/Test 1 Review

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Mini-Lecture 3.1 Graphing Equations

ALGORITHMS COMPLEXITY AND LINE CLIPPING PROBLEM SOLUTIONS

Computer Graphics Geometry and Transform

Windowing And Clipping (14 Marks)

Did You Find a Parking Space?

Polar Coordinates. 2, π and ( )

11.4. Imagine that you are, right now, facing a clock and reading the time on that. Spin to Win. Volume of Cones and Pyramids

Functions. Copyright Cengage Learning. All rights reserved.

10-2 Circles. Warm Up Lesson Presentation Lesson Quiz. Holt Algebra2 2

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

2.1 Derivatives and Rates of Change

Vectors and the Geometry of Space

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

The shortest distance from point K to line is the length of a segment perpendicular to from point K. Draw a perpendicular segment from K to.

2 Unit Bridging Course Day 2 Linear functions I: Gradients

Section 10.1 Polar Coordinates

Algebra Unit 2: Linear Functions Notes. Slope Notes. 4 Types of Slope. Slope from a Formula

4.5 VISIBLE SURFACE DETECTION METHODES

Chapter 8 Three-Dimensional Viewing Operations

Use the graph shown to determine whether each system is consistent or inconsistent and if it is independent or dependent.

CS 450: COMPUTER GRAPHICS REVIEW: CLIPPING SPRING 2015 DR. MICHAEL J. REALE

SNAP Centre Workshop. Graphing Lines

Lecture 4. If P1(x1,y1) and P2(x2,y2) are points on a non-vertical line, then the slope m of the line is defined by

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

10 Polar Coordinates, Parametric Equations

Graphing Linear Equations

Chapter 3A Rectangular Coordinate System

12 Polar Coordinates, Parametric Equations

Question 2: How do you solve a linear programming problem with a graph?

CSE528 Computer Graphics: Theory, Algorithms, and Applications

SE Mock Online Test 1-CG

CS488. Implementation of projections. Luc RENAMBOT

Section 3.1 Graphing Using the Rectangular Coordinate System

Three-Dimensional Viewing Hearn & Baker Chapter 7

Graphs and Linear Functions

STRAIGHT LINE GRAPHS THE COORDINATES OF A POINT. The coordinates of any point are written as an ordered pair (x, y)

Section Graphs and Lines

Problems of Plane analytic geometry

Transcription:

Quadrant 1 e-text e-pg Pathshala MODULE - 9 Subject: Computer Science Paper: Computer Graphics and Visualization Module: Line Clipping Module No: CS/CGV/9 Objectives: Understand Cohen-Sutherland Line Clipping Solve an example problem. Discussion: 2D Clipping: Let s try to understand the theory behind the Cohen-Sutherland Line clipping algorithm. Recall discussion from the previous module that, clipping is performed before conversion of data to device coordinates. Line clipping is an extension of point clipping, where we check the position of a given line with respect to a standard rectangular clip window region. We need to perform tests to determine whether a line is completely inside or completely outside or partially inside. The portion of the line that is inside is only selected for display. Clipping algorithms identify the intersections of the lines with the clip window region and decide which portion of the line is inside and so can be selected for display. Two popular algorithms for line clipping are Cohen-Sutherland line clipper and Liang-Barsky line clipper. An algorithm is considered efficient when with few checks if it decides that the line is completely inside and so can be selected (Trivial Accept) or the line is completely outside and so can be discarded (Trivial Reject) or line is partially inside so intersection checks need to be done. A line has two end points. If both the end points are inside the clip window, it is trivial that the line is completely inside and so can be selected for display. From the figure above it is evident that line

P 3 P 4 is completely inside since both the end points P 3 and P 4 are inside (Trivial Accept case). P 1 P 2, P 9 P 10 are completely outside, and so can be discarded. In both these cases both the end points are outside and the line is also completely outside. P 5 P 6 A portion of the line is inside and so find intersection point P 5 and select and display the portion of the line that is inside (P 4 P 5 ). P 7 P 8 Both end points are outside but a portion of the line is inside. For such types we need to calculate two intersection points P 7 and P 8 and display the line P 7 P 8. Both the algorithms for line clipping, Cohen-Sutherland and Liang-Barsky, are efficient algorithms and both can be extended for 3D clipping as well. But it is Liang-Barsky that suits well for implementation in a program. Cohen-Sutherland Line Clipping Procedure: This is a rudimentary level line clipping procedure and is efficient. Two scientists Cohen and Sutherland devised this procedure. The method speeds up the processing of line segments by performing initial tests that reduce the number of intersections that must be calculated particularly in the cases of Trivial Accept and Trivial Reject cases. Imagine that we are dividing the whole space into 9 zones or regions using 4 infinitely extending lines, such that the central region is identified as the clip window region, and remaining 8 regions around the central region are identified relative to the central region as shown in the figure below. Every region is assigned a four digit binary code, called region code that identifies a region. The central region, called the clip window region, is identified with the region code (0000). The region to the left is given a region code 0001. The regions to the right, bottom and top have the region codes, 0010, 0100, and 1000 respectively. The other 4 regions in the corners, top left, top right, bottom left, bottom right have the region codes 1001, 1010, 0101, 0110 respectively. Let s see how this region code was arrived at? Each bit position in the region code is used to indicate one of the four surrounding regions relative to the central clip window region. The order of the bits from right to left is as follows Bit 1 : Left region Bit 2 : Right region Bit 3 : Bottom region Bit 4 : Top region For Ex: If a region code is given as 1010, this means, The top and right bits are set (indicated by a binary bit 1) while the left and bottom bits are not set (indicated by a binary bit 0). The answer is that the region with the region code 1010 is the top right of the central region. The central region has the region code 0000.

Let s try to understand how this region code is useful in determining the relative position of a line against the clip window. The idea is that for the two end points of a given line we shall compute region code and with simple checks we should be able to decide whether to go for intersection calculations or simply end up with a trivial reject or trivial accept case. Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point with respect to the clip window. The next step is how do we compute region codes for an end point? It is as simple as checking for four conditions (recall the equations from the point clipping discussion in the previous module - 8). Assume 4 infinitely extending lines defined by xw min, xw max, yw min, yw max make up the clip window region. For an end point (x,y), check the first condition, if x<xw min set the left bit of the region code otherwise keep it 0. Than to check the relation for magnitude, it is convenient to check for the sign bit of the relation, x-xw min, i.e., if the sign bit of the relation is set then set the left bit. We can perform similar checks for other three bit positions. Set Bit 1(left): Sign(x xw min ) Set Bit 2(right): sign(xw max x ) Set Bit 3 (bottom): sign(y yw min ) Set Bit 4 (top): sign(yw max y) Compute the region codes for both the end points of a given line. If both the end points have a region code of 0000, then it is a Trivial Accept case, i.e., the line is completely inside and so can be considered for display. In general, a line that is parallel and outside the clip window region, will have, one bit position commonly set in both the region codes of the two end points. For Ex: consider a line that is parallel to the top boundary and is outside will have its region codes, 1001, 1010. From the region codes we can simply conclude that the line has one bit position commonly set, i.e. the top bit, so the line is parallel to the top boundary and is outside and so can be discarded. *************************************************************************************************** Steps in the algorithm are as follows o For each end point of a line, compute region code o If both the end points have a region code of 0000, then it is a Trivial Accept case, i.e., the line is completely inside and so can be considered for display o Otherwise perform a bit wise AND operation for the two region codes of the two end points of a line, and if the operation results in a non-zero value, then it can be concluded that the line is outside and is parallel to that boundary represented by that bit position that is is set in the result, and so is a Trivial Reject case. (Ex: consider two region codes 1010, 0110. Performing bit-wise AND operation we get, 0010, which is a non-zero value and the bit position commonly set in both the region codes is the right bit position. The result says that the line is an outside line and is parallel to the right boundary.) o Otherwise, if the bit-wise AND operation results in a zero value, the line intersects the clip window and we need to go for intersection calculations. (Ex: Consider a line with region codes for its end points as 0100 and 0010. The line is an inclined line, no bit position is commonly set and bit-wise AND operation results in a zero value. So it s obvious to go for intersection calculations.) o If the above cases fail we need to go for intersection calculations. *****************************************************************************************************

It is known that, there will be a maximum of two intersection points for a given line, when it intersects clip window, but assuming infinitely extending clip window boundaries, and the line to be clipped being longer, there will be four intersection points, as shown below. The four dots represent the four intersection points, the maximum possible for a line. ywmin ywmin xwmin xwmax We need to check for a maximum of 4 intersection points, for the maximum possible line as shown in the figure above. Intersection points with a clipping boundary can be calculated using the slope-intercept form of the line equation. The y coordinate of the intersection point at vertical line can be computed using the formula ( ) where x is either xwmin or xwmax The x coordinate of the intersection point at horizontal line can be computed using the equation + where y is either ywmin or ywmax. ********************************************************************************************************* Example: Compute the clipped portion of the line at [(0,0), (8,5)], when clipped against the clip window between [(1,2), (7, 6)]. Solution: From the problem, we can note the following data xwmin 1 xwmax 7 ywmin 2 ywmax 6 Starting with left boundary we can calculate intersection points, and continue with the right, bottom, top boundaries.

********************************************************************************************************* In the solution shown above, after the line is clipped against the left boundary, we get an intersection point, P1, discard the portion from P1 to P1 and the line to be sent to the next clipper (right) is P1 P2. With respect to the right clipper, when we clip the line we get another intersection point, P2, and discard the portion from P2 to P2. Now the line between P1 P2 is sent to the bottom clipper. When we clip the portion of the line with respect to the bottom clipper, we compute another intersection point, P1, and discard the line from P1 to P1. When the line is finally sent to the top clipper, no intersection point needs to be computed as the line is completely inside with respect to top boundary. The computation ends and finally the line to be displayed is the line between P1 to P2. Summary: Ø We have learnt how Cohen-Sutherland line clipping works Ø This algorithm also works for clipping in 3D as well. Ø An example problem has been solved