# 布雷森汉姆直线算法

**布雷森汉姆直线算法**（Bresenham's line algorithm）是一种在离散网格（如绘图仪台面或像素显示器）上绘制直线的方法，每一步只使用整数加法、减法和比较运算。它维护一个运行中的误差项，记录所选网格点偏离理想数学直线的程度，并依据该误差项的符号来决定下一步在两个相邻网格点中绘制哪一个。<sup>[1](https://unseel.com/cs/bresenham-line)</sup> 杰克·埃尔顿·布雷森汉姆（Jack Elton Bresenham）于1965年在《IBM系统期刊》上以《数字绘图仪计算机控制算法》为题发表了该算法。<sup>[2](https://dblp.org/rec/journals/ibmsj/Bresenham65.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 原始发表 | J. E. Bresenham，《数字绘图仪计算机控制算法》，《IBM系统期刊》4(1)：25–30，1965，DOI 10.1147/sj.41.0025<sup>[2](https://dblp.org/rec/journals/ibmsj/Bresenham65.html)</sup><sup> • </sup><sup>[3](https://cir.nii.ac.jp/crid/1360574095645461376)</sup> |
| 首次报告 | ACM全国会议，科罗拉多州丹佛，1963年8月30日，题为《一种用于数字绘图的增量算法》<sup>[4](https://janmr.com/files/papers/bresenham65.pdf)</sup> |
| 算术运算 | 无需乘法或除法指令即可编程实现；在速度和内存使用上均高效<sup>[5](https://ibm-1401.info/Pics3/bresenham1965.pdf)</sup> |
| 原始硬件环境 | IBM 1401驱动IBM圣何塞的一台11英寸Calcomp 565滚筒绘图仪，至1962年已在使用<sup>[6](https://ibm1401.computerhistory.org/BresenhamLineDraw.html)</sup> |
| 绘图仪模型 | 能够在方形网格相邻点之间执行八种线性运动的设备，典型网格尺寸为1/100英寸<sup>[5](https://ibm-1401.info/Pics3/bresenham1965.pdf)</sup> |
| 报告性能 | 相邻增量之间的计算时间约为1.5毫秒，而功能相似的已发表算法需要513个磁芯存储位置和2.4毫秒<sup>[4](https://janmr.com/files/papers/bresenham65.pdf)</sup> |
| 现代用途 | 常用于图形硬件，因为整数运算比浮点运算所需硬件更少，且不引入舍入误差<sup>[7](https://courses.physics.illinois.edu/cs418/fa2022/text/dda.html)</sup> |

## 所解决的问题

数字显示器或绘图仪只能在离散的网格位置上放置标记，而数学直线经过的点的坐标通常不是整数。任何有限的像素网格都无法精确再现任意连续直线，因此任务是在有界视觉误差下一致地选取离散样本，而非追求精确的几何等同。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup> 工程问题是：沿主轴每前进一步时，应选择哪个相邻网格位置，才能使绘制的路径最接近理想直线。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup>

直接方法通过乘法和舍入为每个x计算分数y坐标。布雷森汉姆的洞见在于用增量误差递推取代这种重复的几何计算：一旦第一个决策值已知，下一个决策值仅通过加法和减法即可从前一个值推出。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup> 误差是实际绘制的整数y坐标与该x处数学完美直线的y坐标之差；当累积误差达到半个单位时，算法将y前进一格并从误差中减去一，这等价于舍入到最近的网格点。<sup>[9](https://www.teach.cs.toronto.edu/~ajr/104/diary/06/bres/)</sup>

## 起源与发表历史

布雷森汉姆于1962年至1967年在IBM圣何塞的尤金·林斯特伦（Eugene Lindstrom）博士的计算实验室工作期间开发了该例程。实验室的IBM 1401作为7090的输入输出假脱机设备，来自7094的工程计算曲线以磁带上的数字列形式送达，绘制在11英寸Calcomp 565滚筒绘图仪上。布雷森汉姆回忆说，该直线例程至1962年已在使用。<sup>[6](https://ibm1401.computerhistory.org/BresenhamLineDraw.html)</sup>

发表顺序从部署代码到会议再到期刊。布雷森汉姆于1963年8月30日在丹佛的1963年ACM全国会议上以《一种用于数字绘图的增量算法》为题报告了该工作，随后于1965年在《IBM系统期刊》上发表论文。<sup>[4](https://janmr.com/files/papers/bresenham65.pdf)</sup><sup> • </sup><sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup> 据1965年的论文，该算法无需任何乘法或除法指令即可实现，且在执行速度和内存占用方面均表现良好。<sup>[5](https://ibm-1401.info/Pics3/bresenham1965.pdf)</sup>

原始公式受到绘图仪本身的塑造，绘图仪可响应脉冲从网格点向相邻点执行八种线性运动中的任意一种。<sup>[5](https://ibm-1401.info/Pics3/bresenham1965.pdf)</sup> 因此算法的每一步选择一个相邻位置，决策变量使由此产生的步进链保持在理想直线附近。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup>

## 算法工作原理

基本推导考虑单个八分圆，例如斜率在零到一之间的正斜率直线，其中x每步前进一格，y有时前进。坐标交换、符号变更和端点处理将同一递推扩展到其余方向，因此一条增量规则覆盖所有斜率。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup> 对于从(1,1)到(8,5)的直线，斜率为4/7，因此精确绘制时每单位x应向y加4/7；算法改为在误差项中累积该分数，仅当累积误差越过舍入阈值时才步进y。<sup>[9](https://www.teach.cs.toronto.edu/~ajr/104/diary/06/bres/)</sup>

布雷森汉姆推导该方法时并非将其视为数字微分分析仪（DDA）的变体——DDA是一种使用浮点斜率值沿直线步进的增量技术——而是通过考虑直线的隐式方程得出的。<sup>[7](https://courses.physics.illinois.edu/cs418/fa2022/text/dda.html)</sup> 两种方法产生相同的像素结果，但布雷森汉姆的版本仅使用整数值，这使其更快，因为整数运算比浮点运算所需硬件更少，也更精确，因为不引入舍入误差。它适用于整数、有理数和定点端点及输出，因此常用于图形硬件；代码不如DDA直观，但产生更简单、更小的电路，所需晶体管少得多。<sup>[7](https://courses.physics.illinois.edu/cs418/fa2022/text/dda.html)</sup>

在1965年论文自身的性能比较中，目标机器上相邻增量之间的平均计算时间约为1.5毫秒，而F. G. Stockton发表的功能相似的算法被描述为需要513个磁芯存储位置，相邻增量之间的计算时间为2.4毫秒。<sup>[4](https://janmr.com/files/papers/bresenham65.pdf)</sup>

## 扩展

布雷森汉姆本人展示了如何将该方法用于绘制其他曲线，包括圆，方法是将同样的增量决策思想应用于曲线的隐式方程；这些推广适合硬件实现，但通常不在硬件中实现。<sup>[7](https://courses.physics.illinois.edu/cs418/fa2022/text/dda.html)</sup> 该算法还可扩展到三维及更高维度。Chi Kit Au和Tony Woo于2010年发表在《计算机辅助设计》上的研究将二维中点比较推广为基于直线与网格点之间最小距离的规则，候选点按Voronoi图的结构组织——Voronoi图将空间划分为若干区域，每个区域由距某个网格点最近的点组成；作者指出直接对二维选择数进行“平方”会遇到困难，他们研究整数运算和对称性以保持三维版本的高效。<sup>[10](https://researchcommons.waikato.ac.nz/items/0cbe9c6b-7c77-4cd0-a720-02975bb0d209)</sup> 简单的三维实现为每个轴运行一个误差累加器，与最大坐标差比较，已发表的代码将同一模式扩展到四维、五维和六维。<sup>[11](https://github.com/zingl/Bresenham)</sup><sup> • </sup><sup>[12](https://www.crisluengo.net/archives/400/)</sup> 三维形式也已直接在FPGA硬件中实现用于扫描转换，其中整数x和y值寻址帧缓冲，计算出的z值支持深度缓冲隐藏面消除。<sup>[13](https://tj-es.com/ojs/index.php/tjes/article/download/398/409)</sup>

## 局限与替代方案

该算法产生硬边缘、有锯齿的直线：每步选择一个像素，不混合强度。从业者对于粗线或纹理线也会跳过布雷森汉姆算法，转而将其光栅化为四边形；在现代GPU上也是如此，因为光栅化器并行地在整个图块上评估边缘函数，而非遵循严格的顺序递推。<sup>[1](https://unseel.com/cs/bresenham-line)</sup>

## 意义

布雷森汉姆并未发明数学直线或数字绘图仪；他的贡献是一种从连续几何到离散设备步进的经济映射，表达为适合其时代机器的增量递推——在那个时代，乘法和除法代价高昂。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup> 计算机历史博物馆的早期计算机辅助设计研讨班将该方法认定为该领域的一项基础性使能技术。<sup>[8](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)</sup>

## References

1. [Bresenham's Line Algorithm — Integer-Only Line Rasterization, Unseel](https://unseel.com/cs/bresenham-line)
2. [Jack Bresenham (1965). "Algorithm for Computer Control of a Digital Plotter," IBM Syst. J. 4(1): 25–30, dblp record](https://dblp.org/rec/journals/ibmsj/Bresenham65.html)
3. [Algorithm for computer control of a digital plotter, CiNii Research](https://cir.nii.ac.jp/crid/1360574095645461376)
4. [J. E. Bresenham (1965). "An algorithm is given for computer control of a digital plotter," PDF scan](https://janmr.com/files/papers/bresenham65.pdf)
5. [J. E. Bresenham (1965). "Algorithm for computer control of a digital plotter," IBM Systems Journal, PDF via ibm-1401.info](https://ibm-1401.info/Pics3/bresenham1965.pdf)
6. [Bresenham Line Drawing Algorithm, IBM 1401 / Computer History Museum community archive](https://ibm1401.computerhistory.org/BresenhamLineDraw.html)
7. [CS 418 — DDA (and Bresenham), University of Illinois](https://courses.physics.illinois.edu/cs418/fa2022/text/dda.html)
8. [Jack Bresenham and the Line Drawing Algorithm, CodeHistory](https://www.codehistory.org/computer-graphics-games-visual-computing/jack-bresenham-line-algorithm-raster-graphics/)
9. [The Bresenham line algorithm, University of Toronto course notes](https://www.teach.cs.toronto.edu/~ajr/104/diary/06/bres/)
10. [Au, C.K. & Woo, T. (2010). "Three dimensional extension of Bresenham's algorithm with Voronoi diagram," Computer-Aided Design, University of Waikato repository](https://researchcommons.waikato.ac.nz/items/0cbe9c6b-7c77-4cd0-a720-02975bb0d209)
11. [zingl/Bresenham: implementation to plot lines, circles, ellipses and Bézier curves, GitHub](https://github.com/zingl/Bresenham)
12. [Bresenham's line drawing algorithm in any number of dimensions, Cris' Image Analysis Blog](https://www.crisluengo.net/archives/400/)
13. [Younis, B.M.K. & Sheet, N.S.M. (2013). "Hardware Implementation of 3D-Bresenham's Algorithm Using FPGA," Tikrit Journal of Engineering Sciences 20(2)](https://tj-es.com/ojs/index.php/tjes/article/download/398/409)
14. [Anti-aliased Line — Xiaolin Wu's algorithm, GeeksforGeeks](https://www.geeksforgeeks.org/dsa/anti-aliased-line-xiaolin-wus-algorithm/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 19, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 19, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Numerical, string, and geometric algorithms › Computational geometry

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/bresenhams-line-algorithm

English original: https://www.edgepedia.org/bresenhams-line-algorithm
