SlideShare a Scribd company logo
1 of 30
WELCOME TO
OUR
PRESENTATION
Submitted By-
Submitted To-
Fahima Khanam
Lecturer
Dept. Of CSE
Daffodil International University
INTRODUCTION
In computer graphics, line clipping is the process of removing lines or portions
of lines outside an area of interest. Typically, any line or part thereof which is outside
of the viewing area is removed.
There are two common algorithms for line clipping: Cohen–Sutherland and Liang–
Barsky.
CLIPPING LINES
• If a line is partially in the viewport, then we need to
recalculate its endpoints.
• In general, there are four possible cases.
• The line is entirely within the viewport.
• The line is entirely outside the viewport.
• One endpoint is in and the other is out.
• Both endpoints are out, but the middle part is in.
CLIPPING LINE
• Clipping rectangle:
• xmin to xmax
• ymin to ymax
• A point (x,y) lies within a clip
rectangle and thus displayed if
following conditions are hold
• xmin <= x <= xmax
• ymin <= y <= ymax
CASES
Here are a few cases, where the black rectangle represents the screen, in red are the
old endpoints, and in blue the ones after clipping:
CLIPPING LINES
• Before clipping
F
A
B
C
D
E
G
H
CLIPPING LINES
• After clipping
F
A
B
E
G
H
F'
G'
H'
C
D
POINT CLIPPING
For a point (x,y) to be inside the clip
rectangle:
LINE CLIPPING
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
1. End points are checked to for trivial acceptance
• If both endpoints are inside the clip rectangle boundary
2. If not trivially accepted, region check is done for trivial rejection
• Both endpoints have x co-ordinate less than xmin
 region to the left edge of clip rectangle
• Both endpoints have x co-ordinate greater than xmax
 region to the right edge of clip rectangle
• Both endpoints have y co-ordinate less than ymin
 region below the bottom edge of clip rectangle
• Both endpoints have y co-ordinate greater than ymax
 region above the top edge of clip rectangle
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM
3. If neither trivially accepted, nor trivially rejected
• Divided into two segments at the intersection point of a clip edge, such that
• one segment can be trivially
rejected/accepted
• Another segment is subdivided
iteratively until cannot be trivially
rejected or accepted.
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM• Extend the edges of the clip rectangle
• Divide the plane into 9 regions
• Each region is assigned a 4 bit code
called outcode
• First bit is 1 if the region is
above the top edge, 0 otherwise
• Second bit is 1 if the region is
below the bottom edge, 0 otherwise
• Third bit is 1 if the region is
right to the right edge, 0 otherwise
• Fourth bit is 1 if the region is
left to the left edge, 0 otherwise
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM• Each endpoint of the line segment is assigned the outcode
• If both endcodes are 0000 then
it completely lies inside the
clip rectangle
 trivial acceptance
A:0000
B:0000
• Otherwise perform the
logical AND of the outcodes.
If results in non zero
 trivial rejection
C:1000
D:1010
A
B
C
D
AND gives 1000  above the top edge
COHEN-SUTHERLAND LINE CLIPPING
ALGORITHM• If neither trivially accepted nor rejected, subdivide
it based on a intersecting edge
• Select the outcode of the endpoint
that lies outside
• Choose a set bit in that outcode
for selecting the edge for
subdivision
Let us choose:
topbottomrightleft order
leftmost set bit in the outcode is used
for selecting the edge for subdivision
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• Let the x-coordinates of the window boundaries be xmin and xmax and let the y-
coordinates be ymin and ymax.
xmin xmax
ymin
ymax
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• For each endpoint p of a line segment we will define a
codeword c3c2c1c0 consisting of 4 true/false values.
• c3 = true, if p is left of the window.
• c2 = true, if p is above the window.
• c1 = true, if p is right of the window.
• c0 = true, if p is below the window.
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• Consider the vertical edge x = xmin. (You can do the other edges.)
• Compare the x-coordinate of p to xmin.
• If it is less, then “set” bit 3 of the codeword.
if (p.x < xmin)
c = 1 << 3;
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• After the codewords for both endpoints are computed, we divide the possibilities
into three cases:
• Trivial accept – both codewords are FFFF.
• Trivial reject – both codewords have T in the same position.
• Indeterminate so far – Investigate further.
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
clip
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
clip
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
clip
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
clip
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• Consider again the vertical edge x = xmin. (You can do the other edges.)
• Compute codeword1 ^ codeword2.
• This shows where they disagree.
• Why?
• “And” this with (1 << 3).
• If result = 1, then clip.
• Else do not clip.
THE COHEN-SUTHERLAND CLIPPING
ALGORITHM
• If we clip, then the new point will be on the line x = xmin.
• So its x-coordinate will be xmin.
• We must calculate its y-coordinate.
• In this algorithm it divides lines & edges into 2 cases.
1) Trivially Accept and
2) Trivially Reject.
CONDITIONS OF TRIVIALLY ACCEPT
Xmin ≤ X ≤ Xmax
Ymin ≤ Y ≤ Ymax
Lines fulfill this conditions then we will mark those lines as
trivially accept.
CONDITIONS OF TRIVIALLY REJECT
X0 < Xmin & X1 < Xmin or
Y0 < Ymin & Y1 < Ymin
X0 > Xmax & X1 > Xmax or
Y0 > Ymax & Y1 > Ymax

More Related Content

What's hot

The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
Mani Kanth
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
avelraj
 

What's hot (20)

Clipping2
Clipping2Clipping2
Clipping2
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 
Line clipping
Line clippingLine clipping
Line clipping
 
Curve clipping
Curve clippingCurve clipping
Curve clipping
 
Lect 5 2d clipping
Lect 5 2d clippingLect 5 2d clipping
Lect 5 2d clipping
 
Clipping
ClippingClipping
Clipping
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 
Clipping
ClippingClipping
Clipping
 
Sutherlands Cohen and Hodgeman algorithms
Sutherlands Cohen and Hodgeman algorithmsSutherlands Cohen and Hodgeman algorithms
Sutherlands Cohen and Hodgeman algorithms
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
clipping
clippingclipping
clipping
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics
 
line clipping
line clipping line clipping
line clipping
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 

Similar to Computer graphics

Clipping in 2 d
Clipping in 2 dClipping in 2 d
Clipping in 2 d
Ashiv Khan
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
Roziq Bahtiar
 

Similar to Computer graphics (19)

99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
 
Implementation
ImplementationImplementation
Implementation
 
Clipping
ClippingClipping
Clipping
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 
Cohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithmCohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithm
 
7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & Rasterization
 
Clipping
ClippingClipping
Clipping
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
 
lecture8 clipping
lecture8 clippinglecture8 clipping
lecture8 clipping
 
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygonsLiang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
 
ibuib.pptx
ibuib.pptxibuib.pptx
ibuib.pptx
 
Clipping in 2 d
Clipping in 2 dClipping in 2 d
Clipping in 2 d
 
Clipping
ClippingClipping
Clipping
 
kgv.pptx
kgv.pptxkgv.pptx
kgv.pptx
 
Lec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdfLec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdf
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Clipping.ppt
Clipping.pptClipping.ppt
Clipping.ppt
 
Windowing clipping
Windowing   clippingWindowing   clipping
Windowing clipping
 

More from Daffodil International University

More from Daffodil International University (8)

Data mining
Data miningData mining
Data mining
 
OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]
 
Web engineering / web design & development
Web engineering / web design & development Web engineering / web design & development
Web engineering / web design & development
 
Ibm watson
Ibm watsonIbm watson
Ibm watson
 
ATM System management
ATM System managementATM System management
ATM System management
 
Analysis and design of information system
Analysis and design of information systemAnalysis and design of information system
Analysis and design of information system
 
Basic computer architecture
Basic computer architectureBasic computer architecture
Basic computer architecture
 
Priority scheduling algorithms
Priority scheduling algorithmsPriority scheduling algorithms
Priority scheduling algorithms
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 

