SlideShare a Scribd company logo
5
Most read
6
Most read
7
Most read
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 ).
Cohen-sutherland & liang-basky line clipping algorithm
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

PPTX
Ray Tracing in Computer Graphics
PPTX
The sutherland hodgeman polygon clipping algorithm
PPT
Fill area algorithms
PPT
Turing Machine
PPTX
Canny Edge Detection
PPTX
Unit 2 part-2
PPT
Lecture15 anti aliasing
PDF
Curves and fractals b spline and bezier
Ray Tracing in Computer Graphics
The sutherland hodgeman polygon clipping algorithm
Fill area algorithms
Turing Machine
Canny Edge Detection
Unit 2 part-2
Lecture15 anti aliasing
Curves and fractals b spline and bezier

What's hot (20)

PPTX
Geometric transformation
PPTX
Concept of basic illumination model
PDF
Little o and little omega
PDF
Graph Theory: Trees
PDF
PPTX
Circle & curve clipping algorithm
PPTX
String matching algorithms
PDF
Digital image processing fundamental explanation
PPTX
Projection In Computer Graphics
PDF
module6_stringmatchingalgorithm_2022.pdf
PPTX
Bfs and Dfs
PPTX
Algorithm big o
PPT
Ch10 Recursion
PDF
Image restoration
PPTX
Computer graphics
PPT
Coloring graphs
PPT
Lecture filling algorithms
PPTX
Quicksort Presentation
PPTX
Polygon filling algorithm
PDF
Asymptotic notation
Geometric transformation
Concept of basic illumination model
Little o and little omega
Graph Theory: Trees
Circle & curve clipping algorithm
String matching algorithms
Digital image processing fundamental explanation
Projection In Computer Graphics
module6_stringmatchingalgorithm_2022.pdf
Bfs and Dfs
Algorithm big o
Ch10 Recursion
Image restoration
Computer graphics
Coloring graphs
Lecture filling algorithms
Quicksort Presentation
Polygon filling algorithm
Asymptotic notation
Ad

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

PPTX
ibuib.pptx
PPTX
kgv.pptx
PPTX
Unit2- line clipping.pptx
PPTX
Computer Graphic - Clipping
PPTX
PPTX
line clipping
PPT
Cohen and Sutherland Algorithm for 7-8 marks
PPT
Clipping
PPTX
Clipping ( Cohen-Sutherland Algorithm )
PPTX
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
PPTX
Lect 5 2d clipping
PPTX
Clipping in 2 d
PPTX
ohu.pptx
PPT
Line clipping
PPTX
Clipping computer graphics
PPTX
Clipping
PPTX
Cohen sutherland line clipping algorithm
PDF
Chapter4.pdf
PPTX
Group 6 Presentation - Copy.pptx
PPTX
Group 5 Presentation.pptx
ibuib.pptx
kgv.pptx
Unit2- line clipping.pptx
Computer Graphic - Clipping
line clipping
Cohen and Sutherland Algorithm for 7-8 marks
Clipping
Clipping ( Cohen-Sutherland Algorithm )
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Lect 5 2d clipping
Clipping in 2 d
ohu.pptx
Line clipping
Clipping computer graphics
Clipping
Cohen sutherland line clipping algorithm
Chapter4.pdf
Group 6 Presentation - Copy.pptx
Group 5 Presentation.pptx
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy

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 ).
  • 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.