📄
字号:
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>2</span></sub>为下一个象素;</p>
<p style='line-height:200%'><span lang=EN-US> 当</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>d></span></i><span
lang=EN-US>0时,</span><i><span lang=EN-US style='font-family:"Times New Roman"'>M</span></i>在<i><span
lang=EN-US style='font-family:"Times New Roman"'>L</span></i><span lang=EN-US>(</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>Q</span></i>点<span lang=EN-US>)上方,取</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>1</span></sub>为下一个象素;</p>
<p style='line-height:200%'><span lang=EN-US> 当</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>d=</span></i><span lang=EN-US>0时,选</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>1</span></sub>或<i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>2</span></sub>均可,约定取<i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>1</span></sub>为下一个象素;</p>
<p style='line-height:200%'>注意到<i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i>是<i><span
lang=EN-US style='font-family:"Times New Roman"'>x</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i>的线性函数,可采用增量计算,提高运算效率。</p>
<p style='line-height:200%'><span lang=EN-US> 若当前象素处于</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>d</span></i><span lang=EN-US
style='font-family:Symbol'>³</span><span lang=EN-US>0情况,则取正右方象素</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>1</span></sub><span
lang=EN-US style='font-family:"Times New Roman"'>(<i>x</i></span><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+1, y</span><i><sub><span lang=EN-US style='mso-bidi-font-size:10.0pt;
font-family:"Times New Roman"'>p</span></sub></i><span lang=EN-US>),要判下一个象素位置,应计算
</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>1</span></sub><span
lang=EN-US>=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>F</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+2, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+0.5)=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+2)+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>b</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+0.5)=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><span
lang=EN-US>+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i>,增量为<i><span
lang=EN-US style='font-family:"Times New Roman"'>a</span></i>。</p>
<p style='line-height:200%'><span lang=EN-US> 若</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>d</span></i><span lang=EN-US><0时,则取右上方象素</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>P</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>2</span></sub><span
lang=EN-US style='font-family:"Times New Roman"'>(<i>x</i></span><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+1, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+1)。要判断再下一象素,则要计算</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>2</span></sub><span
lang=EN-US>= </span><i><span lang=EN-US style='font-family:"Times New Roman"'>F</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+2, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+1.5)=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+2)+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>b</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>p</span></sub></i><span
lang=EN-US>+1.5)+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>c</span></i><span
lang=EN-US>=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><span
lang=EN-US>+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i><span
lang=EN-US>+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>b </span></i>,增量为<i><span
lang=EN-US style='font-family:"Times New Roman"'>a</span></i>+<i><span
lang=EN-US style='font-family:"Times New Roman"'>b</span></i>。画线从<span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>)开始,</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i>的初值
<i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>F</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>+1, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>+0.5)=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>F</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>)+</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i><span
lang=EN-US>+0.5</span><i><span lang=EN-US style='font-family:"Times New Roman"'>b</span>,</i>因<i><span
lang=EN-US style='font-family:"Times New Roman"'> F</span></i><span
lang=EN-US>(</span><i><span lang=EN-US style='font-family:"Times New Roman"'>x</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>, </span><i><span lang=EN-US style='font-family:"Times New Roman"'>y</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>)=0,所以</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i><sub><span
lang=EN-US style='mso-bidi-font-size:10.0pt;font-family:"Times New Roman"'>0</span></sub><span
lang=EN-US>=</span><i><span lang=EN-US style='font-family:"Times New Roman"'>a</span></i><span
lang=EN-US>+0.5</span><i><span lang=EN-US style='font-family:"Times New Roman"'>b</span></i>。</p>
<p style='line-height:200%'><span lang=EN-US> 由于我们使用的只是</span><i><span
lang=EN-US style='font-family:"Times New Roman"'>d</span></i>的符号,而且<i><span
lang=EN-US style='font-family:"Times New Roman"'>d</span></i>的增量都是整数,只是初始值包含小数。因此,我们可以用<span
lang=EN-US>2</span><i><span lang=EN-US style='font-family:"Times New Roman"'>d</span></i>代替<i><span
lang=EN-US style='font-family:"Times New Roman"'>d</span></i>来摆脱小数,写出仅包含整数运算的算法程序。</p>
<p style='line-height:200%'><span lang=EN-US style='color:navy'><!--[if gte vml 1]><v:shape
id="_x0000_i1051" type="#_x0000_t75" alt="" style='width:10.5pt;height:10.5pt'>
<v:imagedata src="./第二章%20光栅图形学.files/image004.gif" o:href="http://learn.bitsde.com/hep/jisuanjituxing/material/CG_Gif_pub_031.gif"/>
</v:shape><![endif]--><![if !vml]><img border=0 width=14 height=14
src="./第二章%20光栅图形学.files/image004.gif" v:shapes="_x0000_i1051"><![endif]></span><span
style='font-size:10.0pt;color:navy'>中点画线算法程序:</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'>void Midpoint Line
(int x0,int y0,int x1, int y1,int color)</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'>{ int a, b, d1, d2,
d, x, y;</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> a=y0-y1;
b=x1-x0;d=2*a+b;</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> d1=2*a;d2=2*
(a+b);</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> x=x0;y=y0;</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> drawpixel(x,
y, color);</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> while
(x<x1)</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> { if
(d<0) {x++;y++; d+=d2; }</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'>
else {x++; d+=d1;}</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'>
drawpixel (x, y, color);</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'> } /* while
*/</span></p>
<p style='margin-top:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:
0cm'><span lang=EN-US style='font-size:10.0pt;color:purple'>} /* mid PointLine
*/</span></p>
<p><span lang=EN-US style='font-size:10.0pt;color:#006666'><!--[if gte vml 1]><v:shape
id="_x0000_i1052" type="#_x0000_t75" alt="" style='width:10.5pt;height:10.5pt'>
<v:imagedata src="./第二章%20光栅图形学.files/image005.gif" o:href="http://learn.bitsde.com/hep/jisuanjituxing/material/CG_Gif_pub_032.gif"/>
</v:shape><![endif]--><![if !vml]><img border=0 width=14 height=14
src="./第二章%20光栅图形学.files/image005.gif" v:shapes="_x0000_i1052"><![endif]></span><span
style='color:#006666'>举例:用中点画线方法扫描转换连接两点<span lang=EN-US>P0(0,0)和P1(5,2)的直线段。</span></span></p>
<p><span lang=EN-US style='font-size:10.0pt'>a=y0-y1=-2; b=x1-x0=5; d0=2*a+b=1;d1=2*a=-4;d2=2*(a+b)=6
,</span></p>
<p><!--[if gte vml 1]><v:shape id="_x0000_s1027" type="#_x0000_t75" alt=""
style='position:absolute;margin-left:165.5pt;margin-top:0;width:205.5pt;
height:126pt;z-index:2;mso-wrap-distance-left:0;mso-wrap-distance-right:0;
mso-position-horizontal:right;mso-position-vertical-relative:line'
o:allowoverlap="f">
<v:imagedata src="./第二章%20光栅图形学.files/image010.png" o:title="CG_Gif_2_003"/>
<w:wrap type="square"/>
</v:shape><![endif]--><![if !vml]><img width=274 height=168
src="./第二章%20光栅图形学.files/image011.gif" align=right v:shapes="_x0000_s1027"><![endif]><span
lang=EN-US style='font-size:10.0pt'>x y d </span></p>
<p><span lang=EN-US style='font-size:10.0pt'>0 0 1 </span></p>
<p><span lang=EN-US style='font-size:10.0pt'>1 0 -3</span></p>
<p><span lang=EN-US style='font-size:10.0pt'>2 1 3 </span></p>
<p><span lang=EN-US style='font-size:10.0pt'>3 1
-1 </span></p>
<p><span lang=EN-US style='font-size:10.0pt'>4 2
5 &n
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -