SlideShare a Scribd company logo
1 of 14
Cohen-Sutherland Line Clipping and Liang-Barsky Line 
Clipping Algorithm 
By Shilpa
Cohen-Sutherland line clipping Algorithm:- 
Step 1: Read two end points of the line say p1(x1,y1) and p2(x2,y2). 
P1(x1,y1) P2(x2,y2) 
Step 2: Read two corner (left-bottom and right-top) of the window, say 
(Xwmin,YWmin) and (Xwmax,YWmax). 
Step 3: Assign the region code for two end points p1 and p2 are follows: 
Region code calculation for point (x,y):- 
Sign bit for Bit1 is x-xwmin, sign bit for Bit2 xwmax-x, sign bit for Bit3 for y-ywmin, 
sign bit for Bit4 ywmax-y. 
(Xwmax,Ywmax) 
(Xwmin,Ywmin) 
Bit4 Bit3 Bit2 Bit1
Then if sign bit is negative then the corresponding bit is assigned to be 1. If it is 
positive then the corresponding bit is assigned to be 0. 
Step 4: Check for visibility of P1P2:- 
a)If the both region code for p1 and p2 is 0000. Then the line completely visible, then 
exit. 
b)Else, ANDing the region code for p1 and p2, if the result is not 0000. Then the line is 
completely invisible. Then exit. 
c)If the region code for two end points do not satisfy the above two condition, then the 
line is partially visible. 
Step 5: Determine the intersection point:- 
a)If the line partially visible and region code for both p1 and p2 are not 0000. 
Then find p1’ and p2’. The intersection point with the boundaries edge of the clipping 
window.
p1 P1’ P2’ p2 
b) If any one of the point p1 or p2 is 0000(region code) and other root 0000. Then 
find the intersection point p1’ or p2’ with the boundary edge of the clipping 
window. 
p1 P2’ p2 
Step 6: Reject the line outside of the clipping window and draw the remaining line 
segment. 
Step 7: Stop.
consider the clipping window and the lines shown in following figure and 
find the region code for each end points and identify whither the line is 
completely visible, partially visible or completely. 
Line End points Region code ANDing Result 
P1p2 0000 0000 0000 Completely 
visible 
P3p4 0001 0001 0001 Completely 
invisible 
P5p6 0001 0000 0000 Partially Visible 
P7p8 0100 0010 0000 Partially visible 
P9p10 1000 0010 0000 Partially visible
Problem : 
Giving a clipping window p(25,25), Q(65,25), R(65,45) and S(25,45). Using 
Cohen-Sutherland algorithm find the visible position of line segment joining 
the points x(45,85), x’(125,35). 
Xwmin=25 
Xwmax=65 
Ywmin=25 
Ywmax=45 
According to Cohen-Sutherland algorithm the region code for the point x(45,85). Here 
x=45 and y=85. 
Bit1=x-xwmin=45-25=20(+ve)=0 
Bit2=xwmax-x=65-45=20(+ve)=0 
Bit3=y-ywmin=85-25=60(+ve)=0 
Bit4=ywmax-y=45-85=-60(-Ve)=1
Thus the region code of the point x=1000. 
The region code for the point x’(125,35). Here x=125,y=35. 
Bit1=x-xwmin=125-25=100(+ve)=0 
Bit2=xwmax-x=65-125=-60(-ve)=1 
Bit3=y-ywmin=35-25=10(+ve)=0 
Bit4=ywmax-y=45-35=-10(+Ve)=0 
Thus the region code of the point x’=0010. 
AND operation between two region code: 
For x=1000 
For x’=0010 
0000 
Thus the line is partially visible.
Liang-Barsky Line Clipping Algorithm:- 
The Liang–Barsky algorithm uses the parametric equation of a line and inequalities 
describing the range of the clipping window to determine the intersections between 
the line and the clipping window. With these intersections it knows which portion of 
the line should be drawn. This algorithm is significantly more efficient than 
Cohen–Sutherland. Consider first the usual parametric form of a straight line: 
X=x0+u(x1-x0)=x0+uΔx, 
Y=y0+u(y1-y0)=y0+uΔy, where 0<=u<=1. 
A point is in the clip window, if Xwmin<=x0+uΔx<=xwmax and 
Ywmin<=y0+uΔy<=Ywmax, which can be expressed as the 4 inequalities u.pk<qk, 
k=1,2,3,4 where 
P1=- Δx, 
p2= Δx, 
p3=- Δy, 
p4= Δy, 
q1=x0-xmin(left), 
q2=xmax-x0(right),q3=y0-ymin(bottom),q4=ymax-y0(top).
• When pk < 0, as u increases 
- line goes from outside to inside - entering 
• When pk > 0, 
- line goes from inside to outside - exiting 
• When pk = 0, 
- line is parallel to an edge 
• If there is a segment of the line inside the clip region, a sequence of infinite line 
intersections must go: entering, entering, exiting, exiting. 
Algorithm:- 
1. Set umin = 0 and umax = 1. 
2. Calculate the u values: 
3. If u < umin or u > umax ignore it. 
Otherwise classify the u values as entering or exiting. 
4. If umin < umax then draw a line from: ( x0 + Δx · umin, y0 + Δy · umin ) to 
( x0 + Δx · umax, y0 + Δy · umax ).
We have umin = 1/4 and umax = 3/4 
Pend - P0 = (15+5,9-3) = (20,6) 
 If umin < umax , there is a line segment 
