dda算法_計算機圖形學中的DDA(數字差分分析儀)算法

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

XYx = round(x + xinc)y = y + yinc
222 + 0.75 = 2.75 = 32 + 1 = 3
333 + 0.75 = 3.75 = 43 + 1 = 4
444 + 0.75 = 4.75 = 54 + 1 = 5
555 + 0.75 = 5.75 = 65 + 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算法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542615.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542615.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542615.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

購物商城框架java_基于jsp的購物商城-JavaEE實現購物商城 - java項目源碼

基于jspservletpojomysql實現一個javaee/javaweb的購物商城, 該項目可用各類java課程設計大作業中, 購物商城的系統架構分為前后臺兩部分, 最終實現在線上進行購物商城各項功能,實現了諸如用戶管理, 登錄注冊, 權限管理等功能, 并實現對各類購物商城相關的實體進行管理。該購物…

c語言++數組名【數字】_C ++程序在數組中打印所有非重復數字

c語言數組名【數字】Problem statement: Write a C program to print all the non-repeated numbers in an array in minimum time complexity. 問題陳述&#xff1a;編寫一個C 程序&#xff0c; 以最小的時間復雜度將所有未重復的數字打印在數組中 。 Input Example: 輸入示例…

java最接近對點及距離_最接近點對問題_分治法

一、問題描述給定平面上的n個點&#xff0c;找其中的一對點&#xff0c;使得在n個點組成的所有點對中該點對間的距離最小。二、解題思路及所選算法策略的可行性分析思路&#xff1a;利用分治法來解決問題。遞歸子結構求最接近點對總體可分為幾個步驟&#xff1a;1、當問題規模小…

python return用法_初學Python要了解什么 裝飾器知識匯總有哪些

初學Python要了解什么&#xff1f;裝飾器知識匯總有哪些&#xff1f;在Python學習過程中&#xff0c;有多種方法對函數和類進行加工&#xff0c;相對于其它方式&#xff0c;裝飾器語法簡單&#xff0c;代碼可讀性高。因此&#xff0c;裝飾器在Python項目中有廣泛的應用&#xf…

android emulator虛擬設備分析第三篇之pipe上的qemud service

一、概述 本篇和第二篇是強相關的&#xff0c;需要結合第二篇一起看。 以boot-properties為例&#xff0c;注意不需要看ANDROID-QEMUD.TXT&#xff0c;這個是和guest os中的qemud進行相關的&#xff0c;已廢棄。 啟動emulator時&#xff0c;有一個參數-prop <key><val…

c#異常處理_C#異常處理能力問題和解答 套裝4

c#異常處理1) Which is not a valid keyword used in the context of exception handling? trycatchfinalfinally Answer & Explanation Correct answer: 3final The final keyword is not used to handle exceptions in C#.NET. 1)在異常處理的上下文中使用哪個無效關鍵字…

Castor xsd生成java_java – Castor可以處理從基礎XSD導入的多個XSD生成類嗎?

注意&#xff1a;我是EclipseLink JAXB (MOXy)領導者,也是JAXB 2 (JSR-222)專家組的成員.Can Castor do this? If so, what would be the Ant task syntax for it.If not, would perhaps JAXB be a better alternative?下面是如何使用JAXB完成此操作的示例&#xff1a;產品xm…

串口通信 校驗碼_一文讀懂S7-200 SMART自由口通信!

學習S7-200 SMART時了解到&#xff0c;基于RS485接口可實現一下幾種通信&#xff1a;1&#xff09;modbus RTU通信2&#xff09;PPI協議通信3&#xff09;USS協議通信4&#xff09;自由口通信何為自由口通信呢&#xff1f;前三種通信必須要PLC和與其通信的設備支持相同的通信協…

hbase 學習(十三)集群間備份原理

集群建備份&#xff0c;它是master/slaves結構式的備份&#xff0c;由master推送&#xff0c;這樣更容易跟蹤現在備份到哪里了&#xff0c;況且region server是都有自己的WAL 和HLog日志&#xff0c;它就像mysql的主從備份結構一樣&#xff0c;只有一個日志來跟蹤。一個master集…

python expect模塊_Python基礎教程:用Python怎么telnet到網絡設備

