⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.3.2 扫描线填色算法.htm

📁 计算机图形学教程计算机图形学教程
💻 HTM
📖 第 1 页 / 共 3 页
字号:
    face=Arial>        update-_sides_list ( 
    );</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp; }</FONT></P></BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>}</FONT></P></BLOCKQUOTE>
<BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>void put_in_sides_list(entry, x1, y1, x2, y2, next_y);</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>int entry, x1, y1, x2, y2, next_y;</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>{</FONT></P>
  <BLOCKQUOTE>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>int maxy;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>float x2_temp, x_change_temp;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>x_change_temp = (float) (x2-x1) / (float) (y2-y1);</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>x2_temp =x2; /*</FONT>以下为退缩一点操作<FONT face=Arial>. */</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>if ((y2&gt;y1) &amp;&amp; (y2&lt;next_y)) {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y2 - - 
    ;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x2_temp - 
    = x_change_temp;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>else {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
    ((y2&lt;y1) &amp;&amp; (y2 &gt;next_y)) {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    y2++;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    x2_temp+=x_change_temp;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>/* </FONT>以下为插入活性表操作<FONT face=Arial>. */</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>maxy = (y1 &gt; y2)? y1: y2;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>while (( entry &gt;1) &amp;&amp; (maxy &gt; sides [entry -1]. 
    y_top))</FONT> </P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    sides[entry]=sides [entry ?];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    entry - -;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>sides[entry]. y_top=maxy;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>sides[entry]. delta_y =abs(y2-y1)+1;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>if (y1&gt;y2)</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    sides[entry]. x_int =x1;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>else{</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    sides[entry].x_int=x2_temp;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    sides[entry]. x_change_per_scan=x_change_temp;</FONT></P></BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>&nbsp;&nbsp; }</FONT></P></BLOCKQUOTE>
<BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>void sort_on_bigger_y(n)</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>int n;</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>{</FONT></P>
  <BLOCKQUOTE>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>int k, x1, y1;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>side_count=0;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>y1=y[n];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>x1=x[n];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>bottomscan=y[n];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify> </P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>for (k=1; k&lt;n+1; k++)</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp; {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
    (y1 ! =y[k]) {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; side_count 
    ++;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    put_in_sides_list(side_count, x1, y1, x[k], y[k]);</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else 
    {</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    move ((short)x1, (short)y1);</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    line((short)x[k], (short)y1, status);</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    }</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
    (y[k] &lt;bottomscan) bottomscan=y[k];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    y1=y[k]; x1=x[k];</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT></P></BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>}</FONT></P></BLOCKQUOTE>
<BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>void update_first_and_last(count, scan)</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>int count, scan;</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>{</FONT></P>
  <BLOCKQUOTE>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>while((sides[last_s+1]. y_top&gt;=scan) &amp;&amp; (last_s 
    &lt;count)) last_s ++;</FONT></P>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>while(sides[first_s]. delta_y = = 0) first_s 
  ++;</FONT></P></BLOCKQUOTE>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>}</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify> </P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>void swap(x, y)</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>EACH_ENTRY x, y;</FONT></P>
  <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
  face=Arial>{</FONT></P>
  <BLOCKQUOTE>
    <P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" align=justify><FONT 
    face=Arial>int i_temp;</FONT></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -