Vous êtes sur la page 1sur 63

SCAN CONVERTI NG

LI NES,
CI RCLES and ELLI PSES
LINE DRAWING
Descr i pt i on: Gi v en t he speci f i cat i on f or a
st r ai ght l i ne, f i nd t he col l ect i on of
addr essabl e pi x el s w hi ch most cl osel y
appr ox i mat es t hi s l i ne.
Goal s ( not al l of t hem ar e achi ev abl e w i t h
t he di scr et e space of a r ast er dev i ce) :
St r ai ght l i nes shoul d appear st r ai ght .
Li nes shoul d st ar t and end accur at el y ,
mat chi ng endpoi nt s w i t h connect i ng l i nes.
Li nes shoul d hav e const ant br i ght ness.
Li nes shoul d be dr aw n as r api dl y as possi bl e.
Pr obl ems:
How do w e det er mi ne w hi ch pi x el s t o
i l l umi nat e t o sat i sf y t he abov e goal s?
Ver t i cal , hor i zont al , and l i nes w i t h sl ope
= + / - 1, ar e easy t o dr aw .
Ot her s cr eat e pr obl ems: st ai r - casi ng/
j aggi es/ al i asi ng.
Qual i t y of t he l i ne dr aw n depends on t he
l ocat i on of t he pi x el s and t hei r br i ght ness
I t i s di f f i cul t t o det er mi ne w het her
a pi x el bel ongs t o an obj ect
Di r ect Sol ut i on:
Sol v e y = mx + b, w her e ( 0, b) i s t he y - i nt er cept
and m i s t he sl ope.
Go f r om x
0
t o x
1
:
cal cul at e r ound( y ) f r om t he equat i on.
Tak e an ex ampl e, b = 1 ( st ar t i ng poi nt ( 0, 1) )
and m = 3/ 5.
Then x = 1, y = 2 = r ound( 8/ 5)
x = 2, y = 2 = r ound( 11/ 5)
x = 3, y = 3 = r ound( 14/ 5)
x = 4, y = 3 = r ound( 17/ 5)
x = 5, y = 4 = r ound( 20/ 5)
For r esul t s, see nex t sl i de.
( 0, 1) 1 2 3 4 5
4
3
2
( 5,4)
Ideal Case of a line drawn in a graph paper
Usi ng Round
( 0,1)
( 5,4)
4
3
2
( 0, 1)
4
3
2
( 5,4)
Usi ng nex t hi ghest
Choice of pixels in the raster, as integer values
x = 1, y = 2 = r ound( 8/ 5)
x = 2, y = 2 = r ound( 11/ 5)
x = 3, y = 3 = r ound( 14/ 5)
x = 4, y = 3 = r ound( 17/ 5)
x = 5, y = 4 = r ound( 20/ 5)
Tak e anot her ex ampl e:
y = 10. x + 2
x = 1, y = 12;
x = 2, y = 22.
Why i s t hi s undesi r ed?
` * and ` / ar e ex pensi v e
Round( ) f unct i on needed
Can get gaps i n t he l i ne ( i f sl ope > 1)
DDA - Di gi t al Di f f er ence Anal y zer
I ncr ement al Al gor i t hm.
Based on y = ( y
1
- y
0
) / ( x
1
- x
0
) x + b
Assume x
1
> x
0
and | dx | > | dy |
( can be easi l y modi f i ed f or t he ot her
cases. )
The Al gor i t hm:
dx = x
1
- x
0
;
dy = y
1
- y
0
;
m = dy / dx ;
y = y
0
;
f or ( x = x
0
t o x
1
)
dr aw _poi nt ( x , r ound( y ) ) ;
y = y + m;
end f or
St i l l uses f l oat i ng poi nt and r ound( )
i nsi de t he l oop.
How can w e get r i d of t hese?
Pr obl ems:
4
3 2
1
8
7
6
5
Oct ant s cov er i ng t he 2- D space
MI DPOI NT LI NE ALGORI THM
I ncr ement al Al gor i t hm ( Assume f i r st oct ant )
Gi v en t he choi ce of t he cur r ent pi x el ,
w hi ch one do w e choose nex t : E or NE?
Equat i ons:
1. y = ( dy / dx ) * x + B
2. F( x ,y ) = a* x + b* y + c = 0
Gi v es: F( x ,y ) = dy * x - dx * y + B* dx = 0
= > a = dy , b = - dx , c = B* dx
Rew r i t e as:
F( x ,y ) > 0; i f poi nt bel ow t he l i ne
F( x ,y ) < 0; i f poi nt abov e t he l i ne
NE
M
E
Cr i t er i a:
Evaluate the mid-point, M,
w.r.t. the equation of the line.
F( x ,y ) = dy * x - dx * y + B* dx = 0
Choice: E or NE?
( X
p
, Y
p
)
( X
p
+ 1, Y
p
)
( X
p
+ 1, Y
p
+ 1/ 2)
( X
p
+ 1, Y
p
+ 1)
M
Q
E
NE
Q i s abov e M,
hence sel ect NE pi x el as y our nex t choi ce
ALGO for next choice:
If F(M) > 0 /*Q is above M */
then Select NE
/*M is below the line*/
else Select E ;
/* also with F(M) = 0 */
( X
p
, Y
p
)
( X
p
+ 1, Y
p
)
( X
p
+ 1, Y
p
+ 1/ 2)
( X
p
+ 1, Y
p
+ 1)
M
Q
E
NE
Q i s bel ow M, hence
sel ect E pi x el as
y our nex t choi ce
Ev al uat e mi d- poi nt M usi ng a deci si on
v ar i abl e d = F( X, Y) ;
d = F( X
p
+ 1,Y
p
+ 1/ 2) = a( X
p
+ 1) + b( Y
p
+ 1/ 2) + c;
at M,
Set d
ol d
= d;
Based on t he si gn of d, y ou choose E or NE.
d
new
= F( X
p
+ 2, Y
p
+ 1/ 2)
= a( X
p
+ 2) + b( Y
p
+ 1/ 2) + c
( Ad)
E
= d
new
- d
ol d
= a / * = dy * /
Case I . Chosen E:
d
new
= F( X
p
+ 2, Y
p
+ 3/ 2)
= a( X
p
+ 2) + b( Y
p
+ 3/ 2) + c
( Ad)
NE
= d
new
- d
ol d
= a + b / * = dy dx * /
Updat e usi ng d
new
= d
ol d
+ Ad
Case I I .
Chosen NE:
( X
p
, Y
p
)
( X
p
+ 1, Y
p
)
( X
p
+ 1, Y
p
+ 1/ 2)
( X
p
+ 1, Y
p
+ 1)
M
Q
E
NE
Midpoint criteria
Case EAST :
i ncr ement M by 1 i n x
d
new
= F( M
new
) = F( X
p
+ 2, Y + 1/ 2)
( Ad)
E
= d
new
- d
ol d
= a = dy
( Ad)
E
= dy
Case NORTH- EAST:
i ncr ement M by 1 i n bot h x and y
d
new
= F( M
new
) = F( X
p
+ 2, Y
p
+ 3/ 2)
( Ad)
NE
= d
new
- d
ol d
= a + b = dy - dx
( Ad)
NE
= dy - dx
d = F( M) = F( X
p
+ 1, Y
p
+ 1/ 2) ;
i f d > 0 choose NE
el se / * i f d < = 0 * / choose E ;
Let ' s get r i d of t he f r act i on and see w hat
w e end up w i t h f or al l t he v ar i abl es:
What i s d
st ar t
?
d
st ar t
= F( x
0
+ 1, y
0
+ 1/ 2)
= ax
0
+ a + by
0
+ b/ 2 + c
= F( x
0
, y
0
) + a + b/ 2
= dy - dx / 2
d
st ar t
= 2dy dx ;
( Ad)
E
= 2dy ;
( Ad)
NE
= 2( dy - dx ) ;
The Midpoint Line Algorithm
x = x
0
; y = y
0
;
dy = y
1
- y
0
; dx = x
1
- x
0
;
d = 2dy dx ;
( Ad)
E
= 2dy ;
( Ad)
NE
= 2( dy - dx ) ;
Pl ot _Poi nt ( x ,y )
w hi l e ( x < x
1
)
i f ( d < = 0) / * Choose E * /
d = d + ( Ad)
E
;
el se / * Choose NE * /
d = d + ( Ad)
NE
;
y = y + 1
endi f
x = x + 1 ;
Pl ot _Poi nt ( x , y ) ;
end w hi l e
The Midpoint Line Algorithm (Contd.)
Ex ampl e:
St ar t i ng poi nt :
( 5, 8)
Endi ng poi nt :
( 9, 11)
Successi v e
st eps:
d= 2, ( 6, 9)
d= 0, ( 7, 9)
d= 6, ( 8, 10)
d= 4, ( 9, 11)
4 5 6 7 8 9 10 11
13
12
11
10
9
8
7
6
I NI T: dy = 3; dx = 4; d
st ar t
= 2;
( Ad)
E
= 6; ( Ad)
NE
= - 2;
We hav e consi der ed l i nes i n t he f i r st
Quadr ant onl y .
What about
t he r est ?
4
3 2
1
8
7
6
5
How do y ou gener al i ze t hi s t o t he ot her
oct ant s?
Oct ant Change
1 none
2 Sw i t ch r ol es of x & y
3 Sw i t ch r ol es of x & y ; Use ( 4)
4 Dr aw f r om P
1
t o P
0
; Use ( 8)
5 Dr aw f r om P
1
t o P
0
6 Dr aw f r om P
1
t o P
0
; Use ( 2)
7 Sw i t ch r ol es of x & y ; Use ( 8)
8 Use y = y - 1.
4
3
2
1
8
7
6
5
Oct ant Change
1 None
2 Sw i t ch r ol es of x & y
3 Sw i t ch r ol es of x & y ; Use ( 4)
4 Dr aw f r om P
1
t o P
0
; Use ( 8)
5 Dr aw f r om P
1
t o P
0
6 Dr aw f r om P
1
t o P
0
; Use ( 2)
7 Sw i t ch r ol es of x & y ; Use ( 8)
8 Use y = y - 1.
Dr aw f r om P
1
t o P
0
:
sw ap( P
0
, P
1
) .
Use y = y - 1; dy = - dy ;
Sw i t ch Rol es of X & Y:
Sw ap ( x
1
, y
1
) ;
Sw ap ( x
0
, y
0
) ;
Sw ap ( dx , dy) ;
pl ot _poi nt ( y , x ) ;
I ssues: St ai r casi ng,
Fat l i nes, end- ef f ect s
and end- poi nt or der i ng.
4 5 6 7 8 9 10
11
12
10
9
8
7
6
ANTI -ALI ASI NG
0 1 2 3 4 5 6 7 8 9 10 11
5
4
3
2
1
0
I nt er sect i on of a l i ne w i t h a v er t i cal
edge of t he cl i p r ect angl e
X=X
min
Y=Y
min
NE
E
M
[X
min
, round(m.X
min
+ b)]
[X
min
, m.X
min
+ b]
P
Q
No pr obl em i n t hi s case t o r ound of f t he
st ar t i ng poi nt , as t hat w oul d hav e been a poi nt
sel ect ed by mi d- poi nt cr i t er i a t oo.
Sel ect P by r oundi ng t he i nt er sect i on poi nt
coor di nat es at Q.
X=X
min
Y=Y
min
NE
E
M
[X
min
, round(m.X
min
+ b)]
[X
min
, m.X
min
+ b]
P
Q
X=X
min
Y=Y
min
NE
E
M
[X
min
, round(m.X
min
+ b)]
[X
min
, m.X
min
+ b]
P
Q
What about d
st ar t
?
I f y ou i ni t i al i ze t he al gor i t hm f r om P, and
t hen scan conver t , y ou ar e basi cal l y changi ng dy
and hence t he or i gi nal sl ope of t he l i ne.
Hence, st ar t by i ni t i al i zi ng f r om d( M) , t he
mi d- poi nt i n t he nex t col umn, ( X
mi n
+ 1) , af t er
cl i ppi ng) .
I nt er sect i on of a shal l ow l i ne w i t h a
hor i zont al edge of t he cl i p r ect angl e
X= X
mi n
Y= Y
mi n
A B
Y= Y
mi n
- 1
I nt er sect i on of l i ne w i t h edge and t hen
r oundi ng of f pr oduces A, not B.
To get B, as a par t of t he cl i pped l i ne:
Obt ai n i nt er sect i on of l i ne w i t h ( Y
mi n
- 1/ 2)
and t hen r ound of f , as
B = [ r ound( X|
Y
mi n
- 1/ 2
) , Y
mi n
]
CI RCLE DRAWI NG
CI RCLE DRAWI NG
E
SE
X
p
, Y
p
M
ME
MSE
Assume second oct ant
Now t he choi ce i s bet w een pi x el s E and SE.
CI RCLE DRAWI NG
Onl y consi der s ci r cl es cent er ed at t he or i gi n
w i t h i nt eger r adi i .
Can appl y t r ansl at i ons t o get non- or i gi n
cent er ed ci r cl es.
Ex pl i ci t equat i on: y = + / - sqr t ( R
2
- x
2
)
I mpl i ci t equat i on: F( x ,y ) = x
2
+ y
2
- R
2
= 0
Not e: I mpl i ci t equat i ons used ex t ensi v el y
f or adv anced model i ng
( e.g., l i qui d met al cr eat ur e f r om
" Ter mi nat or 2" )
Dr aw _ci r cl e( x , y )
begi n
Pl ot poi nt ( x , y ) ; Pl ot poi nt ( y , x ) ;
Pl ot poi nt ( x , - y ) ; Pl ot poi nt ( - y , x ) ;
Pl ot poi nt ( - x , - y ) ; Pl ot poi nt ( - y , - x ) ;
Pl ot poi nt ( - x , y ) ; Pl ot poi nt ( - y , x ) ;
end
Use of Sy mmet r y : Onl y need t o cal cul at e one
oct ant . One can get poi nt s i n t he ot her 7
oct ant s as f ol l ow s:
( X, Y)
( Y, X)
( - Y, X)
( X, - Y) ( - X, - Y)
( - Y, - X)
( - Y, X)
( - X, Y)
MI DPOI NT CI RCLE ALGORI THM
Wi l l cal cul at e poi nt s f or t he second oct ant .
Use dr aw _ci r cl e pr ocedur e t o cal cul at e t he r est .
Now t he choi ce i s bet w een pi x el s E and SE.
F( x , y ) = x
2
+ y
2
- R
2
= 0
F( x , y ) > 0 i f poi nt i s out si de t he ci r cl e
F( x , y ) < 0 i f poi nt i nsi de t he ci r cl e.
Agai n, use d
ol d
= F( M) ;
F( M) = F( X
p
+ 1, Y
p
- 1/ 2)
= ( X
p
+ 1)
2
+ ( Y
p
- 1/ 2)
2
- R
2
( Ad)
SE
= d
new
d
ol d
= F( X
p
+ 2, Y
p
- 3/ 2) - F( X
p
+ 1, Y
p
- 1/ 2)
= 2X
p
2Y
p
+ 5 ;
( Ad)
E
= d
new
d
ol d
= F( X
p
+ 2, Y
p
- 1/ 2) - F( X
p
+ 1, Y
p
- 1/ 2)
= 2X
p
+ 3;
d
st ar t
= F( X
0
+ 1, Y
0
- 1/ 2) = F( 1, R - 1/ 2)
= 1 + ( R - 1/ 2)
2
- R
2
= 1 + R
2
- R + 1/ 4 - R
2
= 5/ 4 - R
d > = 0 choose SE ; nex t mi dpoi nt : M
new
;
I ncr ement + 1 i n X, - 1 i n y ; w hi ch gi v es d
new
.
d < 0 choose E ; nex t mi dpoi nt : M
new
;
I ncr ement + 1 i n X; w hi ch gi v es = d
new
.
To get r i d of t he f r act i on,
Let h = d - = > h
st ar t
= 1 - R
Compar i son i s: h < - 1/ 4.
Si nce h i s i ni t i al i zed t o and i ncr ement ed
by i nt eger s, so w e can j ust do w i t h: h < 0.
E
SE
X
p
, Y
p
M
ME
MSE
The Mi dpoi nt Ci r c l e al gor i t hm:
( Ver si on 1)
x = 0;
y = R;
h = 1 R;
Dr aw Ci r cl e( x , y ) ;
w hi l e ( y > x )
i f h < 0 / * sel ect E * /
h = h + 2x + 3;
el se / * sel ect SE * /
h = h + 2( x - y ) + 5;
y = y - 1;
endi f
x = x + 1;
Dr aw Ci r cl e( x , y ) ;
end_w hi l e
10
9
8
7
6
0 1 2 3 4 5 6 7 8
Ex ampl e:
R = 10;
I ni t i al Val ues:
h = 1 R = - 9;
X = 0; Y = 10;
2X = 0;
2Y = 20.
X, Y
2Y
2X
h
7 6 5 4 3 2 1 K
(1, 10)
20
0
-6
(2, 10)
20
2
-1
(3, 10)
20
4
6
(4, 9)
20
6
-3
(5, 9)
18
8
8
(6, 8)
18
10
5
(7, 7)
16
12
6
Pr obl ems w i t h t hi s?
Requi r es at l east 1 mul t i pl i cat i on and
3 addi t i ons per pi x el .
Why ? Because ( Ad)
E
and ( Ad)
SE
ar e l i near f unct i ons and not const ant s.
Sol ut i on?
Al l w e hav e t o do i s cal cul at e t he
di f f er ences f or : ( Ad)
E
and (Ad)
SE
( check i f t hese
w i l l be const ant s) . Say , ( Ad
2
)
E
and ( Ad
2
)
SE
.
I f w e chose E, t hen w e cal cul at e ( Ad
2
)
E/ E
and ( Ad
2
)
E/ SE
, based on t hi s. Same i f w e choose
SE, t hen cal cul at e ( Ad
2
)
SE/ E
and ( Ad
2
)
SE/ SE
.
I f w e chose E, go f r om ( X
p
, Y
p
) t o ( X
p
+ 1, Y
p
)
( Ad)
E- ol d
= 2X
p
+ 3, ( Ad)
E- new
= 2X
p
+ 5.
Thus ( Ad
2
)
E/ E
= 2.
( Ad)
SE- ol d
= 2X
p
2Y
p
+ 5,
( Ad)
SE- new
= 2( X
p
+ 1) 2Y
p
+ 5
Thus ( Ad
2
)
E/ SE
= 2.
I f w e chose SE,
go f r om ( X
p
, Y
p
) t o ( X
p
+ 1, Y
p
- 1)
( Ad)
E- ol d
= 2X
p
+ 3, ( Ad)
E- new
= 2X
p
+ 5.
Thus ( Ad
2
)
SE/ E
= 2.
( Ad)
SE- ol d
= 2X
p
2Y
p
+ 5,
( Ad)
SE- new
= 2( X
p
+ 1) 2( Y
p
- 1) + 5
Thus ( Ad
2
)
SE/ SE
= 4.
So, at each st ep, w e not onl y i ncr ement
h, but w e al so i ncr ement ( Ad)
E
and ( Ad)
SE
.
What ar e ( Ad)
E- st ar t
and ( Ad)
SE- st ar t
?
( Ad)
E- st ar t
= 2* ( 0) + 3 = 3 ;
( Ad)
SE- st ar t
= 2* ( 0) - 2* ( R) + 5
The Mi dPoi nt Ci r c l e Al gor i t hm
( Ver si on 2) :
x = 0; y = r adi us;
h = 1 R ;
del t aE = 3 ; del t aSE = - 2* R + 5 ;
Dr aw Ci r cl e( x , y ) ;
w hi l e ( y > x )
i f h < 0 / * sel ect E * /
h = h + del t aE ;
del t aE = del t aE + 2;
del t aSE= del t aSE + 2
el se / * sel ect SE * /
h = h + del t aSE ;
del t aE = del t aE + 2 ;
del t aSE = del t aSE + 4
y = y 1 ;
endi f
x = x + 1 ;
Dr aw Ci r cl e( x , y ) ;
end_w hi l e
10
9
8
7
6
0 1 2 3 4 5 6 7 8
X, Y
A
SE
A
E
h
7 6 5 4 3 2 1 K
Ex ampl e:
R = 10;
I ni t i al Val ues:
X = 0; Y = 10;
h = 1 R = - 9;
A
E
= 3;
A
SE
= -15;
(1, 10)
-13
5
-6
(2, 10)
-11
7
-1
(3, 10)
-9
9
6
(4, 9)
-5
11
-3
(5, 9)
-3
13
8
(6, 8)
1
15
5
(7, 7)
5
17
6
X, Y
A
SE
A
E
h
7 6 5 4 3 2 1 K
(1, 10)
-13
5
-6
(2, 10)
-11
7
-1
(3, 10)
-9
9
6
(4, 9)
-5
11
-3
(5, 9)
-3
13
8
(6, 8)
1
15
5
(7, 7)
5
17
6
X, Y
2Y
2X
h
7 6 5 4 3 2 1 K
(1, 10)
20
0
-6
(2, 10)
20
2
-1
(3, 10)
20
4
6
(4, 9)
20
6
-3
(5, 9)
18
8
8
(6, 8)
18
10
5
(7, 7)
16
12
6
Comparison of the solutions with two different methods
ELLI PSE DRAWI NG
SCAN CONVERTI NG ELLI PSES
Y
X a
b
- b
- a
Equat i on of El l i pse
cent er ed at or i gi n:
0 b a Y a X b Y) F(X,
2 2 2 2 2 2
= + =
Lengt h of t he maj or ax i s: 2a;
and mi nor ax i s: 2b.
R1
R2
X
Y
sl ope = - 1
Dr aw pi x el s i n t w o r egi ons R1 and R2,
t o f i l l up t he f i r st Quadr ant .
Poi nt s i n ot her quadr ant s ar e obt ai ned
usi ng sy mmet r y .
We need t o obt ai n t he poi nt on t he
cont our w her e t he sl ope of t he cur v e i s - 1.
Thi s hel ps t o demar cat e r egi ons R1 and R2.
The choi ce of pi x el s i n R1 i s bet w een E and SE,
w her eas i n R2, i t i s S and SE.
( ) | |
j

Y) (2a i

X) 2b (
j

Y
f
i

X
f
Y X, f grad
2 2
+ =
c
c
+
c
c
=
Y
f
X
f
: R2 in
and
X
f
Y
f
: R1 In
c
c
>
c
c
c
c
>
c
c
R1
R2
X
Y
sl ope = - 1
0 b a Y a X b Y) F(X,
2 2 2 2 2 2
= + =
At t he r egi on boundar y poi nt on t he el l i pse:
X
f
Y
f

c
c
=
c
c
Based on t hi s condi t i on,
w e obt ai n t he cr i t er i a w hen t he nex t mi d- poi nt
mov es f r om R1 t o R2 :
1/2) (Y a 1) (X b
p
2
p
2
> +
When t he abov e condi t i on occur s,
w e sw i t ch f r om R1 t o R2.
Anal y si s i n r egi on R1:
Let t he cur r ent pi x el be ( X
p
, Y
p
) ; d
ol d
= F( M
1
) ;
For choi ce E ( d< 0) :
d
new
= F( X
p
+ 2, Y
p
- 1/ 2)
= b
2
( X
p
+ 2)
2
+ a
2
( Y
p
- 1/ 2)
2
- a
2
b
2
= d
ol d
+ b
2
( 2X
p
+ 3) ;
Thus, ( Ad)
E1
= b
2
( 2X
p
+ 3) ;
For choi ce SE ( d> 0) :
d
new
= F( X
p
+ 2, Y
p
- 3/ 2)
= b
2
( X
p
+ 2)
2
+ a
2
( Y
p
- 3/ 2)
2
- a
2
b
2
= d
ol d
+ b
2
( 2X
p
+ 3) + a
2
( - 2Y
p
+ 2) ;
Thus, ( Ad)
SE1
= b
2
( 2X
p
+ 3) + a
2
( - 2Y
p
+ 2) ;
F( M
1
) = d
ol d
= F( X
p
+ 1, Y
p
- 1/ 2)
= b
2
( X
p
+ 1)
2
+ a
2
( Y
p
- 1/ 2)
2
- a
2
b
2
I ni t i al Condi t i on:
I n r egi on R1, f i r st poi nt i s ( 0, b) .
Sw i t ch t o Regi on R2, w hen:
1/2) (Y a 1) (X b p p
2 2
> +
( d
i ni t
)
R1
= F( 1, b - 1/ 2) = b
2
+ a
2
( 1/ 4 - b) ;
Let t he l ast poi nt i n R1 be ( X
k
, Y
k
) .
F( M
2
) = F( X
k
+ 1/ 2, Y
k
- 1)
= b
2
( X
k
+ 1/ 2)
2
+ a
2
( Y
k
- 1)
2
- a
2
b
2
= ( d
i ni t
)
R2
Pr obl em w i t h a f r act i onal ( f l oat i ng poi nt ) v al ue
f or ( d
i ni t
)
R1
?
For choi ce SE ( d< 0) :
d
new
= F( X
K
+ 3/ 2, Y
k
- 2)
= b
2
( X
k
+ 3/ 2)
2
+ a
2
( Y
k
- 2)
2
- a
2
b
2
= d
ol d
+ b
2
( 2X
k
+ 2) + a
2
( - 2Y
k
+ 3) ;
Thus, ( Ad)
SE2
= b
2
( 2X
k
+ 2) + a
2
( - 2Y
k
+ 3) ;
For choi ce S ( d> 0) :
d
new
= F( X
K
+ 1/ 2, Y
k
- 2)
= b
2
( X
k
+ 1/ 2)
2
+ a
2
( Y
k
- 2)
2
- a
2
b
2
= d
ol d
+ a
2
( - 2Y
k
+ 3) ;
Thus, ( Ad)
S2
= a
2
( - 2Y
k
+ 3) ;
St op i t er at i on, w hen Y
k
= 0;
F( M
2
) = d
ol d
= F( X
k
+ 1/ 2, Y
k
- 1)
= b
2
( X
k
+ 1/ 2)
2
+ a
2
( Y
k
- 1)
2
- a
2
b
2
v oi d Mi dPoi nt El l i pse ( i nt a, i nt b, i nt v al ue) ;
{
doubl e d2; i nt X = 0; i nt Y = 0;
sa = sqr ( a) ; sb = sqr ( b) ;
doubl e d1 = sb sa* b + 0. 25* sa;
El l i psePoi nt s( X, Y, v al ue) ;
/ * 4- w ay sy mmet r i cal pi x el pl ot t i ng * /
w hi l e ( sa* ( Y - 0. 5) > sb* ( X + 1) )
/ * Regi on R1 * /
{ i f ( d1 < 0) / * Sel ect E * /
d1 + = sb* ( ( X< < 1) + 3) ;
el se / * Sel ect SE * /
{ d1 + = sb* ( ( X< < 1) + 3) + sa*
( - ( Y< < 1) + 2) ; Y- - ; }
X+ + ; El l i psePoi nt s( X, Y, v al ue) ;
}
doubl e d2 = sb* sqr ( X + 0. 5) +
sa* sqr ( Y - 1) - sa* sb;
w hi l e ( Y > 0) / * Regi on R2 * /
{ i f ( d2 < 0) / * Sel ect SE * /
{ d2 + = sb* ( ( X< < 1) + 2) +
sa* ( - ( Y< < 1) + 3) ;
X+ + ; }
el se / * Sel ect S * /
d2 + = sa* ( - ( Y< < 1) + 3) ;
Y- - ; El l i psePoi nt s( X, Y, v al ue) ;
}
}
I n some cases t he qual i t y of
t he pi ct ur e i s not sat i sf act or y

Vous aimerez peut-être aussi