dda算法

DDA(数字差分分析仪)算法 (DDA (Digital Differential Analyzer) Algorithm)

In computer graphics, the DDA algorithm is the simplest algorithm among all other line generation algorithms. Here, the DDA is an abbreviation that stands for "Digital Differential Analyzer". It is an incremental method, i.e. it works by incrementing the source coordinate points according to the values of the slope generated.

在计算机图形学中, DDA算法是所有其他线生成算法中最简单的算法。 在此, DDA“数字差分分析仪”的缩写。 这是一种增量方法,即,它根据生成的坡度值通过增加源坐标点来工作。

Hence, we can define DDA as follows,

因此,我们可以如下定义DDA,

"DDA stands for Digital Differential Analyzer. This algorithm is incremental and is used for the rasterization of lines, triangles, and polygons."

“ DDA代表数字差分分析仪。此算法是增量算法,用于线,三角形和多边形的栅格化。”

DDA算法的工作 (Working of the DDA Algorithm)

Suppose we have to draw a line PQ with coordinates P (x1, y1) and Q (x2, y2).

假设我们必须绘制一条坐标为P(x1,y1)和Q(x2,y2)的直线PQ

  1. First, Calculate dx = (x2 - x1) and dy = (y2 - y1)

    首先,计算dx =(x2-x1)和dy =(y2-y1)

  2. Now calculate the slope m = (dy / dx)

    现在计算斜率m =(dy / dx)

  3. Calculate the number of points to be plotted (i.e. n) by finding the maximum of dx and dy, i.e. n = abs (max (dx , dy))

    通过找到dxdy的最大值来计算要绘制的点数(即n ),即n = abs(最大值(dx,dy))

    To draw an accurate line, more number of points are required. Therefore, the maximum of the two values is used here.

    要绘制一条精确的线,需要更多的点。 因此,此处使用两个值中的最大值。

  4. Now as the n is calculated, to know by how much each source point should be incremented, calculate xinc and yinc as follows: xinc = (dx / n) and yinc = (dy / n)

    现在,当计算n时,要知道每个源点应增加多少,请按以下方式计算x incy incx inc =(dx / n)和y inc =(dy / n)

  5. Now we draw the points from P to Q. The successive points are calculated as follows: (xnext, ynext) = (x + xinc, y + yinc)

    现在我们将点从P画到Q。 连续点的计算如下: (x next ,y next )=(x + x inc ,y + y inc )

    Start plotting the points from

    从开始绘制点

    P and stop when Q is reached. In case the incremented values are decimal, use the round off values.

    P并在达到Q时停止。 如果增量值为十进制,请使用四舍五入值。

Now, let us have a look at the algorithm that is followed in DDA.

现在,让我们看一下DDA中遵循的算法。

DDA算法 (DDA Algorithm)

  • Step 1: Start.

    步骤1:开始。

  • Step 2: Declare x1, y1, x2, y2.

    步骤2:声明x1,y1,x2,y2。

  • Step 3: Calculate the following,

    步骤3:计算以下内容,

        dx = x2 - x1
    dy = y2 - y1
    
    
  • Step 4: Calculate slope as follows,

    步骤4:按以下方式计算斜率,

        m = dy / dx
    
    
  • Step 5: Calculate the no. of points (n) between x1 and x2 as follows,

    步骤5:计算编号。 x1和x2之间的点(n)如下,

        n = abs ( max ( dx , dy ) )
    
    
  • Step 6: Calculate xincand yinc as follows,

    步骤6:按以下方式计算x inc和y inc

        xinc = (dx / n) and yinc = (dy / n)
    
    
  • Step 7: Now, Initialize x = x1 and y = y1.

    步骤7:现在,初始化x = x1和y = y1。

  • Step 8:

    步骤8:

        while ( x <= x2 )
    x = x + xinc
    y = y + yinc
    
    
  • Step 9: Now, Plot (x,y) on the graph, and hence we get our required line between the given points.

    步骤9:现在,在图形上绘制(x,y),因此我们得到了给定点之间的所需线。

  • Step 10: End.

    步骤10:结束。

Formula:

式:

In the entire DDA algorithm, there are three conditions and according to these conditions, the formula for calculating the coordinates is changed. These formulas are as follows,

在整个DDA算法中 ,存在三个条件,并根据这些条件更改了计算坐标的公式。 这些公式如下:

    If m < 1 :      If m > 1 :          If m = 1 :
xinc = 1        xinc = (1 / m)      xinc = 1
yinc = m        yinc = 1            yinc = 1

Example:

例:

Now let us take an example to understand the whole working of the DDA algorithm,

现在让我们举一个例子来了解DDA算法的整个工作原理

Question: Draw a line from A(2 , 2) to B(5 , 5) using the DDA algorithm.

问题:使用DDA算法A(2,2)B(5,5 )画一条线。

Solution:

解:

    Given:
x1 = 2 , y1 = 2
x2 = 5 , y2 = 6
Calculating:
dx  = (x2 - x1) = (5 - 2) = 3
dy  = (y2 - y1) = (6 - 2) = 4
n   = abs (max (dx , dy ) ) = abs (max (3 , 4) ) = 4
xinc = dx / n = 3/4 = 0.75
yinc = dy / n = 4 / 4 = 1

X Y x = round(x + xinc) y = y + yinc
2 2 2 + 0.75 = 2.75 = 3 2 + 1 = 3
3 3 3 + 0.75 = 3.75 = 4 3 + 1 = 4
4 4 4 + 0.75 = 4.75 = 5 4 + 1 = 5
5 5 5 + 0.75 = 5.75 = 6 5 + 1 = 6
X ÿ x =圆(x + x inc ) y = y + y inc
2 2 2 + 0.75 = 2.75 = 3 2 +1 = 3
3 3 3 + 0.75 = 3.75 = 4 3 +1 = 4
4 4 4 + 0.75 = 4.75 = 5 4 +1 = 5
5 5 5 + 0.75 = 5.75 = 6 5 +1 = 6

Stop here as we have reached point B.

当我们到达B点时,在此停止。

Now, Plot the points ( (2 , 2) , (3 , 3) , (4 , 4) , (5 , 5) ) on the graph and thus we get our required line from point A to point B.

现在,在图形上绘制点((2,2),(3、3),(4、4),(5、5)) ,这样我们就得到了从点A到点B所需的线。

DDA算法的优点 (Advantages of the DDA algorithm)

Now, we will be looking at the advantages that the DDA algorithm offers over other line drawing algorithms.

现在,我们将探讨DDA算法相对于其他线条绘制算法的优势。

  1. It is the simplest line generation algorithm.

    它是最简单的线生成算法。

  2. Implementation of the DDA algorithm is very easy as compared to other line generation algorithms.

    与其他线路生成算法相比,DDA算法的实现非常容易。

  3. It does not use multiplication which reduces the time complexity of implementation.

    它不使用乘法来减少实现的时间复杂度。

  4. It is a faster and a better method than using the direct method of the line equation: i.e. y = mx + c

    与使用线性方程式的直接方法相比,这是一种更快,更好的方法:即y = mx + c

DDA算法的缺点 (Disadvantages of the DDA algorithm)

  • DDA algorithm use floating-point arithmetic as it involves the use of division in the calculation of xinc and yinc. This floating-point arithmetic makes the algorithm time-consuming.

    DDA算法使用浮点算法,因为它涉及在x inc和y inc的计算中使用除法。 这种浮点算法使算法耗时。

  • The use of floating-point arithmetic decreases the accuracy of the generated points. Hence the points that we get are not accurate, i.e. they may not lie accurately on the line.

    使用浮点算法会降低生成点的准确性。 因此,我们得到的点是不准确的,即它们可能不准确地位于线上。

  • As the points that we get from the DDA algorithm are not accurate, the lines generated by this algorithm are not smooth, i.e. some discontinuation and zigzag nature can be commonly seen in the lines drawn through this algorithm.

    由于我们从DDA算法获得的点不准确,因此该算法生成的线条不平滑,即在通过该算法绘制的线条中通常可以看到一些不连续和之字形性质。

翻译自: https://www.includehelp.com/computer-graphics/dda-digital-differential-analyzer-algorithm.aspx

dda算法

dda算法_计算机图形学中的DDA(数字差分分析仪)算法相关推荐

  1. 图形学 射线相交算法_计算机图形学中的阴极射线管

    图形学 射线相交算法 阴极射线管 (Cathode Ray Tube) Ferdinand Barun of Strasbourg developed the cathode ray tube in ...

  2. 图形学 射线相交算法_计算机图形学中的彩色阴极射线管

    图形学 射线相交算法 彩色阴极射线管 (Color Cathode Ray Tube) CRT i.e. Cathode Ray Tubes are used to produce Color dis ...

  3. 图形学 射线相交算法_计算机图形学中的阴极射线管(CRT)

    图形学 射线相交算法 什么是阴极射线管(CRT)? (What is Cathode Ray Tube (CRT)?) CRT stands for "Cathode Ray Tube&qu ...

  4. 计算机图形学图形旋转_计算机图形学中的旋转

    计算机图形学图形旋转 计算机图形学| 回转 (Computer Graphics | Rotation) Rotation is a type of transformation that is ve ...

  5. 计算机图形学 光栅化_计算机图形学中的光栅扫描和随机扫描显示

    计算机图形学 光栅化 光栅扫描显示 (Raster Scan Display) Raster can be explained as a rectangular collection of dots ...

  6. 计算机图形学图形旋转_计算机图形学中的平板显示

    计算机图形学图形旋转 平板显示器 (Flat Panel Display) It is generally known as FPD, the flat-panel display is such a ...

  7. java代码隐藏面消除算法_计算机图形学—— 隐藏线和隐藏面的消除(消隐算法)...

    一.概述 由于投影变换失去了深度信息,往往导致图形的二义性.要消除二义性,就必须在绘制时消除被遮挡的不可见的线或面,习惯上称作消除隐藏线和隐藏面(或可见线判定.可见面判定),或简称为消隐.经过消隐得到 ...

  8. std中稳定排序算法_实战c++中的vector系列--使用sort算法对vector进行排序(对vector排序、使用稳定的排序std::stable_sort())...

    写了挺多关于vector的操作了,正好工作中遇到对vector进行排序的问题,这里就讨论一下. 直接使用sort算法,那就先了解一下: template void sort (RandomAccess ...

  9. DDA直线生成算法|MFC|计算机图形学

    DDA直线生成算法|MFC|计算机图形学|保姆篇 1.如何创建MFC编译环境? 点击工具->获取工具和功能 2.创建MFC编辑窗口 3.进入到MFC编辑窗口后 1)设计窗口,修改ID 2)添加事 ...

  10. 计算机图形学画线_在计算机图形学中直接使用线方程

    计算机图形学画线 计算机图形学| 直接使用线方程 (Computer Graphics | Direct Use of Line Equation) The standard line equatio ...

最新文章

  1. 一次生产 CPU 100% 排查优化实践
  2. 如何用html语言定位img,html经常使用标签(图像标签img,连接标签a,锚点定位,及路径)...
  3. Long类型传到前端失去精度(2):Long类型不是实体类的某一个字段,Long类型是一个函数的返回值
  4. python菜鸟教程函数-Python 函数装饰器
  5. JDK源码重新编译——支持eclipse调试JDK源码--转载
  6. html修改上传文件名,input(file)样式修改及上传文件名显示
  7. 异常处理——namenode启动成功但是没有namenode进程
  8. linux安装运行redis
  9. Java 基础知识体系
  10. 服务器后端开发系列——《实战Nginx高性能Web服务器》 (转载)
  11. trigger 根据绑定到匹配元素的给定的事件类型执行所有的处理程序和行为。
  12. 数据仓库入门(实验9)查询多维数据集
  13. 莫烦python_莫烦python教学网站
  14. SpreadJS V15.0 Update2 新特性一览
  15. 2022 CCF国际AIOps挑战赛决赛暨AIOps研讨会成功举办
  16. Python 变量作用域问题 函数名.变量名
  17. python爬取bilibili数据_BiliBili爬取数据简单分析
  18. CFML----一门在国外很多大公司得到应用的语言
  19. 【THREE.JS学习(3)】使用THREEJS加载GeoJSON地图数据
  20. 电路图:LM3886低音炮电路

热门文章

  1. 用python写个类似浏览器的下载器,超简单的
  2. CAJViewer 无法获取document路径问题--360卫士C盘搬家
  3. VRay4.2 for 3dsMax2013-2020
  4. 百度文库的内容怎么复制粘贴下来呢,look
  5. win7 64位系统PS、AI、PSD缩略图预览补丁
  6. dsoframer java_[转]内嵌WORD/OFFICE的WINFORM程序——DSOFRAMER使用小结
  7. Elsevier LaTeX 模板
  8. UltraEdit 25注册机及免费破解注册教程(附带工具)
  9. 【优化模型】逐步回归算法
  10. 三菱GXWorks2 新建工程