Python基礎教程&#xff1a;用Python怎么telnet到網絡設備0.前言Telnet協議屬于TCP/IP協議族里的一種&#xff0c;對于我們這些網絡攻城獅來說&#xff0c;再熟悉不過了&#xff0c;常用于遠程登陸到網絡設備進行操作&#xff0c;但是&#xff0c;它的缺陷太明顯了&#xff0c;…

Java實現動態加載頁面_[Java教程]動態加載頁面數據的小工具 javascript + jQuery (持續更新)...

[Java教程]動態加載頁面數據的小工具 javascript jQuery (持續更新)0 2014-05-07 18:00:06使用該控件&#xff0c;可以根據url&#xff0c;參數&#xff0c;加載html記錄模板(包含json參數對應&#xff0c;以及具體記錄位置Index根據參數描述加載對應的屬性&#xff0c;并可以…

馬哥linux第六周作業

1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄&#xff0c;將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#&#xff1b;[rootmageedu tmp]# cp /etc/rc.d/rc.sysinit . [rootmageedu tmp]# vim rc.sysinit :% s/^[[:space:]]/#&/ #按Esc進入vi…

Java ObjectInputStream enableResolveObject()方法與示例

ObjectInputStream類enableResolveObject()方法 (ObjectInputStream Class enableResolveObject() method) enableResolveObject() method is available in java.io package. enableResolveObject()方法在java.io包中可用。 enableResolveObject() method is used to enable th…

pygame render怎么顯示中文_PyGame開發游戲(2D)02.基礎圖元

這節將介紹PyGame的基礎架構。并學習如何在PyGame里繪制各種幾何圖形和顯示加載圖片。01.應用框架上一節的示例程序里&#xff0c;我們用到一個PyGame的應用程序框架。這是一個基礎框架&#xff0c;利用它我們可以很輕松的添加各類圖型繪制&#xff0c;鍵盤鼠標輸入處理和各類邏…

word+增加水印+java_為Word2019文檔添加水印的兩種方法

水印的類型包括文字水印和圖片水印兩種。在Word文檔中添加文字水印時&#xff0c;可以使用程序中預設的水印效果&#xff0c;而圖片水印則需要自定義添加。一、使用程序預設的文字水印Word 2019中預設了機密、緊急、免責聲明三種類型的文字水印&#xff0c;用戶可根據文件的類型…

如何設置CentOS 7獲取動態及靜態IP地址

自動獲取動態IP地址1.輸入“ip addr”并按回車鍵確定&#xff0c;發現無法獲取IP(CentOS 7默認沒有ifconfig命令)&#xff0c;記錄下網卡名稱&#xff08;本例中為ens33&#xff09;。2.輸入“cd /etc/sysconfig/network-scripts/”按回車鍵確定&#xff0c;繼續輸入“ls”按回…

請求列出指定服務器上的可用功能失敗_濫用 ESI 詳解(上)

在進行安全性評估時&#xff0c;我們注意到了標記語言 Edge Side Includes (ESI)中的一個意外行為&#xff0c;這種語言用于許多流行的 HTTP 代理(反向代理、負載平衡器、緩存服務器、代理服務器)。我們發現成功的 ESI 攻擊可以導致服務器端請求偽造(SSRF)、各種繞過 HTTPOnly …

Java ClassLoader setPackageAssertionStatus()方法與示例

ClassLoader類setPackageAssertionStatus()方法 (ClassLoader Class setPackageAssertionStatus() method) setPackageAssertionStatus() method is available in java.lang package. setPackageAssertionStatus()方法在java.lang包中可用。 setPackageAssertionStatus() metho…

java上傳kafka的方法_哪種方法是將所有數據從Kafka主題復制到接收器(文件或Hive表)的最佳方法?...

我正在使用Kafka Consumer API將所有數據從Kafka主題復制到Hive表 . 為此&#xff0c;我使用HDFS作為中間步驟 . 我使用唯一的組ID并將偏移重置為“最早”&#xff0c;以便從頭開始獲取所有數據&#xff0c;并在執行后忽略提交 . 然后我遍歷Kafka主題中的記錄&#xff0c;并將每…

openstack nova-network 的小bug的排錯經歷

環境是 nova-network vmwareflatdhcp錯誤表現為 開出來的虛擬機有一定幾率獲取不到dhcp地址&#xff0c;手工賦予ip則正常&#xff0c;用flat模式注入的ip正常&#xff0c;下面是排錯過程1首先找網絡防火墻已經把 dnsmasq對應的端口已經打開抓包結果&#xff1a;可以看到虛擬機…