Вы находитесь на странице: 1из 58

INDIANINSTITUTEOFTECHNOLOGYROORKEE

DEPARTMENTOFCIVILENGINEERING

CE201:ComputerAidedGraphics
Week5,6,7
RajatRastogi
rajatfce@iitr.ernet.in

Previous Lecture
PreviousLecture
ImageFileFormats
Image File Formats
RasterFormats
VectorFormats
Vector Formats
FormatStructure
ColourSetting
C l
S tti

Lecture Outline
LectureOutline
ScanConversion
Scan Conversion
Point
Line
Circle

Point Scan
PointScan
Point
Pointplottingisfurnishedbyconvertingasingle
plotting is furnished by converting a single
coordinatepositionintoappropriateoperationsfor
theoutputdeviceinuse.
Randomscanusesstoredpointplottinginstructions
(coordinates)andconvertthemindeflectionvoltage
thatpositionstheelectronbeamatthescreen
locationstobeplottedduringeachrefreshcycle.

Point Scan1
PointScan1
Raster
Rasterscandependsonsettingthebitvalue
scan depends on setting the bit value
correspondingthespecifiedscreenpositionwithin
theframebufferto1.Theelectronbeamwhen
sweepsacrosssuchpositioninalineemitsburstof
electronswithintensitiescorrespondingtocolour
codestobedisplayedatthatlocation.
d t b di l d t th t l ti

Point Scan2
PointScan2
Let
Letasscan
as scanconvert
convertapoint(x,y)toapixellocation
a point (x, y) to a pixel location
(x,y)
x=Floor(x),andy=Floor(y)
WhereFloorisafunctionthatreturnslargestintegerthat
islessthanorequaltotheargument.

Insuchacase,theoriginisplacedatthelowestleft
cornerofthepixelgridintheimagespace
Allpointsthatsatisfyx
All i
h
i f x<x+1andy
1 d y<y+1
1
willbemappedtopixellocation(x,y)(referFiga)

Point Scan3
PointScan3

Xiang and Plastock

Point Scan4
PointScan4
If
Iftheoriginofcoordinatesystemfor(x,y)isto
the origin of coordinate system for (x y) is to
beshiftedtonewlocationsay(x+0.5,y+0.5),
then
x=Floor(x+0.5),andy=Floor(y+0.5)
Thiswillplacetheoriginofthecoordinatesystem
This will place the origin of the coordinate system
(x,y)atthecentreofpixel(0,0)
Now,allpointsthatsatisfyx
Now all points that satisfy x0
0.5
5 x<x
x < x+0
+0.5and
5 and
y0.5 y<y+0.5willbemappedtopixellocation
( ,y)(
(x,y)(referFigb)
g )

Line ScanConversion
LineScan
Conversion
Lineplottingisdonebycalculatingintermediate
e p o g s do e by ca cu a g e ed a e
positionsbetweenthetwospecifiedendpointpositions.
Linearlyvaryinghorizontalandverticaldeflection
voltagesaregeneratedproportiontotherequired
changesinx,ydirectionstoproducethesmoothline.
Astraightlinesegmentisdisplayedbyplottingthe
A t i ht li
t i di l d b l tti th
discretepointsbetweenendpointpositions.
These
Theseintermediatepositionsarecalculatedfromtheequation
intermediate positions are calculated from the equation
oftheline
Colourintensityisloadedintotheframebufferatthe
corresponding pixel coordinate
correspondingpixelcoordinate

Line ScanConversion1
LineScan
Conversion1
Sc
Screenlocationsarereferencedwithintegervalues.E.g.
ee oca o s a e e e e ced
ege a ues g
(10.48,20.51)willbeconvertedtopixelposition(10,20)
Thisroundingeffectcauseslinestobedisplayedwitha
stairstepappearance.Thisisnoticeableonlow
resolutionsystems.
Bettersmoothingcanbeachievedbyadjustinglight
B tt
thi
b
hi d b dj ti li ht
intensitiesalongthelinepaths.

Line ScanConversion2
LineScan
Conversion2

Scan Lin
ne No

Pixelcolumnnumberisbasicallypixelpositionacrossa
e co u
u be s bas ca y p e pos o ac oss a
scanline.Theseareincreasingfromlefttoright.
Scanlinenumberareincreasingfrombottomtotop.
Loadingaspecifiedcolour intoframe
bufferatapixelpositiondefinedby
columnxalongscanliney
l
l
li
setPixel (x,y)
Currentframebufferintensityfora
Current frame buffer intensity for a
specifiedlocationcanbeaccomplished
ggetPixel ((x,y)
, y)
2
1
0

0 12

Pixel
column No

Line ScanConversion3
LineScan
Conversion3
LineisdefinedbytwoendpointsP
y
p
q
1,,P2 andtheequationof
lineasshownintheFigure
Thesecanbeplottedorscanconvertedusingdifferentline
plottingalgorithms.
l tti
l ith
Theslopeinterceptequationis
y
P2(x2, y2)
notsuitableforverticallines.
Horizontal,verticalanddiagonal
y = m.x + b
(|m|=1)linescanbehandled
as special cases and can be
asspecialcasesandcanbe
P1 (x
( 1, y 1)
mappedtoimagespace
b
straightforward.
x

Line Drawing Algorithms


LineDrawingAlgorithms
Directuseoflineequation
Direct use of line equation
DDAalgorithm
BresenhamsLineAlgorithm
h i
l ih

Direct use of Line equation


DirectuseofLineequation
Directapproach
Direct approach
y2

TheCartesianslope
interceptequationfora
straightline:

y=m.x+b

(1)

mrepresentsslopeof

l
f
thelineandbis
p
y
interceptonyaxis,such
that
m=

y 2 y1

x2 x1

b = y1 m . x1

y1

(2)
(3)

x1 x2

y2
y1
x1

x2

Direct use of Line equation..1


DirectuseofLineequation..1
For
Forasmallchangein
a small change in x
x Forlineswithslope
For lines with slope
alongtheline,the
magnitudes|m|<1,x
correspondingchange
issetproportionalto
inycanbegivenby
smallhorizontal
deflectionvoltageand
y=m.x (4)
th
thecorresponding
di
or x=y/m
(5)
verticaldeflectionis
Theseequationsform
the basis for determining
thebasisfordetermining
then set proportional to
thensetproportionalto
thedeflectionvoltages
yascalculatedfrom
inanalogdevices.
q
( )
theequation(4).

Direct use of Line equation2


DirectuseofLineequation2
For
Forlineswithslope
lines with slope
Forlineswithslope
For lines with slope
magnitudes|m|>1,y
magnitudesm=1,x=
issetproportionaltoa
yandthehorizontal
smallverticaldeflection
andverticaldeflection
voltageandthe
voltageareequal
corresponding
di
horizontaldeflectionis
then set proportional to
thensetproportionalto
xascalculatedfrom
q
( )
theequation(5).

Direct use of Line equation3


DirectuseofLineequation3
Thismeans:
This means:
Firstscanconvertendpointstopixellocations(x1,y1)and
(x2,y2)
Setmandbusingequations
For|m| 1,forintegervalueofxbetweenandexcluding
x1,xx2,calculatethecorrespondingvalueofyandscan
calculate the corresponding value of y and scan
convert(x,y)
For|m|>
| | 1,forintegervalueofxbetweenandexcluding
g
g
y1,y2,calculatethecorrespondingvalueofxandscan
convert(x,y)

Direct use of Line equation4


DirectuseofLineequation4
Example:
Endpointsare(0,0)and(6,18).Computeeachvalueofy
asxstepsfrom0to6andplot.
Forequationy=m.x+b,computeslopeas
m=y/x

Usingvalueofmcomputeb
Placex=0to6andcomputecorrespondingvalueofy
Plot

Digital Differential Analyzer (DDA)


DigitalDifferentialAnalyzer(DDA)
DDA
DDAisanincrementalscan
is an incremental scanconversion
conversionlinealgorithm
line algorithm
basedoncalculatingeitherxoryasmentionedin
lineprimitives.
Supposeatstepithepointis(xi,yi)ontheline.
p
yi+1)
Fornextpoint(x
i+1,y
yi+1 =yi +y,wherey=mx
xi+1 =xi +x,wherex=y/m
Theprocesscontinuesuntilxreachesx2(for|m| 1case)
oryreachesy2(for|m|>1case)

Digital Differential Analyzer1


DigitalDifferentialAnalyzer1
Consider
Consideralinewithpositiveslope.Lettheslopebe
a line with positive slope. Let the slope be
lessthanorequalto1.Forunitintervalx=1,
yk+1 =yk +m,wherek=1,2,.,endpoint
(6)
Thevalueofyk+1 shouldberoundedtothenearestinteger

Forslopegreaterthan1,increasingyby1
xk+1 =xk +1/m,wherek=1,2,.,endpoint (7)

Digital Differential Analyzer2


DigitalDifferentialAnalyzer2
The
Theassumptionhereisthatlinesareprocessedfrom
assumption here is that lines are processed from
lefttoright.Ifitisprocessedfromrighttoleftthen
yk+1 =yk m
xk+1 =xk 1/m

(8)
(9)

Digital Differential Analyzer3


DigitalDifferentialAnalyzer3
Fornegativeslopeoflineasshowninfigure:
For negative slope of line as shown in figure:
Ifmovingfromlefttoright:
Setx=+1anduseequation(8)form<1tocalculateyvalues
Set y=1anduseequation(7)form>1tocalculatexvalues
y

Ifmovingfromrighttoleft:
If
Ifm<1thensetx=1andobtainy
m < 1 then set x = 1 and obtain y
valuesfromequation(6)
Ifm>1thensety=+1andobtainx
values from equation (9)
valuesfromequation(9)

Digital Differential Analyzer4


DigitalDifferentialAnalyzer4
This
Thisalgorithmisfasterincalculatingpixelpositions
algorithm is faster in calculating pixel positions
Iteliminatesmultiplicationbymakinguseofraster
characteristics
Butroundingoffinsuccessiveadditionsandits
accumulationmaycausedriftingofthepixelposition
y
g
p
p
awayfromthetrueline
Thisroundingoffprocedureisalsotimeconsuming
Byconvertingmor1/mintointegerorfractional
part,thetimeconsumedcanbereduced.

BresenhamssLineAlgorithm
Bresenham
Line Algorithm
Thisrasterlinegeneratingalgorithmismoreaccurate
s as e
e ge e a g a go
s o e accu a e
andefficient
Itusesonlyincrementalintegercalculations
Itcanbeadaptedtodisplaycirclesandothercurves.
Themethodisbasedonidentifyingthenearestpixel
positionclosertothelinepathateachsamplestep.

Fig-1

13

53

12

52

11

51

10

50
10

11

12

13

Fig-2
50

51

52

53

BresenhamssLineAlgorithm1
Bresenham
Line Algorithm1
InFig1thelinesegment
g
e e seg e
startsfromscanline11
andpixelposition
( l
(column)10.Thenext
) 10 Th
pointalongthelinemay
be at pixel position (11,
beatpixelposition(11,
11)or(11,12)
Similarly,inFig2theline
segmentstartsfrom(50,
52)andthenextpixel
position may be (51 52)
positionmaybe(51,52)
or(51,51)

13
12
11

Fig-1

10
10

11

12

13

53
52
51
50

Fig-2
Fig
2
50

51

52

53

BresenhamssLineAlgorithm2
Bresenham
Line Algorithm2
Bresenhams
Bresenham slinealgorithmteststhesignofan
line algorithm tests the sign of an
integerparameterandtheonewhosevalueis
proportionaltothedifferencebetweenthe
separationsofthetwopixelpositionsfromtheactual
linepathisselected.
y
Letthelinestartsfromleftend
point(xo,yo)ofagivenline.Now, y
the pixel whose scan line y value y
thepixelwhosescanlineyvalue
isclosesttothelinepathisplotted. y
k+3

k+2

k+1

xk

xk+1 xk+2 xk+3

Fig-3

BresenhamssLineAlgorithm3
Bresenham
Line Algorithm3
Let
Letthepixeldisplayedis(x
the pixel displayed is (xk,y
, yk).Thenextpixelto
). The next pixel to
plotwillbeincolumnxk+1 andmayberepresentedas
(xk+1,yk)or(xk+1,yk+1)
y
y = m.x + b
Thedifferencebetweenestimated y
valueofyandnewyvaluealongthey
d
d
lineistobecomputed.
y
k 3
k+3

k+2

kk+1
1

2
1

Forfirstpoint
yest =m.(xk+1)+b(10) x
Difference
iff
d1 =yest yk
(11)
Forsecondpoint d2 =(yk+1) yest
(12)
Difference between the two separations = d1 d2
Differencebetweenthetwoseparations=d
k

xk+1 xk+2 xk+3

Fig-3

BresenhamssLineAlgorithm4
Bresenham
Line Algorithm4
Difference
Difference(d
(d1 d2)
) =2m.(x
2m.(xk+1)
+1) 2y
2 yk +2b
+ 2b 1 (13)
Letm=y/xdenotingverticalandhorizontal
separations.Letp
p
px isdefinedas
y
k 3
k+3

px = x(d1 d2)
px=2 y.xk 2x.yk +c
Where,c=2 y+x(2b 1)

y = m.x + b

yk+2

(14)
(15)

ykk+11

d2
d1

yk

Decisionparameterpx isvei.e.d1<d2
Pixelatyk isclosertolinethanthatatyk+1
Lowerpointwillbeplotted
ViceVersa

xk

xk+1 xk+2 xk+3

Fig-3

BresenhamssLineAlgorithm5
Bresenham
Line Algorithm5
The
Thechangeincoordinatealongthelinetakesplace
change in coordinate along the line takes place
inunitsteps.Thedecisionparameteratnextstepwill
be:
pk+1 =2y.xk+1 2x.yk+1 +c
Andpk+1 pk =2y(xk+1 xk) 2x(yk+1 yk)
(16)
Butxk+1 =xk+1,sothat
pk+1 =pk +2y 2x(yk+1 yk)
(17)
( k+1 yk)iseither0or1dependinguponthesignofp
(y
) is either 0 or 1 depending pon the sign of pk.
Theinitialvalueofparameterwillbe
po =2y
= 2 y x
(18)

BresenhamssLineAlgorithm6
Bresenham
Line Algorithm6
Algorithmfor|m|<1:(steps)
Algorithm for |m|<1: (steps)
Inputandstore(xo,yo).Plotit(loadonbuffer).
Calculatex,y,2y 2x
Computedecisionparameter,po (=2y x)
Assumingpk<0,thenextpointwillbe(xk+1,yk)and
pk+1 =pk +2y
Otherwise,plotpoint(xk +1,yk +1)and
pk+1 =pk +2y
2 2x
2
Repeatstepxtimes

BresenhamssLineAlgorithm7
Bresenham
Line Algorithm7
E.g.
E.g.Plotalinewithendpoints(20,10)and(30,18).
Plot a line with end points (20, 10) and (30, 18).
Theslopeoflineis0.8.
Calculatex(=10),y(=8)
Computedecisionparameter,po (=2y x=6)
Compute2y(=16),2y 2x(=4)
Assumingpk<0,thenextpointwillbe(xk+1,yk)and
pk+1 =pk +2y
Oth
Otherwise,plotpoint(x
i
l t i t ( k +1,y
1 k +1)and
1) d
pk+1 =pk +2y 2x
Repeatstepxtimes
Repeat step x times

BresenhamssLineAlgorithm8
Bresenham
Line Algorithm8
Itisgeneralizedtolineswitharbitraryslopes.
s ge e a ed o es
a b a y s opes
Considerssymmetrybetweenoctantsandquadrantsof
thexyplane.
Algorithmallowsmovingalongpixelpositionfromeither
endoftheline.
Forpositiveslopeandstartfromleftendpoint,boththe
incrementsarepositive.Itisviceversaforstartfrom
right end point
rightendpoint.
Fornegativeslope,oneincrementwillbepositiveand
othernegativedependinguponthestartpoint.
g
p
g p
p

BresenhamssLineAlgorithm9
Bresenham
Line Algorithm9
Whenthetwoverticalseparationsfromthelinepathare
e
e o e ca sepa a o s o
e e pa a e
equal(d1 =d2),wechooseupper(orlower)ofthetwo
candidatepixels.
Specialcaseslikey=0(horizontalline);x=0(vertical
line)and|x|=|y|(diagonalline)canbeloaded
directly into the frame buffer without processing them
directlyintotheframebufferwithoutprocessingthem
throughthelineplottingalgorithm.

Circle Generating Algorithms


CircleGeneratingAlgorithms
Properties of circle:
A circle is defined as the set of points that are all at a given
distance r from a center position (xc,yc)
This distance relationship is expressed by the Pythagorean
theorem in Cartesian coordinates as
(x xc)2 + (y yc)2 = r2
(22)
For position of points on a circle
Move from ((xc r)) to ((xc + r)) in unit steps
p
Calculate corresponding y values as:

y = yc (r2 (xc x)2

(23)

r
yc
xc

Circle Generating Algorithms1


CircleGeneratingAlgorithms1
This is not the best method for ggeneratingg a circle.
One problem with this approach is that it involves
considerable computation at each step.
Moreover, the spacing between plotted pixel
positions is not uniform
The
Th spacing
i can be
b adjusted
dj t d by
b interchanging
i t h i x and
dy
whenever the absolute value of
slope
p of the curve is ggreater than 1.
This is computationally more
cumbersome.

Circle Generating Algorithms2


CircleGeneratingAlgorithms2
Another
o e approach
app oac iss to
o use po
polar
a coo
coordinates
d a es r aand
d ,
yielding
x = xc + r Cos
(24)
y = yc + r Sin
(25)
Larger angular separations along the circumference can
be connected with straight line segments to approximate
the circular path.
For a more continues boundary on a raster display,
display the
step size is set at 1/r. This plots pixel positions that are
approximately
pp
y one unit apart.
p

Circle Generating Algorithms3


CircleGeneratingAlgorithms3
Computation can be reduced either by
Considering symmetry w.r.t. yaxis for segment in 1st and
2nd quadrant, and then considering symmetry w.r.t. xaxis
for segment in 3rdd and 4thh quadrant or
Considering the symmetry between adjacent octants
within a quadrant w.r.t
w r t 45o line
(y, x)
(-y, x)
Therefore calculations are required
(-x, y)
(x, y)
for points between x=0 and x=y
(x, -y)
(-x, -y)
and then these are mapped to rest
eight sectors.
(y, -x)
(-y, -x)
450

Circle Generating Algorithm4


CircleGeneratingAlgorithm4

Circle Generating Algorithms5


CircleGeneratingAlgorithms5
All these procedures require a good deal of
computation time
g
are based on
More efficient circle algorithms
incremental calculations as in the Bresenham line
algorithm
Bresenhams line algorithm is adapted to circle
generation by setting up decision parameters for
finding the closest pixel to the circumference at each
sampling step
q
calculations byy comparing
p
g the
It avoids squareroot
squares of the pixel separation distances

Midpoint Circle Algorithm


MidpointCircleAlgorithm
The closest pixel position to the specified circle path
is determined by moving unit distance at each step
position is ((xc, yc)
Let radius is r and screen center p
Set up algorithm to calculate pixel positions around a
circle p
path centered at the coordinate origin
g (0, 0)
To move each calculated position (x, y) to its proper
screen position add xc to x and yc to y
Along the circle section from x = 0 to x = y in the first
quadrant the slope of the curve varies from 0 to 1

Midpoint Circle Algorithm1


MidpointCircleAlgorithm1
To apply the midpoint method, circle function is
defined as:
fcircle (x, y) = x2 + y2 r2
(26)
Such that
fcircle (x, y) < 0, if (x, y) is inside the circle boundary
=0, if(x,y)isonthecircleboundary
>0, if(x,y)outsidethecircleboundary

Thi
Thisbecomesthedecisionparameterformidpoint
b
h d ii
f
id i
algorithm

Midpoint Circle Algorithm2


MidpointCircleAlgorithm2

Let us consider the midpoint between the two


candidate pixels at sampling position xk+1.
After p
plottingg of the p
pixel at ((xk, yk), next to
determine is whether the pixel at position (xk+1, yk)
along a circular path.
or the one at position (xk+1, yk1) is closer to the
circle.
Decision parameter will be:
x +y -r =0
y
2

p k = f circle x k + 1, y k
2

= (x k + 1 )

+yk
2

yk-1

Midpoint

r2

(27)

xk

x k + 1 xk + 2

Midpoint Circle Algorithm3


MidpointCircleAlgorithm3
If pk<0, this midpoint is inside the circle and the pixel
on scan line yk is closer to the circle boundary.
position is outside or on the
Otherwise,, the mid p
circle boundary, and we select the pixel on scanline
yk1.
Successive decision parameters are obtained using
incremental calculations. For pixel location (xk+1+ 1)
(28)
p k +1 = p k + 2(x k + 1) + ( y 2k +1 y 2k ) ( y k +1 y k ) + 1
yk+1 is either yk or yk1 depending on the sign of pk

Midpoint Circle Algorithm4


MidpointCircleAlgorithm4

Increments for obtaining pk+1 are either 2xk+1 +1 (if pk


is negative) or (2xk+1 + 1 2yk+1)
Evaluation of the terms 2xk+1 and 2yyk+1 can also be
done incrementally as
2xk+1 = 2xk + 2;

2yk+1 = 2yk 2

At the start position (0, r) these two terms have the


values 0 and 2r, respectively.
Each successive value is obtained by adding 2 to the
previous value of 2x and subtracting 2 from the
previous
i
value
l off 2y.
2

Midpoint Circle Algorithm5


MidpointCircleAlgorithm5
The initial decision parameter is obtained by
evaluating the circle function at the start position
(x0, y0) = (0, r) as:
1

p 0 = f cricle 1 , r

=1+ r

5
p0 =
r
4

( )
(29)
If the radius r is specified as an integer, we can simply
or
round to p0 = 1 r ((for r an integer).
g )

Steps
Steps
Input radius r, circle center (xc, yc), and obtain the first point
on the circumference of a circle centered at the origin as (x0,
y0) = (0, r)
Calculate the initial value of the decision parameter as
p0 = 5/4 r
At each xk position, starting at k = 0, perform the following
test: if pk < 0,
0 the next point along the circle centered on (0,0)
(0 0)
is (xk+1 , yk) and pk+1 = pk + 2xk+1 + 1
Otherwise,thenextpointalongthecircleis(xk+1,yk1)and
pk+1 =pk +2x
2 k+1 +1
1 2y
2 k+1
Where2xk+1 =2xk +2and2yk+1 =2yk 2
Determinesymmetrypointsinthesevenotheroctants
Determine symmetry points in the seven other octants
Movepixelposition(calculated)toscreenpositionbyadding

Example
Plot
Plotthegeneratedpixelpositionsforacirclewith
the generated pixel positions for a circle with
radiusr=10usingmidpointcirclealgorithm.
po =1 r=9
Initialpoint(0,10)
Decisionparameters
2xo =0;2yo =20

y=x

y
10
9
8
7
6
5
4
3
2
1
0

x
0

10

BRESENHAMSSALGORITHM
BRESENHAM
ALGORITHM
Assume
ssu e that
a ((xi, yi) aaree thee coo
coordinates
d a es o
of thee last
as sca
scan
converted pixel upon entering step i.
Let the distance from the origin to pixel T squared minus
the distance to the true circle squared = D(t).
Then let the distance from the origin to pixel S squared
minus
i
th distance
the
di t
t the
to
th true
t
circle
i l squared
d = D(s).
D( )
As the coordinates of T are (xi + 1, yi) and those of S are
(xi + 1,
1 yi 1),
1) the following expression can be developed:

BRESENHAMSSALGORITHM1
BRESENHAM
ALGORITHM1
y

(xi, yi)

(xi + 1, yi)
(xi, + 1, yi - 1)

(xi + 1)2 + ( yi 1)2


x

Choosing Pixels in Bresenhams Circle Algorithm

BRESENHAMSSALGORITHM2
BRESENHAM
ALGORITHM2
D(t)
( ) = ((xi + 1))2 + yi2 r2
D(s) = (xi+1)2 + (yi 1)2 r2
This function D provides a relative measurement of the
distance from the center of a pixel to the true circle.
Since D(t)
( ) will always
y be p
positive ((T is outside the true
circle) and D(s) will always be negative (S is inside the
true circle), a decision variable, di may be defined as
follows:
di = D(t) + D(s)
Therefore
di = 2(xi + 1)2 + yi2 + (yi 1)2 2r2

BRESENHAMSSALGORITHM3
BRESENHAM
ALGORITHM3
When
e di<0,
0, ||D(t)|<|D(s)|,
( )| | (s)|, then
e se
select
ec p
pixel
e T.
When di 0, |D(t) |D(s)|, then select pixel S.
The decision variable di+1 for the next step:
p
di+1 = (2xi+1+1)2 + y2i+ 1 + (yi+11)2 2 r2
Hence
di+1 di = 2(xi+1 + 1)2 + y2i+1 + (yi+1 1)2
2(xi + 1)2 y2i (yi 1)2
Since xi+1 = xi + 1

so,

di+1 = di + 4x
4 i + 2(y
2( 2i+1 y2i) 2(y
2( i+1 yi) + 6

BRESENHAMSSALGORITHM4
BRESENHAM
ALGORITHM4
If T is the chosen p
pixel ((di < 0)) then yi+1=yyi and so
di+1 = di + 4xi + 6
If S is the chosen pixel (di 0) then yi+1 = yi1 and so
di+1 = di + 4(xiyi) + 10
Set (0, r) to be the starting pixel coordinates and
compute the base case value di :

d1 = 2 (0 + 1)2 + r2 + (r 1)2 2r2


= 3 2r

Example
Givenaradiusof10units.
e a ad us o 0 u s
Computedi =2(xi+1)2 +yi2+(yi1)22r2.
Setthevalueas(0,r)asthestartpoint
( ,)
p
d0 =2(0+1)2 +102 +101)2 2x102
=2+100+81200
=183200
=17.

Example1
Asd
As d0 <0
< 0,
, yi+1=yyi1.
i1
Sonextpoint(1,10)
d1 =d
d0 +4x
4xii +6.
6.
= 17+4+6
=7
Sonextpointis(2,10).
d2 =d1 +4x2+6
=7+8+6.
=+7.
7.

Example2
So
Sonextpoint(3,9).
e po (3, 9)
d3 =di+4(xiyi)+10
=7+4(39)+10
( )
=724+10
=7.
Sonextpoint(4,9)
d4=7+16+6=15.
Sonextpoint(5,8).
d5 =15+4(58)+10.

Example3
So
Sonextpoint(6,8).
e po (6,8)
d6 =17+4x6+6
=+13.
Sonextpointis(7,7)

Comparison
Iteration

Mid point

Bresenham

(0,10)

(0,10)

(1 10)
(1,10)

(1 10)
(1,10)

(2,10)

(2,10)

(3 10)
(3,10)

(3 9)
(3,9)

(4,9)

(4,9)

(5,9)

(5,8)

(6,8)

(6,8)

(7,7)

(7,7)

Readings
HearnandBaker,104
Hearn and Baker 104 122
XiangandPlastock,

Вам также может понравиться