Attribution Non-Commercial (BY-NC)

8 views

Week7-2DLineClipping

Attribution Non-Commercial (BY-NC)

- What is an Acute Abdomen
- Application of Computer Graphics
- Tutorial Issue 1 Dark Scenery by Alegion
- Accelero Twin Turbo III Height Restriction Drawing
- Bisect Example
- HW 7 DMOR
- PS Text Effects
- cv v2 madina berkaliyeva 2014 website
- c++ and java
- tesss1
- CG_1_intro
- Gravity Tree _ Week of Code 23 Question _ Contests _ HackerRank
- Video Lab Unit 1
- Common Questions About Computer Graphics
- null
- 3dplotter2
- Computer Aided Design2 ppt
- Computer Programming (for)
- Beautiful lighting FX effect in Photoshop _ Featured - 9tutorials.com
- 3 Cad Hardware

You are on page 1of 14

Line Clipping in 2D

We clip objects to our view before rasterization. Why?

pixel coordinate calculations

parameter interpolation

13 August 2001

2D Viewing

Clipping window

(xwmin, ywmax)

(xwmax, ywmax)

(xwmin, ywmin)

(xwmax, ywmin)

13 August 2001

1. Determine if the line needs clipping

May be able to trivially accept or reject some lines

We can use y = mx + b to do this

against and avoid unnecessary tests.

Cohen

Top

op--Left Top Top

op--Right

Bottom

ottom--Left Bottom Bottom

ottom--Right

TBRL

14 September 2009 SCG 3023 6

13 August 2001

Cohen

Region codes T B R L

Bit 1 2 3 4

1001 1000 1010

14 September 2009 SCG 3023 7

Region coding

How would you decide which region an endpoint is in?

e.g

if (x<xwmin)&&(y>ymax) the point is at the Top-

Top-Left

13 August 2001

algorithm

1. Assign a region code for each endpoints.

2. If both endpoints have a region code 0000 ---

--- trivially accept

these line.

3. Else, perform the logical AND operation for both region codes.

3.1 if the result is not 0000 - trivially reject the line.

3.2 else – (result = 0000, need clipping)

3.2.1. Choose an endpoint of the line that is outside the window.

3.2.2. Find the intersection point at the window boundary (base on

region code).

3.2.3. Replace endpoint with the intersection point and update the

region code.

3.2.4. Repeat step 2 until we find a clipped line either trivially accepted

or trivially rejected.

4. Repeat step 1 for other lines.

if bit 1 = 1 there is intersection on TOP boundary.

if bit 2 = 1 .. .. .. .. BOTTOM ..

if bit 3 = 1 .. .. .. .. RIGHT ..

If bit 4 = 1 .. .. .. .. LEFT ..

How to find intersection point?

use line equation

intersection with LEFT or RIGHT boundary.

x = xwmin (LEFT) x = xwmax (RIGHT)

y = y1 + m(x –x1)

intersection with BOTTOM or TOP boundary.

y = ywmin (BOTTOM) y = ywmax (TOP)

x = x1 + (y –y1)/m

13 August 2001

B1

1001 1000 1010

D1

B2

C1 A2

C2

D2

Example

algorithm

1001 1000 1010 1. A1=0000,A2=0000

2. (both 0000) – Yes

-> accept &

draw

A2 3.

3.1

0001 A1 0000 0010 3.2

3.2.1

3.2.2

3.2.3

3.2.4

13 August 2001

Example

B1 algorithm

1001 1000 1010 1. B1=1001,B2=1010

B2 2. (both 0000) – No

3. AND Operation

B1 1001

A2 B2 1010

Result 1000

0001 A1 0000 0010

3.1 (not 0000) – Yes

reject

3.2

3.2.1

3.2.2

3.2.3

0101 0100 0110 3.2.4

Example

algorithm

1001 1000 1010 1.1.C1=0001,C2=0000

C1=0001,C2=0000

2.2.(both

(both0000)

0000)––No

Yes

3.->AND

acceptOperation

&

C1 draw 0001

A2 3. 0000

3.1result 0000

0001 A1 0000 0010 3.1(not

3.2 0000) - No

C1’ 3.2.3.2.1

(0000)-Yes

3.2.1.

3.2.2 choose C1

C2 3.2.2.

3.2.3 Intersection

point,

3.2.4 C1’ at

LEFT

0101 0100 0110 3.2.3 C1 <- C1’

C1 = 0000

3.2.4 repeat 2

14 September 2009 SCG 3023 14

13 August 2001

Example

D1 algorithm

1001 1000 1010

D1’

D1’’

A2

C1’

C2

D2’’

D2’

D2

14 September 2009 SCG 3023 15

Example

(150, 100)

(10, 10)

(0, 120) dan titik P2(130, 5) . Dapatkan titik-titik persilangan

yang membentuk garisan selepas proses ketipan. Gunakan

algoritma Cohen-Sutherland

14 September 2009 SCG 3023 16

13 August 2001

answer

1. P1=1001, P2=0100

2. (both 0000) – yes No ACCEPT & DRAW

3. AND Operation

Endpoints

B1 after

1001 clipping

1000

0000

P1’’ B2

= (22,

0100 P2’ = 124, 10)

100)

Result 0000

3.1 (not 0000) – no

3.2 (0000) yes

3.2.1choose P2 P1

P1’

3.2.2 intersection with TOP LEFTboundary

BOTTOM boundary

boundary

m = (5-

(5-120)/(130

120)/(130--0) = -0.8846

• y == x1

x y1++(ym(x –x1) where

–y1)/m wherey =x 10;

100;

= 10;

• y = 120

x 10 ++(100-

130 (100

-(10-

(10

0.8846(10-

0.8846(10

-5)/

111)/

-0.8846

-0.8846

-0) ==111.15

124.35

= 22.44

==111

=124

22

• P1’’

P1’ == (124,

P2’ (10,

(22, 111)

100)

10)

3.2.3 update region code P2’ P1’ ==0000

P1’’ 1000

0000(TOP)

3.2.4 repeat step 2

14 September 2009 SCG 3023 17

What’s the maximum number of clips for an accepted line?

Good:

Easy to implement

Early accept/reject tests

Bad:

Slow for many clipped lines

13 August 2001

Liang

• Based on parametric equation of a line:

x = x1 + u.

u.x

0≤u≤1

y = y1 + u.

u.y

xwmin ≤ x1 + u.

u.x ≤ xwmax

ywmin ≤ y1 + u.

u.y ≤ ywmax

… or,

u. pk ≤ qk k = 1, 2, 3, 4

• where:

p1 = - x , q1 = x1 – xwmin

p2 = x , q2 = xwmax- x1

p3 = - y , q3 = y1 – ywmin

p4 = y , q4 = ywmax - y1

Liang--Barsky (continued)

Liang

• Clipped line will be:

x1’ = x1 + u1. x; u1 ≥ 0

y1’ = y1 + u1. y;

y2’ = y1 + u2. y;

• Calculate uk

uk = qk/pk

13 August 2001

Liang--Barsky (continued)

Liang

• u1 : maximum value between 0 and u (for pk < 0), where

starting value for u1 is 0 (u1 =0)

• u2 : minimum value between u and 1 (for pk > 0), where

starting value for u2 is 1 (u2 = 1)

xwmin = 0, xwmax = 100

ywmin = 0, ywmax = 50

And the line we want to clip connects P1(10, 10) and P2(110, 40)

Liang--Barsky (example)

Liang

• Lets construct a table:

k pk qk uk

- x x1 – xwmin

1 = -(110

(110--10) = 10-

10-0 = 10

= -100

x xwmax- x1

2

=110--10=100

=110 = 100 – 10 = 90

- y y1 – ywmin

3 = -(40-

(40-10) = 10–

10–0 = 10

=-30

y ywmax - y1

4

= 40-

40-10=30 = 50 – 10 = 40

13 August 2001

Liang--Barsky (example)

Liang

• Lets construct a table:

k pk qk uk

- x x1 – xwmin

u1 1 = -(110

(110--10) = 10-

10-0 = 10

= -100

x xwmax- x1 Since

2 pk < 0

=110--10=100

=110 = 100 – 10 = 90

- y y1 – ywmin

u1 3 = -(40-

(40-10) = 10–

10–0 = 10

=-30

y ywmax - y1

4

= 40-

40-10=30 = 50 – 10 = 40

Liang--Barsky (example)

Liang

• u1 : maximum value between 0 and u (for pk < 0)!

k pk qk uk

- x x1 – xwmin u=10/(-100)

u=10/(-

u1 1 = -(110

(110--10) = 10-

10-0 = 10 =-1/10 We opt

= -100 u1 =0,

x xwmax- x1

2

=110--10=100

=110 = 100 – 10 = 90

- y y1 – ywmin u=10/(-30)

u=10/(-

u1 3 = -(40-

(40-10) = 10–

10–0 = 10 =-1/3

=-30

y ywmax - y1

4

= 40-

40-10=30 = 50 – 10 = 40

13 August 2001

Liang--Barsky (example)

Liang

• u2 : minimum value between u (for pk > 0) and 1

k pk qk uk

- x x1 – xwmin u=10/(-100)

u=10/(-

1 = -(110

(110--10) = 10-

10-0 = 10 =-1/10 We opt

= -100 u1 =0,

x xwmax- x1

u2 2

=110--10=100

=110 = 100 – 10 = 90

- y y1 – ywmin u=10/(-30)

u=10/(-

3 = -(40-

(40-10) = 10–

10–0 = 10 =-1/3 Since

=-30 pk > 0

y ywmax - y1

u2 4

= 40-

40-10=30 = 50 – 10 = 40

Liang--Barsky (example)

Liang

• u2 : minimum value between u (for pk > 0) and 1

k pk qk uk

- x x1 – xwmin u=10/(-100)

u=10/(-

= 10-

10-0 = 10 =-1/10 We opt

1 = -(110

(110--10)

u1 =0,

= -100

x xwmax- x1 u=90/100

2 We opt

u2 =110--10=100

=110 = 100 – 10 = 90 =9/10 u2 = 0.9

- y y1 – ywmin u=10/(-30)

u=10/(-

3 = -(40-

(40-10) = 10–

10–0 = 10 =-1/3

=-30

y ywmax - y1 u=40/30)

u2 4 =4/3

= 40-

40-10=30 = 50 – 10 = 40

13 August 2001

Liang--Barsky (example)

Liang

• If u1 > u2 then reject line (completely outside clipping

window!)

• Clipped line will be:

x1’ = x1 + u1. x (u1 = 0)

= 10 + 0.(100) = 10

y1’ = y1 + u1. y

= 10 + 0.(30) = 10

= 10 + 0.9(100) = 100

y2’ = y2 + u2. y

= 10 + 0.9(30) = 37

**Homework: Use different values of xwmin, xwmax, ywmin ,

ywmax , P1 and P2 for exercise.

14 September 2009 SCG 3023 27

algorithm

• 1. Initial value : u1 = 0, u2 = 1

• 2. For k = 1, 2, 3, 4;

– 2.1 calculate Pk dan qk

– 2.2 calculate rk = qk/ Pk

– 2.2 if (Pk <0) –find u1 ( if (rk>u1), u1=rk )

– 2.3 if (Pk > 0)–

0)– find u2 ( if (rk<u2), u2=rk )

– 2.4 if (Pk = 0) and (qk< 0) ; reject the line; goto step 6

• 3. If (u1> u2) ; reject the line; goto step 6

• 5. Find the clipped line

•

• x1’ = x1 + u1. ∆x

• y1’ = y1 + u1. ∆y

•

• x2’ = x1 + u2. ∆x

• y2’ = y1 + u2. ∆y

•

• 6. Repeat step 1 –5 for other lines.

•14 September 2009 SCG 3023 28

- What is an Acute AbdomenUploaded bydrhomiedan
- Application of Computer GraphicsUploaded byAbhishek Vk
- Tutorial Issue 1 Dark Scenery by AlegionUploaded byHestu Adi Nugroho
- Accelero Twin Turbo III Height Restriction DrawingUploaded byNathan Colon
- Bisect ExampleUploaded bykragan318_78609
- HW 7 DMORUploaded byAshish Vishnoi
- PS Text EffectsUploaded byapi-26658163
- cv v2 madina berkaliyeva 2014 websiteUploaded byapi-247957764
- c++ and javaUploaded byAnand Dhanalakota
- tesss1Uploaded byCahyadi Maulana
- CG_1_introUploaded byEkram ALhadidi
- Gravity Tree _ Week of Code 23 Question _ Contests _ HackerRankUploaded byIfj Oriskó Norbert
- Video Lab Unit 1Uploaded byDewa Djantra
- Common Questions About Computer GraphicsUploaded byAshwin Kumar
- nullUploaded byapi-26161845
- 3dplotter2Uploaded bynocats69
- Computer Aided Design2 pptUploaded byelango_mm3307
- Computer Programming (for)Uploaded byBank
- Beautiful lighting FX effect in Photoshop _ Featured - 9tutorials.comUploaded byPako Mogotsi
- 3 Cad HardwareUploaded byRaj Sekhar
- Tutorial Ilustración VectorialUploaded byDiegoabh1222
- 15938 IT BSci Games Dev A4 v2Uploaded byFajri Nur Prasetyo
- LQ3 1S1718Uploaded byKaren Lovedorial
- LEACH AlgorithmUploaded byAhmad Hwadi
- Metode_grafikUploaded bysarina
- Adobe Photoshop Shortcut KeysUploaded byJerson Esguerra Rodriguez
- Journal NamesUploaded bysamia
- Tutorial PotoshopUploaded byMochamad Yogi Wasngadiredja
- Computer ProgrammingUploaded byBank
- AOP T2Uploaded byHelen Chou

- Transportation CHAP 7Uploaded byvijayakumarkn
- New scheme based on GMM-PCA-SVM modelling for automatic speaker recognition.pdfUploaded byjehosha
- Activity06.pdfUploaded byJoseph Cedric Quirino
- algorithmComplexity in data structureUploaded byshambhurajput
- lecture33.pptUploaded byAnonymous niE5VQOH
- Recent Advances in Flower Pollination AlgorithmUploaded byATS
- 10.1.1.57.3883Uploaded byJavier Ignacio Pinto Schlack
- DSP1Uploaded bySantosh Ban
- Mech 1442230466423Uploaded byEllango Arasar
- Solution of Macroeconometric ModelsUploaded bygiorgiop5
- NyquistUploaded byMahi Ya
- DSP_class NotesUploaded byNikhil Pathak
- 3. the Z-transform and Its ApplicationsUploaded byshakil
- AsadSarwar_873_BESE-3A_Ass#1Uploaded byAsad Sarwar
- AN3680Uploaded bymono_neurone
- Back Propagation: VariationsUploaded byRoots999
- 07 Rr410201 Digital Signal ProcessingUploaded byandhracolleges
- International Journal of Mathematics and Statistics Invention (IJMSI)Uploaded byinventionjournals
- Design, Analysis and Experimental Evaluation of Block Based Transformation in MFCC Computation for Speaker RecognitionUploaded byMarkAGregory
- DataMining-Caterina Alexandra PredunăUploaded byAAApre
- HashUploaded byTejas Patil
- L S T Lecture 1 E Routh Spring 2012Uploaded byFazal Akbar
- Unscented KF Using Agumeted State in the Presence of Additive NoiseUploaded byJang-Seong Park
- SimulatedUploaded byPushkar Arora
- Midterm 2 SolutionUploaded byvirjog
- A Survey Disease Detection Mechanism for Cotton Leaf: Training & Precaution Based ApproachUploaded byEditor IJRITCC
- IQUploaded byRomualdo Begale Prudêncio
- Crypto_Cheat_Sheet-Technical_Bulletin-en.pdfUploaded byellococareloco
- MIT16_30F10_rec07Uploaded byJames Henry Dannatt
- Ml AlgorithmsUploaded byramesh158