0% found this document useful (0 votes)
2 views32 pages

CG-06-Viewing and Cliping (6)

The document discusses viewing and clipping in computer graphics, focusing on the concepts of point and line clipping. It details the Cohen-Sutherland algorithm for line clipping, explaining how to determine if a line is inside, outside, or partially inside a clipping window. The document also provides examples and calculations for finding intersection points during the clipping process.

Uploaded by

dfhyfy5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views32 pages

CG-06-Viewing and Cliping (6)

The document discusses viewing and clipping in computer graphics, focusing on the concepts of point and line clipping. It details the Cohen-Sutherland algorithm for line clipping, explaining how to determine if a line is inside, outside, or partially inside a clipping window. The document also provides examples and calculations for finding intersection points during the clipping process.

Uploaded by

dfhyfy5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Computer Graphics

Lecture 06

Viewing and clipping


Outlines
1. Viewing
– Camera

2. Clipping
• It is removing lines or portions of lines outside
an area
– Line
• Cohen– Algorithm
– Polygon
• Sutherland Hodgman - Algorithm
• Light Camera
Object
Viewing and clipping
• Example
Viewing and Clipping
• The viewing is the position of points
relative to the viewing

• The Clipping is removing points behind


the viewer − before generating the view.
(removing segments that are outside the
viewing pane.)
1- Point Clipping
• Clipping a point from a given window is very
easy.

• Point clipping tells us whether the given point X,


Y is within the given window or not;

• and decides whether we will use the minimum


and maximum coordinates of the window.
• The point is inside the window,
– if X lies in between Wx1 ≤ X ≤ Wx2.
• And,
– if Y lies in between Wy1 ≤ Y ≤ Wy2.
2- Line Clipping
• The concept of line clipping is same as point
clipping.
• In line clipping, we will cut the portion of line
which is outside of window and keep only the
portion that is inside the window.

Method 1- Cohen- Line Clippings


Line clipping:
Cohen- Line Clippings

• This algorithm uses the clipping window


as:
• for the clipping region (window) is

– (XWmin , YWmin)

– (XWmax, YWmax).
• We will use 4-bits to divide the entire
region. These 4 bits represent the
• Top,
• Bottom,
• Right, and
• Left of the region.
There are 3 possibilities for the line
• Line can be completely inside the window
This line will be completely inside the region.
• Line can be completely outside of the
window
This line will be completely removed from the
region.
• Line can be partially inside the window
We will find intersection points and draw only that
portion of line that is inside region.
Algorithm
• Step 1 − Assign a region code for each endpoints.
• Step 2 − If both endpoints have a region code 0000
then accept this line.
• Step 3 − Else, perform the logical AND operation for
both region codes.
– Step 3.1 − If the result is not 0000, then reject the line.
– Step 3.2 − Else you need clipping.
• Step 3.2.1 − Choose an endpoint of the line that is outside the window.
• Step 3.2.2 − Find the intersection point at the window boundary base on regioncode.
• Step 3.2.3 − Replace endpoint with the intersection point and update the region
code.
• Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or
trivially rejected.

• Step 4 − Repeat step 1 for other lines.


Case 1
• P1→0000 zero
• P2→0000 zero
-------------------
And 0000 zero

Visible line
Accept line
No clipping
Case 2
• P3→1000 non zero
• P4→1000 non zero
-------------------
And 1000 non zero

Not Visible line


reject line
No clipping
Case 3
• P5→1000 non zero
• P6→0000 zero
-------------------
And 0000 zero

Means that some part of line inside and


some part outside
Clipping required
Case 3
• P5’→0000 zero
• P6→0000 zero
-------------------
And 0000 zero

accept
Case 4
• P7→1000 nonzero
• P8→0100 nonzero
-------------------
And 0000 zero

Need clipping
Case 4
• P7’→0000 zero
• P8→0100 nonzero
-------------------
And 0000 zero

Need clipping
Case 4
• P7’→0000 zero
• P8’→0000 zero
-------------------
And 0000 zero

accept
Intersection point
• Calculate intersection point
• Line end points (x1,y1) and (x2,y2)
• Y’ of intersection
– Y’=y1+m(xboundary – x1)
– Xboundary is x window max or min
• x’ of intersection
– x’=x1+1/m(yboundary – y1)
– yboundary is y window max or min
Example
• using Cohen line clipping algorithm to find
intersection points with the window where
the Window’s coordinates are: (2,3) ,
(12,3) , (2,6) and (12,6). The Line
endpoints (1,8) and (7,1)
the Window’s coordinates are: (2,3) , (12,3) , (2,6) and (12,6).
The Line endpoints (1,8) and (7,1)

1,8

2,6 12,6

2,3
12,3

7,1
1001
1000

0000

0100
P1→1001
P2→ 0100
----------------------
And 0000 clipping required

P1’→ 0000
P2→ 0100
------------
And 0000 clipping required

P1’→ 0000
P2’→ 0000
------------
And 0000 accept
Intersection points
• y’ of intersection is y’=y1+m(xboundary – x1)

• x’ of intersection is x’=x1+1/m(yboundary – y1)

where Xboundary is xwmax or xwmin


and
• yboundary is ywmax orywmin

• if intersection in the top then y’= ywmax


• if intersection in the bottom then y’= ywmin
• if intersection in the left then x’= xwmin
• if intersection in the right then x’= xwmax
• First intersection (x’,y’)
• Y’=ywmax X’=x1+m(ywmax – y1)

• second intersection (x’’,y’’)


• Y’’=ywmin X’=x2+m(ywmin – y2)
Clipping
• It is removing lines or portions of lines
outside an area
– Point

– Line
• Cohen– Algorithm

– Polygon
• Sutherland Hodgman Algorithm

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy