Liang Barsky algorithm, Lecture notes of Computer Graphics

This is line clipping algorithm

Typology: Lecture notes

2019/2020

Uploaded on 03/26/2020

arvind_verma
arvind_verma ๐Ÿ‡ฎ๐Ÿ‡ณ

4

(1)

11 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Graphics
Liang-Barsky
(Line Clipping Algorithm)
Covered by:-
Arvind Kumar
Assistant Professor
Vidya College of Engg.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Liang Barsky algorithm and more Lecture notes Computer Graphics in PDF only on Docsity!

Computer Graphics

Liang-Barsky

(Line Clipping Algorithm)

Covered by:-

Arvind Kumar

Assistant Professor

Vidya College of Engg.

Liang-Barsky Line Clipping Algorithm This algorithm uses the parametric equations for a line and solves four inequalities to find the range of the parameter for which the line is in the viewport. Parametric Equations are given below:

๐Ÿ

+ t*ฮ” ๐’™

y = ๐’š

๐Ÿ

+ t*ฮ” y , 0 โ‰ค t โ‰ฅ 1

Where ฮ” ๐‘ฅ = ๐‘ฅ

2

  • ๐‘ฅ 1

ฮ” y = ๐‘ฆ

2

  • ๐‘ฆ 1

As we know the point clipping condition is:

๐’˜๐’Ž๐’Š๐’

๐’˜๐’Ž๐’‚๐’™

โ€ฆโ€ฆโ€ฆโ€ฆโ€ฆโ€ฆ(i)

๐’˜๐’Ž๐’Š๐’

๐’˜๐’Ž๐’‚๐’™

.โ€ฆโ€ฆโ€ฆโ€ฆโ€ฆ...(ii)

Liang-Barsky Line Clipping Algorithm

Following observations can be :

if ๐’‘

๐’Š

= 0 : Line is parallel to the clipping boundary.

if ๐’’๐’Š < 0 : Line is completely outside the clipping

boundary.

if ๐’‘๐’Š < 0 : Line proceeds from outside to inside of the

clipping boundary.

if ๐’‘๐’Š < 0 : Line proceeds from inside to outside of the

clipping boundary.

i.e ,

Line intersect the clipping boundary

Liang-Barsky Line Clipping Algorithm

This algorithm calculate value parameter t: ๐’•๐Ÿ and ๐’•๐Ÿ.

โžข The value of ๐’•๐Ÿ is determined checking the edge for which

line proceed from outside to inside( ๐’‘

๐’Š

< 0 ). The

maximum value is taken.

โžข The value of ๐’•๐Ÿ is determined checking the edge for which

line proceed from inside to outside(๐’‘๐’Š > 0 ). The minimum

value is taken if ๐’• ๐Ÿ

๐’• ๐Ÿ , the line is completely outside the window

and it can be rejected.

Otherwise, the value of ๐’•๐Ÿ & ๐’•๐Ÿ , are substituted in the

parametric equations to get the intersection points of the

clipped line.

Liang-Barsky Line Clipping Algorithm

  1. If ๐’‘๐’Š = 0 , then { Line is parallel to the clipping boundary. Now , if ๐’’๐’Š < 0 then { Line is completely outside the clipping boundary. } } else Check for intersection point.
  2. Initialize values ๐’•๐Ÿ= 0 and ๐’•๐Ÿ = 1.
  3. Calculate values for ๐’’๐’Š ๐’‘๐’Š for i= 1 , 2 , 3 , 4.

Liang-Barsky Line Clipping Algorithm

  1. Select values of ๐’’๐’Š ๐’‘๐’Š , where ( ๐’‘๐’Š < 0 ), assign maximum value out of them as ๐’•๐Ÿ.
  2. Select values of ๐’’๐’Š ๐’‘๐’Š , where ( ๐’‘๐’Š > 0 ), assign minimum value out of them as ๐’•๐Ÿ.
  3. If ๐’•๐Ÿ<๐’•๐Ÿ , then calculate intersection points are as : { ๐’™๐’™๐Ÿ = ๐’™๐Ÿ + ๐’•๐Ÿ *ฮ” ๐’™ ๐’š๐’š๐Ÿ = ๐’š๐Ÿ + ๐’•๐Ÿ *ฮ” y ๐’™๐’™๐Ÿ = ๐’™๐Ÿ + ๐’•๐Ÿ *ฮ” ๐’™ ๐’š๐’š๐Ÿ = ๐’š๐Ÿ + ๐’•๐Ÿ *ฮ” y } Draw clipped line (๐’™๐’™๐Ÿ, ๐’š๐’š๐Ÿ , ๐’™๐’™๐Ÿ , ๐’š๐’š๐Ÿ)
  4. Stop
  1. Calculate the value of parameter ๐’‘๐’Š and ๐’’๐’Š, for i = 1 , 2 , 3 & 4. ๐’‘๐Ÿ = - ฮ” ๐’™ ๐’’๐Ÿ = ๐’™๐Ÿ - ๐’™๐’˜๐’Ž๐’Š๐’ ๐’‘๐Ÿ = - 50 ๐’’๐Ÿ = โˆ’๐Ÿ“ ๐’’๐Ÿ ๐’‘๐Ÿ

๐’’๐Ÿ ๐’‘๐Ÿ

๐’’๐Ÿ‘ ๐’‘๐Ÿ‘

๐’’๐Ÿ’ ๐’‘๐Ÿ’

โžข ๐’•๐Ÿ= max( 0 , 0. 25 , 0. 1 ) = 0. 25 , for the values (๐’‘๐’Š < 0 ) โžข ๐’•๐Ÿ= min( 0. 25 , 0. 1 , 1 )= 0. 3 , for the values (๐’‘๐’Š > 0 )

Calculate the intersection points: ๐’™๐’™๐Ÿ = ๐’™๐Ÿ + ๐’•๐Ÿ *ฮ” ๐’™ = 10 + 0. 25 * 50 = 22. 5 ๐’š๐’š๐Ÿ = ๐’š๐Ÿ + ๐’•๐Ÿ *ฮ” y = 10 + 0. 25 * 20 = 15 ๐’™๐’™๐Ÿ = ๐’™๐Ÿ + ๐’•๐Ÿ *ฮ” ๐’™ = 10 + 0. 3 * 50 = 25 ๐’š๐’š๐Ÿ = ๐’š๐Ÿ + ๐’•๐Ÿ *ฮ” y = 10 + 0. 3 * 20 = 16 The Clipped Line end points are ( 22.5,15) & (25, 16)