Computer graphics

  • 2. Submitted By- Submitted To- Fahima Khanam Lecturer Dept. Of CSE Daffodil International University
  • 3. INTRODUCTION In computer graphics, line clipping is the process of removing lines or portions of lines outside an area of interest. Typically, any line or part thereof which is outside of the viewing area is removed. There are two common algorithms for line clipping: Cohen–Sutherland and Liang– Barsky.
  • 4. CLIPPING LINES • If a line is partially in the viewport, then we need to recalculate its endpoints. • In general, there are four possible cases. • The line is entirely within the viewport. • The line is entirely outside the viewport. • One endpoint is in and the other is out. • Both endpoints are out, but the middle part is in.
  • 5. CLIPPING LINE • Clipping rectangle: • xmin to xmax • ymin to ymax • A point (x,y) lies within a clip rectangle and thus displayed if following conditions are hold • xmin <= x <= xmax • ymin <= y <= ymax
  • 6. CASES Here are a few cases, where the black rectangle represents the screen, in red are the old endpoints, and in blue the ones after clipping:
  • 7. CLIPPING LINES • Before clipping F A B C D E G H
  • 8. CLIPPING LINES • After clipping F A B E G H F' G' H' C D
  • 9. POINT CLIPPING For a point (x,y) to be inside the clip rectangle:
  • 11. COHEN-SUTHERLAND LINE CLIPPING ALGORITHM 1. End points are checked to for trivial acceptance • If both endpoints are inside the clip rectangle boundary 2. If not trivially accepted, region check is done for trivial rejection • Both endpoints have x co-ordinate less than xmin  region to the left edge of clip rectangle • Both endpoints have x co-ordinate greater than xmax  region to the right edge of clip rectangle • Both endpoints have y co-ordinate less than ymin  region below the bottom edge of clip rectangle • Both endpoints have y co-ordinate greater than ymax  region above the top edge of clip rectangle
  • 12. COHEN-SUTHERLAND LINE CLIPPING ALGORITHM 3. If neither trivially accepted, nor trivially rejected • Divided into two segments at the intersection point of a clip edge, such that • one segment can be trivially rejected/accepted • Another segment is subdivided iteratively until cannot be trivially rejected or accepted.
  • 13. COHEN-SUTHERLAND LINE CLIPPING ALGORITHM• Extend the edges of the clip rectangle • Divide the plane into 9 regions • Each region is assigned a 4 bit code called outcode • First bit is 1 if the region is above the top edge, 0 otherwise • Second bit is 1 if the region is below the bottom edge, 0 otherwise • Third bit is 1 if the region is right to the right edge, 0 otherwise • Fourth bit is 1 if the region is left to the left edge, 0 otherwise
  • 14. COHEN-SUTHERLAND LINE CLIPPING ALGORITHM• Each endpoint of the line segment is assigned the outcode • If both endcodes are 0000 then it completely lies inside the clip rectangle  trivial acceptance A:0000 B:0000 • Otherwise perform the logical AND of the outcodes. If results in non zero  trivial rejection C:1000 D:1010 A B C D AND gives 1000  above the top edge
  • 15. COHEN-SUTHERLAND LINE CLIPPING ALGORITHM• If neither trivially accepted nor rejected, subdivide it based on a intersecting edge • Select the outcode of the endpoint that lies outside • Choose a set bit in that outcode for selecting the edge for subdivision Let us choose: topbottomrightleft order leftmost set bit in the outcode is used for selecting the edge for subdivision
  • 16. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • Let the x-coordinates of the window boundaries be xmin and xmax and let the y- coordinates be ymin and ymax. xmin xmax ymin ymax
  • 17. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • For each endpoint p of a line segment we will define a codeword c3c2c1c0 consisting of 4 true/false values. • c3 = true, if p is left of the window. • c2 = true, if p is above the window. • c1 = true, if p is right of the window. • c0 = true, if p is below the window.
  • 18. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • Consider the vertical edge x = xmin. (You can do the other edges.) • Compare the x-coordinate of p to xmin. • If it is less, then “set” bit 3 of the codeword. if (p.x < xmin) c = 1 << 3;
  • 19. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • After the codewords for both endpoints are computed, we divide the possibilities into three cases: • Trivial accept – both codewords are FFFF. • Trivial reject – both codewords have T in the same position. • Indeterminate so far – Investigate further.
  • 26. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • Consider again the vertical edge x = xmin. (You can do the other edges.) • Compute codeword1 ^ codeword2. • This shows where they disagree. • Why? • “And” this with (1 << 3). • If result = 1, then clip. • Else do not clip.
  • 27. THE COHEN-SUTHERLAND CLIPPING ALGORITHM • If we clip, then the new point will be on the line x = xmin. • So its x-coordinate will be xmin. • We must calculate its y-coordinate.
  • 28. • In this algorithm it divides lines & edges into 2 cases. 1) Trivially Accept and 2) Trivially Reject.
  • 29. CONDITIONS OF TRIVIALLY ACCEPT Xmin ≤ X ≤ Xmax Ymin ≤ Y ≤ Ymax Lines fulfill this conditions then we will mark those lines as trivially accept.
  • 30. CONDITIONS OF TRIVIALLY REJECT X0 < Xmin & X1 < Xmin or Y0 < Ymin & Y1 < Ymin X0 > Xmax & X1 > Xmax or Y0 > Ymax & Y1 > Ymax