+ All Categories
Home > Documents > Chapter 4

Chapter 4

Date post: 08-Jan-2016
Category:
Upload: abishek-purushothaman
View: 6 times
Download: 0 times
Share this document with a friend
Description:
ppt
73
Computer Graphics Computer Graphics Chapter 3 Chapter 3 Graphics Output Primitives Graphics Output Primitives Andreas Savva Andreas Savva
Transcript
Page 1: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 1/73

Computer GraphicsComputer Graphics

Chapter 3Chapter 3Graphics Output PrimitivesGraphics Output Primitives

Andreas SavvaAndreas Savva

Page 2: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 2/73

2

Basic Raster AlgorithmsBasic Raster Algorithms

for 2D Primitivesfor 2D Primitives

Description of picturesSpecified b a set of intensities for the pi!el positions"

Describe it as a set of comple! ob#ects$ such as trees$furniture and %alls$ positioned at specific coordinate

locations %ithin the scene"Graphics programming pac&ages provide functions todescribe a scene in terms of basic geometric structuresreferred to as output primitives"

' Points

' Straight lines

' Circles

' Splines curves and surfaces

' Polgon color areas

' Character strings' (tc"

Page 3: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 3/73

3

)mplementing Application programs)mplementing Application programs

Description of ob#ects in terms of primitives and

attributes and converts them to the pi!els on the

screen"Primitives * %hat%hat is to be generated

Attributes * ho%ho% primitives are to be generated

Page 4: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 4/73

+

PointsPoints

,he electron beam is turned on to illuminate the phosphor

at the selected location -!$ . %here

/ 0 x 0 ma!!

/ 0 y 0 ma!

setpi!el-!$ $ intensit. * loads an intensit value into theframe1buffer at -!$ ."

getpi!el-!$ . * retrieves the current frame1buffer

intensit setting at position -!$ ."

-/$/.

-ma!!$ma!.

CR,

Page 5: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 5/73

inesines

Analog devises$ such as a random1scan displa or avector plotter$ displa a straight line smoothl from one

endpoint to another" inearl varing hori4ontal and

vertical deflection voltages are generated that are

 proportional to the re5uired changes in the ! and directions to produce the smooth line"

Page 6: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 6/73

6

Digital devices displa a straight line b plotting discrete

coordinate points along the line path %hich are calculated

from the e5uation of the line"

Screen locations are referenced %ith integer values$ so plotted

 positions ma onl appro!imate actual line positions bet%een t%o

specific endpoints"

A computed line position of -7/"+8$ 2/"7. %ill be converted to

 pi!el position -7/$ 27." ,his rounding of coordinate values to

integers causes lines to be displaed %ith a stairstep appearance

-the 9 #aggies:."

Particularl noticeable on sstems %ith lo% resolution"

,o smooth raster lines$ pi!el intensities along the line paths must

 be ad#usted"

Page 7: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 7/73

;

ine Dra%ing Algorithmsine Dra%ing Algorithms

Cartesian e5uation<

 y = mx + c

%herem * slope

c * 1intercept

 x

 y

 x x

 y ym

∆=

−=

72

72

 x7

 y7

 x2

 y2

Page 8: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 8/73

8

SlopeSlope

if =m= > 7 

θ > +?

+?

+?

+ve -ve

θ?θ?

θ?

θ?

if =m= < 7

1+? @ θ @ +?

if =m= > 7

+? @ θ @ /? or 

1/? @ θ @ 1+?

Page 9: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 9/73

8  

;  

6  

 

+  

3  

2   7  

/  

/ 7 2 3 + 6 ; 8

 y = xm > 7c > /  y

 x

!

/ /

7 7

2 2

3 3

+ +

6 6

; ;

8 8

==mm= > 7= > 7

Page 10: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 10/73

7/

8

;

6

 

+  

3  

2  

7  

/

/ 7 2 3 + 6 ; 8

 y =  x  7m >

c > 7 y

 x

! round-.

/ 7 7

7 7" 2

2 2 2

3 2" 3

+ 3 3

3" +

6 + +

; +"

8

==mm== << 77

Page 11: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 11/73

77

==mm== >> 77

8

;  

6

+  

3

2

7  

/

/ 7 2 3 + 6 ; 8

 y = 3x 1 2m > 3

c > 12 y

 x

! round-.

/ 12 12

7 7 7

2 + +

3 ; ;

+ 7/ 7/

73 73

6 76 76

; 7 7

8 22 22outside

Page 12: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 12/73

72

,he Digital Differential Anal4er,he Digital Differential Anal4er

-DDA. Algorithm-DDA. Algorithm

m x

 y=

∆∆

!

/ 7

7 +

2 ;

3 7/+ 73

76

means that for a unit -7. change in x there is

m1change in y.

i"e"  y > 3 x  7 m > 3

m y

 x 7=

∆means that for a unit -7. change in y there is

7m change in x.

Do not use y > 3 x  7

to calculate y"

Ese m

Page 13: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 13/73

73

,he DDA Fethod,he DDA Fethod

Eses differential e5uation of the line < mm

)f slope =m= ≤ 7 then increment x in steps of 7 pi!el

and find corresponding y1values"

)f slope =m= > 7 then increment y in steps of 7 pi!el

and find corresponding x1values"

step through in x step through in y

Page 14: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 14/73

7+

,he DDA Fethod,he DDA Fethod

Desired line

- xi$round- yi..

- xi$ yi.

- xi7$round- yim..

- xi7$ yim.

Page 15: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 15/73

7

if slopeif slope mm ≥≥ //

if ==mm== ≤≤ 77 

 xiC7 > xi  7

 yiC7 > yi  m

if ==mm== >> 77 

 yiC7 > yi  7

 xiC7 > xi  7m

Left

Right

Left

Right

Page 16: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 16/73

76

Proceeding from right1endpoint to left1endpointProceeding from right1endpoint to left1endpoint

if slopeif slope mm ≥≥ //

if ==mm== ≤≤ 77 

 xiC7 > xi 1 7

 yiC7 > yi 1 m

if ==mm== >> 77 

 yiC7 > yi 1 7

 xiC7 > xi 1 7m

Left

Right

Left

Right

Page 17: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 17/73

7;

if slopeif slope mm @ /@ /

if ==mm== ≤≤ 77 

 xiC7 > xi  7

 yiC7 > yi  m

if ==mm== >> 77 

 yiC7 > yi 1 7

 xiC7 > xi 1 7m

Left

Right

Left

Right

Page 18: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 18/73

78

Proceeding from right1endpoint to left1endpointProceeding from right1endpoint to left1endpoint

if slopeif slope mm << //

if ==mm== ≤≤ 77 

 xiC7 > xi 1 7

 yiC7 > yi 1 m

if ==mm== >> 77 

 yiC7 > yi  7

 xiC7 > xi  7m

Left

Right

Left

Right

Page 19: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 19/73

7

(!ample -DDA.(!ample -DDA.

+=+=

≤≤

+=+

+

37

7

737 7

7/

 7

ii

ii

 y y x x

m

 x y

! round-.

/ 7 77 +3 7

2 3 2

3 2 2

+ ;3 2

83 3

6 3 3

; 7/3 3

8 773 +

8;

6

+  

3  

2  

7  

/

/ 7 2 3 + 6 ; 8

 y

 x

Page 20: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 20/73

2/

(!ample -DDA.(!ample -DDA.

−−=−=

−<

+−=+

+

.-7

7

 83

37

7

7

ii

ii

 x x y y

m

 x y

 y x round- x.

8 / /; 73 /

6 23 7

7 7

+ +3 7

3 3 2

2 2 2

7 ;3 2

/ 83 3

8   ;  

6  

 

+  

3  

2  

7  

/  

/ 7 2 3 + 6 ; 8

 y

 x

Page 21: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 21/73

27

void ineDDA-int !/$ int /$ int !7$ int 7.  int d! > !7 * !/$ d > 7 * /$ stepsH

  if  -abs-d!.Iabs-d.. steps > abs-d!.H

  else steps > abs-d.H  one of these %ill be 7 or 17  double !)ncrement > -double.d! -double .stepsH  double )ncrement > -double.d -double .stepsH

  double ! > !/H

  double  > /H  setPi!el-round-!.$ round-..H

  for  -int i>/H i@stepsH i.     ! > !)ncrementH

  > )ncrementH  setPi!el-round-!.$ round-..H  JJ

 Kote Kote<< ,he DDA algorithm is faster than the direct use of y > mx  c"

)t eliminates multiplicationH onl one addition"

Page 22: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 22/73

22

(!ample(!ample

Dra% a line from point -2$7. to -72$6.

Dra% a line from point -7$6. to -77$/.

;

6

+

3

2

7

/

/ 7 2 3 + 6 ; 8 7/ 77 72

Page 23: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 23/73

23

Bresenham ine AlgorithmBresenham ine AlgorithmA more efficient approach

Basis of the algorithm<

Lrom start position decide A or B ne!t

AA

BB

Start position

Page 24: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 24/73

2+

Bresenham ine AlgorithmBresenham ine Algorithm

Lor a given value of xone pi!el lies at distance t i above the line$ andone pi!el lies at distance si belo% the line

True line

 si

t i

Page 25: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 25/73

2

Bresenham ine AlgorithmBresenham ine Algorithm

Decision parameter 

d i = - si - t i.

)f d i < /$ then closest pi!el is belo% true line - si smaller.

)f d i ≥ /$ then closest pi!el is above true line -ti smaller.

Me must calculate the ne% values for d i as %e move along

the line"

Page 26: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 26/73

26

3d2d

d

(!ample<(!ample<

.2or"/-i"e" /"-slope.gradientet dxdydx

dy<<<

 T r u e  l i n e

Start pi!el at - x/$ y7.

+d

AtAt x  x 11 <  s7 > dy t 7 > dx 1 dy

d 7 = - si - t i. > dy 1 -dx 1 dy. > 2dy 1 dx

 but 2dy < dx  d i < /  y stas the same

hence ne!t pi!el is at - x7$ y7.

AtAt x  x 22 < s2 > 2dy t 2 > dx 1 2dy

d 2 = - s2 – t 2. > 2dy 1 -dx 1 2dy. > +dy 1 dx

Suppose d2 ≥ /  y is incremented

hence ne!t pi!el is at - x2$ y2.

AtAt x  x 33 < s3 > 3dy - dx t 2 > 2dx 1 3dy

d 3 = - s2 – t 3. > 6dy 1 3dx < /

so y stas the same

hence ne!t pi!el is at - x3$ y2.

 x7  x2  x3 x+  x

 x/ y/

 y7

 y2

 y3

 y

Page 27: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 27/73

2;

)n General)n General Lor a line %ith gradient 0 7d / > 2dy * dx

if d i < / then  yi7 > yi

d i7 > d i  2dyif d i N / then  yi7 > yi  7

d i7 > d i  2-dy *  dx.

 xi7 > xi  7

Lor a line %ith gradient > 7d / > 2dx * dy

if d i < / then  xiC7 > xi

d iC7 > d i  2dx

if d i N / then  xiC7 > xi  7d iC7 > d i  2-dx * dy.

 yiC7 > yi  7

 Kote< Lor =m= 0 7 the constants 2dy and 2-dy-dx. can be calculated once$

so the arithmetic %ill involve onl integer addition and subtraction"

Page 28: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 28/73

28