- compute endpoints by substituting u values 
 Draw a line from (-5+(20)·(1/4), 3+(6)·(1/4)) to (-5+(20)·(3/4), 3+(6)·(3/4))
• We have umin = 4/5 and umax = 2/3 
Pend - P0 = (2+8, 14-2) = (10, 12) 
• umin > umax , there is no line segment do draw. 
 To compute the final line segment: 
1. A line parallel to a clipping window edge has pk=0 for that boundary. 
2. If for that k, qk<0, the line is completely outside and can be eliminated. 
3. When pk<0 the line proceeds outside to inside the clip window and when pk>0, the 
line proceeds inside to outside. 
4. For nonzero pk, u=qk/pk gives the intersection point. 
5. For each line, calculate u1 and u2. For u1, look at boundaries for which pk<0 (i.e. 
outside to inside). Take to be the largest among . For u2, look at boundaries for 
which pk>0 (i.e. inside to outside). Take u2 to be the minimum of {1,qk/pk}. 
If u1>u2, the line is outside and therefore rejected.
Liang-Barsky vs Cohen-Sutherland:- 
LB generally more efficient: 
- LB: updates of u1 and u2 use one division, window intersections computed 
only once with final u1 and u2. 
- CS: may repeatedly calculate intersections along a line, even if line is 
totally exterior to clip window and each intersection computation uses division 
and multiplication.
Cohen-sutherland & liang-basky line clipping algorithm

More Related Content

What's hot

Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 
Circle & curve clipping algorithm
Circle & curve clipping algorithmCircle & curve clipping algorithm
Circle & curve clipping algorithmMohamed El-Serngawy
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarsyedArr
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphicanku2266
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmMani Kanth
 
region-filling
region-fillingregion-filling
region-fillingKumar
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalPunyajoy Saha
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
 
Unit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfUnit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfAmol Gaikwad
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 

What's hot (20)

Shading
ShadingShading
Shading
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Clipping
ClippingClipping
Clipping
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Circle & curve clipping algorithm
Circle & curve clipping algorithmCircle & curve clipping algorithm
Circle & curve clipping algorithm
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
illumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukarillumination model in Computer Graphics by irru pychukar
illumination model in Computer Graphics by irru pychukar
 
Visible surface detection in computer graphic
Visible surface detection in computer graphicVisible surface detection in computer graphic
Visible surface detection in computer graphic
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 
The sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithmThe sutherland hodgeman polygon clipping algorithm
The sutherland hodgeman polygon clipping algorithm
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
region-filling
region-fillingregion-filling
region-filling
 
