<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Cicada's blog</title>
  <subtitle>cicada 的个人博客，记录技术与生活</subtitle>
  <link href="https://blog.cicadae.cloud/feed.xml" rel="self" />
  <link href="https://blog.cicadae.cloud" />
  <updated>2026-07-14T19:09:25.711Z</updated>
  <id>https://blog.cicadae.cloud/</id>
  <author>
    <name>cicada</name>
  </author>
  <entry>
    <title>C2 Triangle rasterization</title>
    <link href="https://blog.cicadae.cloud/blog/2026-02-06%20001"/>
    <id>https://blog.cicadae.cloud/blog/2026-02-06%20001</id>
    <published>2026-02-06T00:00:00.000Z</published>
    <updated>2026-02-06T00:00:00.000Z</updated>
    <summary>TinyRenderer学习：三角形栅格化</summary>
    <content type="html">&lt;h1&gt;三角形栅格化&lt;/h1&gt;
&lt;h2&gt;V1 扫描线算法&lt;/h2&gt;
&lt;p&gt;通过逐行扫描绘制三角形的方法，核心思想是&lt;br&gt;
&lt;strong&gt;三角形是”凸多边形“，将三角形切为上下两半&lt;/strong&gt;&lt;br&gt;
主要步骤如下：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;排序顶点（最低-最高），得到长边和短边&lt;/li&gt;
&lt;li&gt;短边由两条边组成，从其顶点水平切分三角形&lt;/li&gt;
&lt;li&gt;由扫描线的 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 坐标，确定扫描线的 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 的左右边界&lt;/li&gt;
&lt;li&gt;依次自底向上逐行绘制扫描线&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;代码如下：&lt;/p&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; triangle&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by) { &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx); &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by); }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy) { &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, cx); &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, cy); }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy) { &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, cx); &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by, cy); }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_h &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;    // 下半部分&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; seg_h &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ac_x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (cx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_h;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ab_x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; seg_h;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ac_x, ab_x); x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ac_x, ab_x); x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;                framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;    // 上半部分&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; seg_h &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ac_x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (cx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_h;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bc_x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (cx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; seg_h;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ac_x, bc_x); x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ac_x, bc_x); x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;                framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;27&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;28&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;29&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;30&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;h2&gt;V2 现代化方法&lt;/h2&gt;
&lt;p&gt;通过确认每点是否处于三角形内部，从而进行填充的方法。&lt;br&gt;
&lt;strong&gt;核心思想是重心坐标的运用，在下一章详细展开&lt;/strong&gt;&lt;br&gt;
具体步骤如下：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;找到三角形的包围盒（bounding box)
&lt;ul&gt;
&lt;li&gt;由&lt;mark&gt;左下角&lt;/mark&gt;和&lt;mark&gt;右下角&lt;/mark&gt;控制&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;对包围盒中的所有点，检查其是否处于三角形内部
&lt;ul&gt;
&lt;li&gt;若处于，则在此像素点位置填充颜色&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;这里的每个像素点都是单独处理的，因此这是一种便于&lt;strong&gt;并行计算&lt;/strong&gt;的方法。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;代码如下：&lt;/p&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 现代栅格化算法&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@note&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 便于并行计算&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; cx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; cy&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; triangle&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;    /* 左下角坐标 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbminx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, cx));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbminy &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by, cy));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;    /* 右上角坐标 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbmaxx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, cx));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbmaxy &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, &lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by, cy));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    double&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_area &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; get_signed_area&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, ay, bx, by, cx, cy);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbminx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbmaxx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbminy; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bbmaxy; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            double&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; alpha &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; get_signed_area&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, bx, by, cx, cy) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_area;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            double&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; beta &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; get_signed_area&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, cx, cy, ax, ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_area;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;27&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;            double&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; gamma &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; get_signed_area&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, ax, ay, bx, by) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; tot_area;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;28&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;29&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(alpha &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; beta &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; gamma &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;30&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;31&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;32&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;33&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;h3&gt;重心坐标的计算&lt;/h3&gt;
&lt;p&gt;有很多方法可以检查一个点/像素是否属于三角形内部。&lt;br&gt;
这里选择&lt;strong&gt;重心坐标（barycentric coordinates）&lt;/strong&gt;，因其对后续处理的帮助很大。&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;在三角形的语境中，重心坐标也称为&lt;strong&gt;面积坐标&lt;/strong&gt;或&lt;strong&gt;面坐标&lt;/strong&gt; ，因为点 P 相对于三角形 &lt;em&gt;ABC&lt;/em&gt; 的坐标等价于 &lt;em&gt;PBC&lt;/em&gt; 、 &lt;em&gt;PCA&lt;/em&gt; 和 &lt;em&gt;PAB&lt;/em&gt; 的面积与参考三角形 &lt;em&gt;ABC&lt;/em&gt; 面积的（有符号）比值。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;每个三角形 ABC 都有一个&lt;mark&gt;带符号的面积值&lt;/mark&gt; ，即正负其面积：&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo&gt;±&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;sarea(ABC)= \pm area(ABC)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;±&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
如果沿三角形&lt;mark&gt;逆时针&lt;/mark&gt;方向绕行，则符号为正；如果沿三角形顺时针方向绕行，则符号为负。&lt;/p&gt;
&lt;p&gt;设 P 为平面上的一个点，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;(λ_1,λ_2,λ_3)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 为其相对于三角形 ABC 的&lt;mark&gt;归一化重心坐标&lt;/mark&gt; ，则&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;P = λ_1 A + λ_2 B + λ_3 C&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;λ_1  + λ_2  + λ_3 = 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
归一化重心坐标也称为面积坐标 ，因为它们表示三角形有符号面积的比率：&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;/&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;λ_1 = sarea(PBC) / sarea(ABC)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;/&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;λ_2 = sarea(APC) / sarea(ABC)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;λ&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;/&lt;/mi&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;λ_3 = sarea(ABP) / sarea(ABC)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8444em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.1389em;&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mopen&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0502em;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0715em;&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;mclose&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;面积的计算&lt;/h3&gt;
&lt;p&gt;这里运用的是&lt;mark&gt;鞋带公式 / 高斯面积公式（Shoelace formula）&lt;/mark&gt;对三角形的面积进行计算：&lt;/p&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 鞋带公式求三角形面积&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@note&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 逆时针求解面积，一般为正&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; cx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; cy&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@return&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; double 三角形有向面积&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;double&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; get_signed_area&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0.5&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ((by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (cy &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (cx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cy) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; cx));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;</content>
<category term="图形学"/>
  </entry>
  <entry>
    <title> C1 Bresenham's line drawing</title>
    <link href="https://blog.cicadae.cloud/blog/2026-01-13%20001"/>
    <id>https://blog.cicadae.cloud/blog/2026-01-13%20001</id>
    <published>2026-01-13T00:00:00.000Z</published>
    <updated>2026-01-13T00:00:00.000Z</updated>
    <summary>TinyRenderer学习：关于画线算法</summary>
    <content type="html">&lt;h2&gt;V1 朴素插值法算法&lt;/h2&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 朴素参数插值法画线&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;0.&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;; t&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;1.&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;; t&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;.02&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;( ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (bx&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;ax)&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;t );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;( ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (by&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;ay)&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;t );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;当 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;t = 0&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6151em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 时，点在起点；当 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;t&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;t = 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6151em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 时，点在终点；&lt;br&gt;
代码硬编码步长为0.02，说明&lt;strong&gt;固定采样50/51个点&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;缺点&lt;/strong&gt;：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;长线会有“断点”，变成虚线形式。&lt;/li&gt;
&lt;li&gt;短线会导致过于密集。&lt;/li&gt;
&lt;li&gt;浮点数运算浪费性能。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713231958522.png&quot; data-action=&quot;preview&quot; data-fslightbox=&quot;2026-01-13 001&quot;&gt;&lt;img src=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713231958522.png&quot; alt=&quot;&quot; class=&quot;img-center&quot; style=&quot;&quot; width=&quot;200&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;V1.1 改进：采取不同的采样策略&lt;/h3&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 朴素参数插值法画线：步长改进&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;   // ltr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        float&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; static_cast&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; t);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;改进：
&lt;ul&gt;
&lt;li&gt;不再固定步长，可以比较合理的取样&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;缺陷：
&lt;ul&gt;
&lt;li&gt;不适用于&lt;strong&gt;陡峭&lt;/strong&gt;的线，会导致线的断裂甚至程序崩溃（除以0）&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232239326.png&quot; data-action=&quot;preview&quot; data-fslightbox=&quot;2026-01-13 001&quot;&gt;&lt;img src=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232239326.png&quot; alt=&quot;&quot; class=&quot;img-center&quot; style=&quot;&quot; width=&quot;200&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;V1.2 改进：识别陡峭部分&lt;/h3&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; 朴素参数插值法画线：步长改进 + 陡峭翻转&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(isSteep) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, ay);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;   // ltr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        float&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; static_cast&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;        int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; t);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(y, x, color) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;优点&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;解决了之前的所有痛点&lt;br&gt;
&lt;strong&gt;缺陷&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;性能瓶颈：循环体内部包含除法 / 浮点乘法 / 浮点加法 / 取整函数&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;V2 DDA 算法&lt;/h2&gt;
&lt;p&gt;DDA：digital differential analyzer&lt;br&gt;
基于直线的微分方程来生成直线的方法&lt;/p&gt;
&lt;p&gt;直线斜率：&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;m&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;−&lt;/mo&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;m = \frac{y2-y1}{x2-x1} = \frac{dy}{dx}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.3005em;vertical-align:-0.4033em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8972em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mbin mtight&quot;&gt;−&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.4033em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2772em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9322em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;通过 &lt;code&gt;V1.2&lt;/code&gt; 的式子，可以看出&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;初始时，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x_0 = ax&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5806em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y_0 = ay&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;，还未开始循环步进/采样&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mtext&gt;，&lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x_1 = ax + 1，y_1 = y_0 + \frac{dy}{dx}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5806em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;mord cjk_fallback&quot;&gt;，&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2772em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9322em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mtext&gt;，&lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x_2 = ax + 2，y_2 = y_1 + \frac{dy}{dx}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5806em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord cjk_fallback&quot;&gt;，&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2772em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9322em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mtext&gt;，&lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x_3 = ax + 3，y_3 = y_2 + \frac{dy}{dx}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5806em;vertical-align:-0.15em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:0em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6667em;vertical-align:-0.0833em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;mord cjk_fallback&quot;&gt;，&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.7778em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;msupsub&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.3011em;&quot;&gt;&lt;span style=&quot;top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:2.7em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.15em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mbin&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2222em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2772em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9322em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\dots&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.123em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;minner&quot;&gt;…&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;观察 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 的序列，可以将 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;v&lt;/mi&gt;&lt;mn&gt;1.2&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;v1.2&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1.2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 优化为如下算法：&lt;/p&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; DDA法&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(isSteep) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, ay);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;   // ltr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    float&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(y, x, color) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; static_cast&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax);&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;   // 每次x进，y就增斜率量&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;p&gt;效果如下：&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232321842.png&quot; data-action=&quot;preview&quot; data-fslightbox=&quot;2026-01-13 001&quot;&gt;&lt;img src=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232321842.png&quot; alt=&quot;&quot; class=&quot;img-center&quot; style=&quot;&quot; width=&quot;200&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;优点&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;易理解&lt;/li&gt;
&lt;li&gt;速度快&lt;/li&gt;
&lt;li&gt;化除为加&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;缺陷&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;目前每轮循环还是包含除法（编译器可以优化）&lt;/li&gt;
&lt;li&gt;没有解决浮点数计算的问题，对硬件不友好（还引入了&lt;code&gt;float y&lt;/code&gt; )&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;V3 Bresenham 算法&lt;/h2&gt;
&lt;p&gt;前面所做的积累&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;依照直线调整步长，而非固定步长&lt;/li&gt;
&lt;li&gt;&lt;mark&gt;只做平缓直线的绘制（陡峭情形化归到平缓）&lt;/mark&gt;&lt;/li&gt;
&lt;li&gt;循环除法 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo&gt;→&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\to&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.3669em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;→&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 累加法&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;注意第2点，我们总是做平缓情形，这说明直线的斜率有&lt;br&gt;
&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mi&gt;k&lt;/mi&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∣&lt;/mi&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;|k| \leq 1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1em;vertical-align:-0.25em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0315em;&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;∣&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;≤&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
这说明在主循环中，&lt;strong&gt;我们每当对 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 做累加操作时，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 的增量总不会超过 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;由于我们要求的 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x, y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;mpunct&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.1667em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 坐标皆为&lt;strong&gt;整数&lt;/strong&gt;，所以没有必要在 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;x&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 累加时，通过直线方程去计算 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 的坐标（因为这个结果通常是&lt;strong&gt;浮点数&lt;/strong&gt;），我们引入一个 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;e&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;e&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 来记录每一像素点与目标直线的误差（&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 值）。&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;每当x的值增加1，误差的值就会增加斜率的值 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\frac{dx}{dy}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.3612em;vertical-align:-0.4811em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.8801em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.394em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.4811em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br&gt;
每当误差的值超出0.5，线就会比较靠近下一个点，因此y的值便会加1，且误差减1。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;代码如下：&lt;/p&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; Bresenham法&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; steep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (steep) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; // if the line is steep, we transpose the image&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, ay);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (ax&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;bx) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; // make it left−to−right&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    float&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; error &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;ax; x&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;bx; x&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (steep)&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; // if transposed, de−transpose&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(y, x, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;27&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;28&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        error &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;ay)&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;/static_cast&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;ax);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;29&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (error&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;.5&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;30&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;31&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            error &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 1.&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;32&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;33&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;34&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;p&gt;上述是算法原理可理解性的代码，实际上可以去除浮点数，得到整数形式的算法，代码如下：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;浮点数形式
&lt;ul&gt;
&lt;li&gt;判定 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;&gt;&lt;/mo&gt;&lt;mn&gt;0.5&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;error \gt 0.5&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.5782em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;0.5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;每轮循环 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;error&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;code&gt;+=&lt;/code&gt; &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mfrac&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;/mfrac&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\frac{dy}{dx}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:1.2772em;vertical-align:-0.345em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;&lt;span class=&quot;mopen nulldelimiter&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mfrac&quot;&gt;&lt;span class=&quot;vlist-t vlist-t2&quot;&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.9322em;&quot;&gt;&lt;span style=&quot;top:-2.655em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.23em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;frac-line&quot; style=&quot;border-bottom-width:0.04em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;top:-3.4461em;&quot;&gt;&lt;span class=&quot;pstrut&quot; style=&quot;height:3em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sizing reset-size6 size3 mtight&quot;&gt;&lt;span class=&quot;mord mtight&quot;&gt;&lt;span class=&quot;mord mathnormal mtight&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal mtight&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-s&quot;&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;vlist-r&quot;&gt;&lt;span class=&quot;vlist&quot; style=&quot;height:0.345em;&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;mclose nulldelimiter&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;更新 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 时，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;error&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.4306em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;code&gt;-=&lt;/code&gt; &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;1&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6444em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;整数形式
&lt;ul&gt;
&lt;li&gt;判定 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;&gt;&lt;/mo&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;ierror \gt dy&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6986em;vertical-align:-0.0391em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mrel&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;mspace&quot; style=&quot;margin-right:0.2778em;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;每轮循环 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;ierror&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6595em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;code&gt;+=&lt;/code&gt; &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;2dy&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.8889em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;更新 &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;y&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;y&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.625em;vertical-align:-0.1944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0359em;&quot;&gt;y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; 时，&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;e&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mi&gt;o&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;ierror&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6595em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;er&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot; style=&quot;margin-right:0.0278em;&quot;&gt;or&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;code&gt;-=&lt;/code&gt; &lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mi&gt;x&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;2dx&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;span class=&quot;katex-html&quot; aria-hidden=&quot;true&quot;&gt;&lt;span class=&quot;base&quot;&gt;&lt;span class=&quot;strut&quot; style=&quot;height:0.6944em;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;mord&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;mord mathnormal&quot;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;pre-wrapper&quot;&gt;&lt;pre class=&quot;shiki shiki-themes everforest-dark everforest-dark&quot; style=&quot;background-color:#2d353b;--shiki-dark-bg:#2d353b;color:#d3c6aa;--shiki-dark:#d3c6aa&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot; data-line=&quot;1&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;/**&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;2&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@brief&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; Bresenham法&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;3&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;4&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ax&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;5&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; ay&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;6&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; bx&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;7&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; by&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;8&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;9&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; * &lt;/span&gt;&lt;span style=&quot;color:#E67E80;--shiki-light-font-style:italic;--shiki-dark:#E67E80;--shiki-dark-font-style:italic&quot;&gt;@param&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-light-font-style:italic;--shiki-dark:#D3C6AA;--shiki-dark-font-style:italic&quot;&gt; color&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;10&quot;&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt; */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;11&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt; line&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAImage&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; &amp;#x26;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;framebuffer,&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt; TGAColor&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; color)&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;12&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    bool&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;13&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(isSteep) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;14&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, ay);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;15&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(bx, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;16&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;17&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx) {&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-light-font-style:italic;--shiki-dark:#859289;--shiki-dark-font-style:italic&quot;&gt;   // ltr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;18&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ax, bx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;19&quot;&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt;        std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;swap&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ay, by);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;20&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;21&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;22&quot;&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ierror &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;23&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#7FBBB3;--shiki-dark:#7FBBB3&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx; x &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;24&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        isSteep &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(y, x, color) &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; framebuffer&lt;/span&gt;&lt;span style=&quot;color:#859289;--shiki-dark:#859289&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(x, y, color);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;25&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        ierror &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#83C092;--shiki-dark:#83C092&quot;&gt; std&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#A7C080;--shiki-dark:#A7C080&quot;&gt;abs&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;26&quot;&gt;&lt;span style=&quot;color:#E67E80;--shiki-dark:#E67E80&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;(ierror &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;27&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            y &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; by &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ay &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;28&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;            ierror &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color:#D699B6;--shiki-dark:#D699B6&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; (bx &lt;/span&gt;&lt;span style=&quot;color:#E69875;--shiki-dark:#E69875&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt; ax);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;29&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;30&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot; data-line=&quot;31&quot;&gt;&lt;span style=&quot;color:#D3C6AA;--shiki-dark:#D3C6AA&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;button class=&quot;copy-btn&quot; data-action=&quot;copy&quot;&gt;复制&lt;/button&gt;&lt;/div&gt;
&lt;p&gt;这是我们最终使用的画线算法。效果如下：&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232401824.png&quot; data-action=&quot;preview&quot; data-fslightbox=&quot;2026-01-13 001&quot;&gt;&lt;img src=&quot;https://cdn.jsdelivr.net/gh/D1rection/img@main/images/20260713232401824.png&quot; alt=&quot;&quot; class=&quot;img-center&quot; style=&quot;&quot; width=&quot;200&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content>
<category term="图形学"/>
  </entry>
</feed>