(!ample(!ample  * Dra% a line from -2/$7/. to -3/$78.

7

78

7;

76

7

7+

73

72

77

7/

2/ 27 22 23 2+ 2 26 2; 28 2 3/ 37 32

-2/$7/.

-3/$78.dx > 7/

dy > 8

initial decision d / > 2dy * dx > 6

Also 2dy > 76$ 2-dy * dx. > 1+

i   d i   ( x i +1, y i +1)

0 6 (21,11)

1 2 (22,12)

2 -2 (23,12)

3 14 (24,13)

4 10 (25,14)

5 6 (26,15)

6 2 (27,16)7 -2 (28,16)

8 14 (29,17)

9 10 (30,18) 

Page 29: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 29/73

2

void ineBres-int !/$ int /$ int !7$ int 7. // line for |m| < 1  int d! > abs-!7 * !/.$ d > abs-7 * /.H  int d > 2 d * d!$ t%oD > 2 d$ t%oDFinusD! > 2 -d * d!.H  int !$ H

  if  -!/ I !7. determines %hich point to use as start$ %hich as end  ! > !7H  > 7H  !7 > !/H  J  else 

  ! > !/H  > /H  J  setPi!el-!$.H

  %hile -! @ !7.   !H  if -d @ /. d > t%oDH  else   H  d > t%oDFinusD!H  J  setPi!el-!$ .H

  JJ

Page 30: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 30/73

3/

Special casesSpecial cases

Special cases can be handled separatel

 * ori4ontal lines -∆ > /.

 * Qertical lines -∆! > /.

 * Diagonal lines -=∆!= > =∆=.

directl into the frame1buffer %ithout

 processing them through the line1plottingalgorithms"

Page 31: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 31/73

37

Parallel ine AlgorithmsParallel ine Algorithms

,a&e advantage of multiple processors"

Given n p processors$ subdivide the line path into n p Bresenhamsegments"

Lor a line %ith slope / < m < 7 and leftpoint - x/$ y/. the distance to

the right endpoint -left endpoint for ne!t segment. is

%here

∆ x > %idth of the line

∆ x p is computed using integer division

 Kumbering the segments$ and the processors$ as /$ 7$ 2$ $ n p17$

starting !1coordinate for the & th partition is

 xk  > x/  k ∆ x p 

 p

 p p

nn x x 7−+∆=∆

Page 32: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 32/73

32

Parallel ine Algorithms -continue.Parallel ine Algorithms -continue.

i"e" ∆ x > 7 $ n p > + processors

Starting x1values at x/$ x/  +$ x/  8$ x/  72

∆ y p > m∆ x p

At the k th segment$ the starting 1coordinates is

 yk  > y/  round-k ∆ y p.Also$ the initial decision parameter for Bresenhams

algorithm at the start of the & th subinterval is<

 pk  > -& ∆ x p.-2∆ y. * round-k ∆ y p.-2∆ x. 2∆ y * ∆ x

++

78

+

7+7==

−+=∆  p x

A i li i f i h li

Page 33: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 33/73

33

Anti1aliasing for straight linesAnti1aliasing for straight lines

ines generated can have #agged or stair1step appearance$

one aspect of phenomenon called aliasing$ caused b factthat pi!els are integer coordinate points"

Ese anti1aliasing routines to smooth out displa of a line

 b ad#usting pi!els intensities along the line path

Page 34: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 34/73

3+

Another raster effectAnother raster effect

ine B

ine A

Both lines plotted %ith the same number of pi!els$ but

the diagonal line is longer than the hori4ontal line

Qisual effect is diagonal line appears less thic&"

)f the intensit of each pi!el is I $ then the intensit per unit

length of line A is I $ %hereas for line B it is onl I √2H this

discrepanc is easil detected b the vie%er"

Page 35: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 35/73

3

Circle Generating AlgorithmsCircle Generating Algorithms

Circles and ellipses are common components in

man pictures"

Circle generation routines are often included in

 pac&ages"

Page 36: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 36/73

36

Circle (5uationsCircle (5uations

Polar form x > r Cosθ 

 y > r Sinθ  -r > radius of circle.

 

 P >-r Cosθ $ r Sinθ .

r Sin  )

r Cos ) x

 y

Page 37: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 37/73

3;

Dra%ing a circleDra%ing a circle

DisadvantagesDisadvantages

,o find a complete circle θ  varies from /? to

36/?

,he calculation of trigonometric functions

is ver slo%"

θ  > /?%hile -θ  @ 36/?.

 x > r Cosθ 

 y = r Sinθ 

 setPixel(x,y)

θ  = θ   7?end %hile

Page 38: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 38/73

38

Cartesian formCartesian form Ese Pthagoras theorem

 x2 + y2 = r 2

 x 

r  y

 y

 x   x

 y

(   )2 2$ P x r x= −

Ci l l i hCi l l ith

Page 39: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 39/73

3

Circle algorithmsCircle algorithms Step through x1a!is to determine y-values

Disadvantages< *  Kot all pi!el filled in *  S5uare root function is ver slo%

Page 40: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 40/73

+/

Circle AlgorithmsCircle Algorithms

Ese 81fold smmetr and onl compute pi!el positions for the +? sector"

45°

- x$ y.

- y$ x.

-1 x$ y.

- y$ -x.

- x$ 1 y.-1 x$ 1 y.

-1 y$ x.

--y$ -x.

Page 41: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 41/73

+7

Bresenhams Circle AlgorithmBresenhams Circle Algorithm

eneral !rin"i#leeneral !rin"i#le

,he circle function<

and

Consider onl

+? 0 θ 0 /?

2 2 2- $ .circle f x y x y r = + −

if -!$. is inside the circle boundar

if -!$. is on the circle boundar

if -!$. is outside the circle boundar

/- $ . /

/

circle f x y<= =

>

Page 42: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 42/73

+2

Bresenhams Circle AlgorithmBresenhams Circle Algorithm

 p7  p3

 p2

 D(si ) D(t i )

After point p7$ do %e choose p2 or p3T

 yi 

 yi  - 1

 x i   x i  + 1

h i l l i h

Page 43: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 43/73

+3

Bresenhams Circle AlgorithmBresenhams Circle Algorithm

Define< D- si. > distance of p3 from circle D-t i. > distance of p2 from circle

i"e"  D- si. > - xi  7.2

  yi2

 * r 2

  Ual%as veV D-t i. > - xi  7.2  - yi  * 7 )2 * r 2  Ual%as 1veV

Decision Parameter  pi  $ D%si ) + D%t i )so if pi @ / then the circle is closer to p3 -point above.

  if pi N / then the circle is closer to p2 -point belo%.

,h Al ith,h Al ith