visible surface detection
visible surface detectionvisible surface detection
visible surface detection
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Clipping
ClippingClipping
Clipping
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
Unit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdfUnit-IV Windowing and Clipping.pdf
Unit-IV Windowing and Clipping.pdf
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 

Similar to Cohen-sutherland & liang-basky line clipping algorithm

Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphicsShaishavShah8
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping2013901097
 
Unit2- line clipping.pptx
Unit2- line clipping.pptxUnit2- line clipping.pptx
Unit2- line clipping.pptxRYZEN14
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Comparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementComparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementIJMER
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsThirunavukarasu Mani
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Lect 5 2d clipping
Lect 5 2d clippingLect 5 2d clipping
Lect 5 2d clippingmajicyoung
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptAliZaib71
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5Vanishree Arun
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & RasterizationAhmed Daoud
 

Similar to Cohen-sutherland & liang-basky line clipping algorithm (20)

Clipping
ClippingClipping
Clipping
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping
 
Unit2- line clipping.pptx
Unit2- line clipping.pptxUnit2- line clipping.pptx
Unit2- line clipping.pptx
 
Geometric algorithms
Geometric algorithmsGeometric algorithms
Geometric algorithms
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Comparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for ImprovementComparison of Various Line Clipping Algorithm for Improvement
Comparison of Various Line Clipping Algorithm for Improvement
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
26 Computational Geometry
26 Computational Geometry26 Computational Geometry
26 Computational Geometry
 
