Transcript

CS5600 1

Spring 2003 CS 5600 1

More on Bresenham’sAlgorithm

CS5600 Introduction to Computer Graphics

Rich RiesenfeldJanuary 2003Le

ctur

e S

et 2

Spring 2003 CS 5600 2

More Raster Line Issues

• Fat lines with multiple pixel width• Symmetric lines• End point geometry -- how should it

look?• Generating curves, e.g., circles, etc.• Jaggies, staircase effect, aliasing...

Spring 2003 CS 5600 3

Generating Circles

Spring 2003 CS 5600 4

Exploit 8-Point Symmetry

),( yx),( yx−

),( yx −),( yx −−

),( xy),( xy −

),( xy−),( xy −−

CS5600 2

Spring 2003 CS 5600 5

Once More: 8-Point Symmetry

),( yx),( yx−

),( yx −),( yx −−

),( xy),( xy −

),( xy−),( xy −−Spring 2003 CS 5600 6

We Only Need to Generate One Octant

We will generate 2nd Octant

Spring 2003 CS 5600 7

Generating gives),( yx

The following 8 points:

),,(),,(),,(),,( yxyxyxyx −−−−

),(),,(),,(),,( xyxyxyxy −−−−

Spring 2003 CS 5600 8

2nd Octant Is a Good Arc

• The arc is a function in this domain

–single-valued–no vertical tangents

•• Lends itself to Bresenham

–only need to consider E or SE

1<slope

CS5600 3

Spring 2003 CS 5600 9

Implicit Circle Equations

• Let

• For a circle

• So

• And

ryxyxF 222),( −+=

OutsideyxF ⇒> 0),(

InsideyxF ⇒< 0),(

0),( =yxF

Spring 2003 CS 5600 10

Decide Whether E or SE

• Function is

• So

• And

0222 =−+ ryxSEMF ⇒≥ 0)(

EMF ⇒< 0)(

Spring 2003 CS 5600 11

E

SE

SEMF ⇒≥ 0)(

ideal curve

Spring 2003 CS 5600 12

E

SE

ideal curve

EMF ⇒< 0)(

CS5600 4

Spring 2003 CS 5600 13

The Decision Variable d

Again we let,

)(MFd =

Spring 2003 CS 5600 14

Look at Case 1: E

Spring 2003 CS 5600 15

Ed old⇒< 0

ry px p

y px pFdold

2)(2

)1( 2

),1(

21

2

1

−−++=

−+=

Spring 2003 CS 5600 16

ry px p

y px pFdnew

2)(2

)2( 2

),2(

2

1

2

1

−−++=

−+=

Ed old⇒< 0

CS5600 5

Spring 2003 CS 5600 17

)32( ++= xdd poldnewSince,

32

)12()44()1( 2)2( 2

+=

+−+=+−+

x p

x px px px p

Ed old⇒< 0

Spring 2003 CS 5600 18

32

,

+=∆

∆+=

x p

dd

E

Eoldnew

Ed old⇒< 0

Spring 2003 CS 5600 19

Look at Case 2: SE

Spring 2003 CS 5600 20

ry px p

y px pFd new

2)(2

)2( 2

),2(

2

3

2

3

−−++=

−+=

SEd old ⇒≥ 0

CS5600 6

Spring 2003 CS 5600 21

SEd old ⇒≥ 0

)522( +−+= yxdd ppoldnew

Because,…

Spring 2003 CS 5600 22

SEd old ⇒≥ 0

)44

9 1()3()32( +−−+−++ y py px p

43421 43421 43421

From calculation

From newy-coordinate

=− dd oldnew

∆E From oldy-coordinate

Spring 2003 CS 5600 23

SEd old ⇒≥ 0

)522( +−+= yxdd ppoldnew

That is,

Spring 2003 CS 5600 24

522

,

+−=∆

∆+=

yx

dd

ppSE

SEoldnew

SEd old ⇒≥ 0

CS5600 7

Spring 2003 CS 5600 25

There are dependencies on

in computing

Nonconstant s∆′

∆∆ andE SE

yandx pp

Spring 2003 CS 5600 26

Summary

• The only difference from the line algorithm is that point evaluations are needed for

• Algorithm structure is exactly the same

s∆′

Spring 2003 CS 5600 27

Initial Condition

• Let r be an integer. Start at• Next midpoint lies at

• So,

),0( r

),1(21−r

rrrrF 2)2(1),1(4

1

2

1−−−+=−

r−=4

5

Spring 2003 CS 5600 28

Ellipses

• Evaluation is analogous

• Structure is same

• Have to work out the s∆′

CS5600 8

Spring 2003 CS 5600 29

Getting to Integers

• Note the previous algorithm involves real arithmetic

• Can we modify the algorithm to use integer arithmetic?

Spring 2003 CS 5600 30

Integer Circle Algorithm

• Define a shift decision variable

• In the code, plug in

41

−= dh

41+= hd

Spring 2003 CS 5600 31

Integer Circle Algorithm

• Now, the initialization is

• So the initial value becomes

rh −=1

r

rrF

−=

−−=−−

1

41

)45

(41

21

),1(

Spring 2003 CS 5600 32

Integer Circle Algorithm

• Then,

• Since h an integer

41

becomes 0 << hd

04

1 <⇔< hh

CS5600 9

Spring 2003 CS 5600 33

Integer Circle Algorithm

• But h begins as an integer

• And h gets incremented by integers

• Hence, we have an integer circle algorithm

• Sufficient to test for 0<hSpring 2003 CS 5600 34

Integer Circle Algorithm

• But h begins as an integer

• And h gets incremented by integers

• Hence, we have an integer circle algorithm

• Sufficient to test for 0<h

Spring 2003 CS 5600 35

End of Bresenham Circles

Spring 2003 CS 5600 36

Another Digital Line Issue

• Clipping Bresenham lines• The integer slope is not the true slope• Have to be careful• More issues to follow

CS5600 10

Spring 2003 CS 5600 37

Line Clipping Problem

minyy =

minxx =

Clipping Rectangle

)0,0( yx

)1,1( yx

maxxx =

Spring 2003 CS 5600 38

Clipped Line

minyy =

minxx =

Clipping Rectangle)0,0( yx ′′

)1,1( yx

maxxx =

maxyy =

Spring 2003 CS 5600 39

Drawing Clipped Lines

)0,0( yx

)1,1( yx

Spring 2003 CS 5600 40

Clipped LineHas Different Slope !

4

3=m

2

1=m

CS5600 11

Spring 2003 CS 5600 41

Pick Right Slope to Reproduce Original Line Segment

Zoom of previous situationSpring 2003 CS 5600 42

minxx =Clipping Against

E

NE

minyy =

minxx =

444 8444 76))( min(,min Bxmx +

Clip Rectangle

4444 34444 21))( min(,min Bxmx Round +

midpointM

Spring 2003 CS 5600 43

minyy =Clipping Against

minyy =

minxx =

1min −= yy

21

min −= yy

Line getting clipped

B A

Spring 2003 CS 5600 44

Clipping Against minyy =

• Situation is complicated• Multiple pixels involved at ( )• Want all of those pixels as “in”• Analytic , rounding gives A• We want point B

minyy =

∩ x

CS5600 12

Spring 2003 CS 5600 45

Clipping Against minyy =

• Use Line

• Round up to nearest integer

• This yields point B, the desired result

∩ 21

min −= yy

x

Spring 2003 CS 5600 46

Observations

• Lines are complicated• Many aspects to consider• We omitted many• What about intensity of

?0== yxy vs

Spring 2003 CS 5600 47

The End of

Bresenham’s Algorithm

Lect

ure

Set

2


Recommended