Page 44: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 44/73

++

,he Algorithm,he Algorithm x & $ &

 y& $ r 

 p& $ '12 + r 2 ( r 2 + '12 + %r -1)2 ( r 2 $ 3 ( 2r 

if pi  < 0 then

 yi +1 = yi 

 pi+1 = pi  + 4x i  + *

else if pi  ≥ 0 then

 yi+1 = yi   ( 1 pi +1 = pi  + 4% x i  – yi ) + 1&

Sto# ,en x i   yi  and determine s.mmetr.

#oints in t,e ot,er o"tants

 x i +1 $ x i  + 1

(!ample(!ample

Page 45: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 45/73

+

(!ample(!ample

7/  

 

8  

;  

6  

 

+  

3  

2  

7  

/  

/ 7 2 3 + 6 ; 8 7/

i pi  xi$ i

/ 17; -/$ 7/.7 177 -7$ 7/.

2 17 -2$ 7/.

3 73 -3$ 7/.

+ 1 -+$ . 7 -$ .

6 -6$ 8.

; -;$;.

r > 7/

 p/ > 3 * 2r > 17;

)nitial point - x/$ y/. > -/$ 7/.

Page 46: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 46/73

+6

(!ercises(!ercises

Dra% the circle %ith r  > 72 using the

Bresenham algorithm"

Dra% the circle %ith r  > 7+ and center at

-7$ 7/."

Page 47: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 47/73

+;

Decision ParametersDecision Parameters

Prove that if pi @ / and yiC7 > yi then

 piC7 > pi  + xi  6

Prove that if pi N / and yiC7 > yi * 7 then

 piC7 > pi  +- xi – yi. 7/

Page 48: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 48/73

+8

Advantages of Bresenham circleAdvantages of Bresenham circle

Onl involves integer addition$ subtraction

and multiplication

,here is no need for s5uares$ s5uare rootsand trigonometric functions

id i Ci l Al i h

Page 49: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 49/73

+

Fidpoint Circle AlgorithmFidpoint Circle Algorithm

 yi    yi17

 xi  xi7  xi2

Fidpoint

 x2  y2 * r 2 > /

Assuming that %e have #ust plotted the pi!els at % x i  yi )"Mhich is ne!tT % x i +1 .i) OR % x i +1 yi  ( 1)0

- ,e one t,at is "loser to t,e "ir"le0

Fid i Ci l Al i h

Page 50: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 50/73

/

Fidpoint Circle AlgorithmFidpoint Circle Algorithm

,he decision parameter is the circle at the midpoint

 bet%een the pi!els yi and yi * 7"

)f pi @ /$ the midpoint is inside the circle and the pi!el

 yi is closer to the circle boundar" )f pi N /$ the midpoint is outside the circle and the pi!el

 yi 1 7 is closer to the circle boundar"

72

2 2 272

- 7$ .

  - 7. - .

i circle i i

i i

 p f x y

 x y r 

= + −

= + + − −

D i i PD i i P t

Page 51: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 51/73

7

Decision ParametersDecision Parameters

Decision Parameters are obtained using

incremental calculations

OR 

%here yi7 is either yi or yi17 depending on the sign of pi

77 7 7 2

2 2 27

7 2

- 7$ .

  - 2. - .

i circle i i

i i

 p f x y

 x y r 

+ + +

+

= + −

= + + − −

2 2 2

7 7 72- 7. - . - . 7i i i i i i i p p x y y y y+ + += + + + − − − +

 Kote<

 xi7 > xi 7

,h Al ith,h Al ith7 )nitial values< point-/ r.

Page 52: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 52/73

2

,he Algorithm,he Algorithm7" )nitial values<1 point-/$r .

 x/ > /

 y/ > r 

2" )nitial decision parameter 

3" At each xi position$ starting at i > /$ perform the

follo%ing test< if pi @ /$ the ne!t point is - xi  7$ yi. and

 pi7 > pi  2 xi7  7

  )f pi N /$ the ne!t point is - xi7$ yi17. and

 pi7 > pi  2 xi7  7 * 2 yi7

  %here 2 xi7 > 2 xi  2 and 2 yi7 > 2 yi * 2+" Determine smmetr points in the other octants

" Fove pi!el positions - x,y. onto the circular path centered

on - xc , yc. and plot the coordinates< x > x  xc$ y > y  yc

6" Repeat 3 * until x N y

move circle origin at -/$/. b x > x * xc and y > y * yc

2 2 7 7/ 2 2 +

-7$ . 7 - .circle p f r r r r = − = + − − = −

(!ample(!ample

Page 53: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 53/73

3

(!ample(!ample

7/  

 

8  

;  

6  

 

+  

3  

2  

7  

/  

/ 7 2 3 + 6 ; 8 7/

i pi  xi7$ i7 2 xi7 2 yi7

/ 1 -7$ 7/. 2 2/

7 16 -2$ 7/. + 2/

2 17 -3$ 7/. 6 2/

3 6 -+$ . 8 78

+ 13 -$ . 7/ 78

8 -6$ 8. 72 76

6 -;$ ;.

r > 7/

 p/ > 7 * r > 1 -if r  is integer round p/ > + * r  to integer.

)nitial point - x/$ y/. > -/$ 7/.

Page 54: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 54/73

+

(!ercises(!ercises

Dra% the circle %ith r  > 72 using the

Fidpoint1circle algorithm

Dra% the circle %ith r  > 7+ and center at

-7$ 7/."

Page 55: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 55/73

(!ercises(!ercises

Prove that if pi @ / and yiC7 > yi then

 piC7 > pi  2 xiC7  7

Prove that if pi N / and yiC7 > yi17 then

 piC7 > pi  2 xiC7  7 * 2 yiC7

Fidpoint functionFidpoint function

Page 56: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 56/73

6

Fidpoint functionFidpoint functionvoid plotpoints(int x, int y){

setpixel(xcenter+x, ycenter+y);

setpixel(xcenter-x, ycenter+y);setpixel(xcenter+x, ycenter-y);setpixel(xcenter-x, ycenter-y);setpixel(xcenter+y, ycenter+x);setpixel(xcenter-y, ycenter+x);setpixel(xcenter+y, ycenter-x);setpixel(xcenter-y, ycenter-x);

}

void circle(int r){

int x = 0, y = r; plotpoints(x,y);int p = 1 – r;

 while (x<y) {

x++;if (p<0) p += !x + 1;else {y--;

 p += !(x-y) + 1;}

 plotpoints(x,y);

}}

(llipse Generating Algorithms(llipse Generating Algorithms

Page 57: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 57/73

;

(llipse1Generating Algorithms(llipse1Generating Algorithms

lli#selli#se * A modified circle %hose radius varies from a

ma!imum value in one direction -ma#or a!is. to a minimumvalue in the perpendicular direction -minor a!is."

 P=(x,y) F 7

 F 2

d 7

d 2

,he sum of the t%o distances d 7 and d 2$ bet%een the fi!ed positions F 7 and F 2 -called the foci of the ellipse. to an point P  on the ellipse$ is the same value$ i"e"

d 1 + d 2 $ "onstant

(llipse Properties(llipse Properties

Page 58: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 58/73

8

(llipse Properties(llipse Properties

(!pressing distances d 7 and d 2 in terms of the focal

coordinates F 7 > - x7$ x2. and F 2 > - x2$ y2.$ %e have<

Cartesian coordinates<

Polar coordinates<

2 2 2 2

7 7 2 2- . - . - . - . constant x x y y x x y y− + − + − + − =

r  yr  x

22

7c c

 x y

 x x y yr r 

   − −+ = ÷ ÷ ÷      

cos

sin

c x

c y

 x x r 

 y y r 

θ 

θ 

= +

= +

Page 59: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 59/73

(llipse Algorithms(llipse Algorithms

Smmetr bet%een 5uadrants  Kot smmetric bet%een the t%o octants of a 5uadrant

,hus$ %e must calculate pi!el positions along the

elliptical arc through one 5uadrant and then %e obtain

 positions in the remaining 3 5uadrants b smmetr

- x$ y.-1 x$ y.

- x$ 1 y.-1 x$ 1 y.

r  x

r  y

(llipse Algorithms(llipse Algorithms

Page 60: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 60/73

6/

(llipse Algorithms(llipse Algorithms

Decision parameter<

2 2 2 2 2 2- $ .ellipse y x x y

 f x y r x r y r r = + −

7

Slope > 17

r  x

r  y 2

/ if - $ . is inside the ellipse

- $ . / if - $ . is on the ellipse/ if - $ . is outside the ellipse

ellipse

 x y

 f x y x y x y

<

= =>

2

2

2

2

 y

 x

r xdylope

dx r y= = −

(lli Al ith(lli Al ith Slope 7

Page 61: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 61/73

67

(llipse Algorithms(llipse Algorithms

Starting at -/$ r  y. %e ta&e unit steps in the x direction until

%e reach the boundar bet%een region 7 and region 2"

,hen %e ta&e unit steps in the y direction over the

remainder of the curve in the first 5uadrant"

At the boundar

therefore$ %e move out of region 7 %henever 

7

Slope > 17

r  x

r  y 2

2 2

7 2 2 y x

dy

r x r ydx = − ⇒ =

2 22 2 y xr x r y≥

Fid i t (lli Al ithFid i t (lli Al ith

Page 62: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 62/73

62

Fidpoint (llipse AlgorithmFidpoint (llipse Algorithm

 yi  

 yi17

 xi  xi7  xi2

Fidpoint

Assuming that %e have #ust plotted the pi!els at % x i  yi )"

,he ne!t position is determined b<

72

2 2 2 2 2 272

7 - 7$ .

  - 7. - .

i ellipse i i

 y i x i x y

 p f x y

r x r y r r  

= + −= + + − −

)f p7i @ / the midpoint is inside the ellipse ⇒  yi  is closer 

)f p7i N / the midpoint is outside the ellipse ⇒  yi   * 7 is closer 

i i - i .D i i P -R i 7.

Page 63: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 63/73

63

Decision Parameter -Region 7.Decision Parameter -Region 7.

At the ne!t position U xi7  7 > xi  2V

 

%here yi7 > yi

or  yi7 > yi * 7

77 7 7 2

2 2 2 2 2 27

7 2

7 - 7$ .

  - 2. - .

i ellipse i i

 y i x i x y

 p f x y

r x r y r r  

+ + +

+

= + −

= + + − −

2 2 2 2 2 27 77 7 2 2

7 7 2 - 7. - . - .i i y i y x i i p p r x r r y y+ + = + + + + − − −

Decision Parameter -Region 7.Decision Parameter -Region 7.

Page 64: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 64/73

6+

Decision Parameter -Region 7.Decision Parameter -Region 7.Decision parameters are incremented b<

Ese onl addition and subtraction b obtaining

At initial position %& r  y)

2 2

7

2 2 2

7 7

2 if 7 /

2 2 if 7 /

 y i y i

 y i y x i i

r x r p

increment  r x r r y p

+

+ +

  + <=  + − ≥

2 2

2 and 2 y xr x r y

2

2 2

2 2 2 2 27 7/ 2 2

2 2 27

+

2 /

2 2

7 -7$ . - .

 

 y

 x x y

ellipse y y x y x y

 y x y x

r x

r y r r  

 p f r r r r r r 

r r r r  

=

=

= − = + − −

= − +

Region 2Region 2

Page 65: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 65/73

6

Region 2Region 2Over  region 2$ step in the negative direction and midpoint ista&en bet%een hori4ontal pi!els at each step"

 yi  

 yi17

 xi  xi7  xi2

Fidpoint

Decision parameter<

72

2 2 2 2 2 272

2 - $ 7.

  - . - 7.

i ellipse i i

 y i x i x y

 p f x y

r x r y r r  

= + −= + + − −

)f p2i I / the midpoint is outside the ellipse ⇒  x i  is closer 

)f p2i 0 / the midpoint is inside the ellipse ⇒  x i   7 is closer 

D i i P -R i 2.D i i P t -R i 2.

Page 66: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 66/73

66

Decision Parameter -Region 2.Decision Parameter -Region 2.

At the ne!t position U yi7 * 7 > yi * 2V

 

%here xi7 > xi

or  xi7 > xi  7

77 7 72

2 2 2 2 2 27

7 2

2 - $ 7.

  - . - 2.

i ellipse i i

 y i x i x y

 p f x y

r x r y r r  

+ + +

+

= + −

= + + − −

2 2 2 2 27 77 7 2 2

2 2 2 - 7. - . - .i i x i x y i i p p r y r r x x+ + = − − + + + − +

Decision Parameter -Region 2.Decision Parameter -Region 2.

Page 67: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 67/73

6;

Decision Parameter -Region 2.Decision Parameter -Region 2.

Decision parameters are incremented b<

At initial position % x & y&) is ta&en at the last  position

selected in region 7

2 2

7

2 2 2

7 7

2 if 2 /

2 2 if 2 /

 x i x i

 y i x i x i

r y r pincrement 

r x r y r p

+

+ +

− + >= 

− + ≤

7/ / /2

2 2 2 2 2 27/ /2

2 - $ 7.

  - . - 7.

ellipse

 y x x y

 p f x y

r x r y r r  

= + −

= + + − −

Fidpoint (llipse AlgorithmFidpoint (llipse Algorithm

Page 68: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 68/73

68

Fidpoint (llipse Algorithmp p g

7" )nput r  x$ r  y$ and ellipse center - xc$ yc.$ and obtain the first

 point on an ellipse centered on the origin as

- x/$ y/. > -/$ r  y.

2" Calculate the initial parameter in region 7 as

3" At each xi position$ starting at i > /$ if p7i @ /$ the ne!t

 point along the ellipse centered on -/$ /. is - xi 7$ yi. and

other%ise$ the ne!t point is - xi  7$ yi * 7. and

and continue until

2 2 27/ +

7  y x y x p r r r r = − +

2 2

7 77 7 2i i y i y p p r x r + += + +

2 2 2

7 7 77 7 2 2i i y i x i y p p r x r y r + + += + − +

2 2

2 2 y xr x r y≥

Fidpoint (llipse AlgorithmFidpoint (llipse Algorithm

Page 69: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 69/73

6

p p gp p g+" - x/$ y/. is the last position calculated in region 7" Calculate the

initial parameter in region 2 as

" At each yi position$ starting at i > /$ if p2i I /$ the ne!t point

along the ellipse centered on -/$ /. is - xi$ yi * 7. and

other%ise$ the ne!t point is - xi  7$ yi * 7. and

Ese the same incremental calculations as in region 7" Continue

until y > /"

6" Lor both regions determine smmetr points in the other three

5uadrants"

;" Fove each calculated pi!el position -!$ . onto the elliptical

 path centered on - xc$ yc. and plot the coordinate values

 x  $ x  + x c    y $ y + yc

2 2 2 2 2 27

/ / /22 - . - 7. y x x y p r x r y r r = + + − −

2 2

7 72 2 2i i x i x p p r y r + += − +

2 2 2

7 7 72 2 2 2i i y i x i x p p r x r y r + + += + − +

(!ample(!ample

Page 70: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 70/73

;/

pp

i pi  xi7$ i7 2r  y2 xi7 2r  x

2 yi7

/ 1332 -7$ 6. ;2 ;68

7 122+ -2$ 6. 7++ ;68

2 1++ -3$ 6. 276 ;68

3 2/8 -+$ . 288 6+/

+ 17/8 -$ . 36/ 6+/

288 -6$ +. +32 72

6 2++ -;$ 3. /+ 38+

r  x  $ r  y $ *

2r  y2 x $ & -%ith increment 2r  y

2 > ;2.

2r  x 

2

 y $ 2r  x 

2

r  y -%ith increment 12r  x2

 > 1728.egion 1egion 1 

% x & y&) $ %& *)2 2 27

/ +7 332 y x y x p r r r r = − + = −

Fove out of region 7 since

2r  y2

 x  6 2r  x 

2

 y

(!ample(!ample

Page 71: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 71/73

;7

pp

6  

 

+   3  

2  

7  

/  

/ 7 2 3 + 6 ; 8

i pi  xi7$ i7 2r  y2 xi7 2r  x

2 yi7

/ 177 -8$ 2. ;6 26

7 233 -8$ 7. ;6 728

2 ;+ -8$ /. 1 1

Region 2Region 2 

% x & y&) $ %7 3)  -ast position in region 7.

7/ 22 -; $2. 77ellipse p f = + = −

Stop at y > /

Page 72: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 72/73

;2

(!ercises(!ercises

Dra% the ellipse %ith r  x > 6$ r  y > 8"

Dra% the ellipse %ith r  x > 7/$ r  y > 7+"

Dra% the ellipse %ith r  x > 7+$ r  y > 7/ and

center at -7$ 7/."

Fidpoint (llipse LunctionFidpoint (llipse Lunction

Page 73: Chapter 4

7/17/2019 Chapter 4

http://slidepdf.com/reader/full/chapter-4-568ebe62bc42a 73/73

dpo t pse u ct op pvoid ellipse(int "x, int "y){

int "x = "x ! "x, "y = "y ! "y;int two"x = ! "x, two"y = "y ! "y;int p, x = 0, y = "y;

int px = 0, py = two"x ! y;

ellise#lot#oints(xcenter, ycenter, x, y);$$ "e%ion 1

 p = ro&nd("y – ("x ! "y) + (0' ! "x)); while (px < py) {x++;

 px += two"y;if (p < 0) p += "y + px;

else {y--; py -= two"x; p += "y + px – py;}ellise#lot#oints(xcenter, ycenter, x, y);}$$ "e%ion

 p = ro&nd("y ! (x+0') ! (x+0') + "x ! (y-1)!(y-1) – "x ! "y; while (y 0) {

y--; py -= two"x;if (p 0) p += "x – py;else {x++;

 px += two"y; p += "x – py + px;}


Recommended