26 Computational Geometry
26 Computational Geometry26 Computational Geometry
26 Computational Geometry
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Lect 5 2d clipping
Lect 5 2d clippingLect 5 2d clipping
Lect 5 2d clipping
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
 
Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & Rasterization
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Cohen-sutherland & liang-basky line clipping algorithm

  • 1. Cohen-Sutherland Line Clipping and Liang-Barsky Line Clipping Algorithm By Shilpa
  • 2. Cohen-Sutherland line clipping Algorithm:- Step 1: Read two end points of the line say p1(x1,y1) and p2(x2,y2). P1(x1,y1) P2(x2,y2) Step 2: Read two corner (left-bottom and right-top) of the window, say (Xwmin,YWmin) and (Xwmax,YWmax). Step 3: Assign the region code for two end points p1 and p2 are follows: Region code calculation for point (x,y):- Sign bit for Bit1 is x-xwmin, sign bit for Bit2 xwmax-x, sign bit for Bit3 for y-ywmin, sign bit for Bit4 ywmax-y. (Xwmax,Ywmax) (Xwmin,Ywmin) Bit4 Bit3 Bit2 Bit1
  • 3. Then if sign bit is negative then the corresponding bit is assigned to be 1. If it is positive then the corresponding bit is assigned to be 0. Step 4: Check for visibility of P1P2:- a)If the both region code for p1 and p2 is 0000. Then the line completely visible, then exit. b)Else, ANDing the region code for p1 and p2, if the result is not 0000. Then the line is completely invisible. Then exit. c)If the region code for two end points do not satisfy the above two condition, then the line is partially visible. Step 5: Determine the intersection point:- a)If the line partially visible and region code for both p1 and p2 are not 0000. Then find p1’ and p2’. The intersection point with the boundaries edge of the clipping window.
  • 4. p1 P1’ P2’ p2 b) If any one of the point p1 or p2 is 0000(region code) and other root 0000. Then find the intersection point p1’ or p2’ with the boundary edge of the clipping window. p1 P2’ p2 Step 6: Reject the line outside of the clipping window and draw the remaining line segment. Step 7: Stop.
  • 5. consider the clipping window and the lines shown in following figure and find the region code for each end points and identify whither the line is completely visible, partially visible or completely. Line End points Region code ANDing Result P1p2 0000 0000 0000 Completely visible P3p4 0001 0001 0001 Completely invisible P5p6 0001 0000 0000 Partially Visible P7p8 0100 0010 0000 Partially visible P9p10 1000 0010 0000 Partially visible
  • 6. Problem : Giving a clipping window p(25,25), Q(65,25), R(65,45) and S(25,45). Using Cohen-Sutherland algorithm find the visible position of line segment joining the points x(45,85), x’(125,35). Xwmin=25 Xwmax=65 Ywmin=25 Ywmax=45 According to Cohen-Sutherland algorithm the region code for the point x(45,85). Here x=45 and y=85. Bit1=x-xwmin=45-25=20(+ve)=0 Bit2=xwmax-x=65-45=20(+ve)=0 Bit3=y-ywmin=85-25=60(+ve)=0 Bit4=ywmax-y=45-85=-60(-Ve)=1
  • 7. Thus the region code of the point x=1000. The region code for the point x’(125,35). Here x=125,y=35. Bit1=x-xwmin=125-25=100(+ve)=0 Bit2=xwmax-x=65-125=-60(-ve)=1 Bit3=y-ywmin=35-25=10(+ve)=0 Bit4=ywmax-y=45-35=-10(+Ve)=0 Thus the region code of the point x’=0010. AND operation between two region code: For x=1000 For x’=0010 0000 Thus the line is partially visible.
  • 8. Liang-Barsky Line Clipping Algorithm:- The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clipping window. With these intersections it knows which portion of the line should be drawn. This algorithm is significantly more efficient than Cohen–Sutherland. Consider first the usual parametric form of a straight line: X=x0+u(x1-x0)=x0+uΔx, Y=y0+u(y1-y0)=y0+uΔy, where 0<=u<=1. A point is in the clip window, if Xwmin<=x0+uΔx<=xwmax and Ywmin<=y0+uΔy<=Ywmax, which can be expressed as the 4 inequalities u.pk<qk, k=1,2,3,4 where P1=- Δx, p2= Δx, p3=- Δy, p4= Δy, q1=x0-xmin(left), q2=xmax-x0(right),q3=y0-ymin(bottom),q4=ymax-y0(top).
  • 9. • When pk < 0, as u increases - line goes from outside to inside - entering • When pk > 0, - line goes from inside to outside - exiting • When pk = 0, - line is parallel to an edge • If there is a segment of the line inside the clip region, a sequence of infinite line intersections must go: entering, entering, exiting, exiting. Algorithm:- 1. Set umin = 0 and umax = 1. 2. Calculate the u values: 3. If u < umin or u > umax ignore it. Otherwise classify the u values as entering or exiting. 4. If umin < umax then draw a line from: ( x0 + Δx · umin, y0 + Δy · umin ) to ( x0 + Δx · umax, y0 + Δy · umax ).
  • 10.
  • 11. We have umin = 1/4 and umax = 3/4 Pend - P0 = (15+5,9-3) = (20,6)  If umin < umax , there is a line segment - compute endpoints by substituting u values  Draw a line from (-5+(20)·(1/4), 3+(6)·(1/4)) to (-5+(20)·(3/4), 3+(6)·(3/4))
  • 12. • We have umin = 4/5 and umax = 2/3 Pend - P0 = (2+8, 14-2) = (10, 12) • umin > umax , there is no line segment do draw.  To compute the final line segment: 1. A line parallel to a clipping window edge has pk=0 for that boundary. 2. If for that k, qk<0, the line is completely outside and can be eliminated. 3. When pk<0 the line proceeds outside to inside the clip window and when pk>0, the line proceeds inside to outside. 4. For nonzero pk, u=qk/pk gives the intersection point. 5. For each line, calculate u1 and u2. For u1, look at boundaries for which pk<0 (i.e. outside to inside). Take to be the largest among . For u2, look at boundaries for which pk>0 (i.e. inside to outside). Take u2 to be the minimum of {1,qk/pk}. If u1>u2, the line is outside and therefore rejected.
  • 13. Liang-Barsky vs Cohen-Sutherland:- LB generally more efficient: - LB: updates of u1 and u2 use one division, window intersections computed only once with final u1 and u2. - CS: may repeatedly calculate intersections along a line, even if line is totally exterior to clip window and each intersection computation uses division and multiplication.