線描算法

線描算法 (Line drawing algorithms)

  • The equation for a straight line is y=mx+b

    直線方程為y = mx + b

  • In this m represent a slope of a line which can be calculated by the m=y2-y1/x2-x1 where (x1, y1) are the starting position of the points and (x2, y2) are the end positions of the points.

    在此m表示可以通過m = y2-y1 / x2-x1計算的直線的斜率,其中(x1,y1)是點的起始位置, (x2,y2)是點的終止位置。

  • There are generally three cases arises, which are:

    通常會出現三種情況,分別是:

    1. If an angle is greater than 45 degree then it means the slope is greater than 1 which also mean that dy/dx>1.
    2. 如果角度大于45度,則意味著斜率大于1,這也意味著dy / dx> 1 。
    3. If an angle is less than 45 degree then it means the slope is less than 1 which also mean that dy/dx<1.
    4. 如果角度小于45度,則意味著斜率小于1,這也意味著dy / dx <1 。
    5. If an angle is equal to 45 degrees then it means the slope is 1 which also means that dy/dx=1.
    6. 如果角度等于45度,則意味著斜率為1,這也意味著dy / dx = 1 。
  • The increment in x can be calculated by the x2-x1 divided by a total number of steps. Similarly increment of y can be calculated by the y2-y1 divided by the total number of steps.

    x的增量可以通過x2-x1除以總步數來計算。 類似地,可以通過y2-y1除以總步數來計算y的增量。

DDA算法 (DDA Algorithm)

This is a line drawing algorithm which is named as Digital Differential Analyzer (DDA). Basically, it uses the floor function which takes the extra time for generating a line. The DDA algorithm is a faster method for calculating a pixel position for a direct use of it. In some cases, the line drawn by the DDA algorithm is not smooth.

這是一種畫線算法,稱為數字差分分析器(DDA)。 基本上,它使用發言權功能,這會花費額外的時間來生成一條線。 DDA算法是一種用于直接使用像素位置來計算像素位置的更快方法。 在某些情況下,DDA算法繪制的線不平滑。

    Algorithm DDA (x1, y1, x2, y2)
{
dx=x2-x1;
dy=y2-y1;
if (abs(dx)>abs(dy))
step=abs(dx)
else
step=abs(dy)
x increment= dx/step
y increment= dy/step
for(i=1;i<=step;i++)
{
putpixel (x1,y1);
x1=x1+increment;
y1=y1+increment;
}
}

Conclusion:

結論:

In this algorithm for finding a position of a point, there can be an increment in both x coordinate or can be in a y coordinate. On the basis of it, there are three cases generated which are as given below:

在用于查找點位置的該算法中, x坐標或y坐標都可以增加。 在此基礎上,生成了以下三種情況:

  1. If the value of m is less than 1, then x=x+1 and y=y+m.

    如果m的值小于1,則x = x + 1和y = y + m 。

  2. If the value of m is greater than 1, then x=x+m and y=y+1.

    如果m的值大于1,則x = x + m和y = y + 1 。

  3. If the value of m is equal to 1, then x=x and y=y.

    如果m的值等于1,則x = x和y = y 。

布雷森納姆算法 (Bresenham’s Algorithm)

This is an algorithm which is used for drawing a line accurately and efficiently which was developed by Bresenham’s. Here generally, decision parameter is used for finding the next value from the initial one. According to this algorithm value of x will always be incremented but the value of y will be incremented or not it depends upon the decision parameter. This is a faster algorithm and less expensive to implement. There are no criteria of a round of the value in this algorithm which makes this algorithm faster and accurate.

這是由布雷森漢姆(Bresenham's)開發的一種算法,用于精確有效地繪制線。 通常,這里使用決策參數從初始值中查找下一個值。 根據該算法,x的值將始終增加,但是y的值將增加或不增加,這取決于決策參數。 這是一種更快的算法,實現起來成本較低。 此算法中沒有輪取值的標準,這會使該算法更快,更準確。

Steps for implementing Bresenham’s algorithm:

實施布雷森漢姆算法的步驟:

    1.	Read the end points (x1, y1) and (x2, y2).
2.	dx=x2-x1 
dy=y2-y1
3.	x=x1, y=y1
4.	e=2dy-dx where, e is a decision parameter.
5.	While(e>=0)
{
y=y+1
e=e-2dx
}
X=x+1
e=e+2dy
6.	i<=dx , here i is only dependent upon the value of x. 

翻譯自: https://www.includehelp.com/algorithms/line-drawing.aspx

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

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

相關文章

為移動端網頁構造快速響應按鈕

背景 在谷歌&#xff0c;我們不斷地推測手機網頁應用的可能性。像HTML5這樣的技術使我們網頁版的應用以及運行在手機設備上的原生應用。而這些技術的成就之一就是我們開發了一種新的創建按鈕的方法&#xff0c;使按鈕的響應時間遠遠快于一般的HTML按鈕。在此之前的按鈕或者其他…

Red Gate系列之一 SQL Compare 10.4.8.87 Edition 數據庫比較工具 完全破解+使用教程

Red Gate系列之一 SQL Compare 10.4.8.87 Edition 數據庫比較工具 完全破解使用教程 Red Gate系列文章&#xff1a; Red Gate系列之一 SQL Compare 10.4.8.87 Edition 數據庫比較工具 完全破解使用教程 Red Gate系列之二 SQL Source Control 3.0.13.4214 Edition 數據庫版本控制…

《MySQL——基于位點orGTID的主備切換協議》

一主多從的設置&#xff0c;用于讀寫分離&#xff0c;主庫負責所有的寫入和一部分讀&#xff0c;其他讀請求則由從庫分擔。 一主多從架構下&#xff0c;主庫故障后的主備切換問題。相比于一主一備&#xff0c;多了從庫指向新主庫的過程。 基于位點的主備切換同步 把節點B設…

數據科學和統計學_數據科學中的統計

數據科學和統計學統計 (Statistics) Statistics are utilized to process complex issues in reality with the goal that Data Scientists and Analysts can search for important patterns and changes in Data. In straightforward words, Statistics can be utilized to ge…

java隨機數生成(固定位數)

隨機生成 a 到 b (不包含b)的整數:(int)(Math.random()*(b-a))a; 隨機生成 a 到 b (包含b)的整數:(int)(Math.random()*(b-a1))a;轉載于:https://www.cnblogs.com/zhwl/p/3624726.html

POJ 3670 Eating Together

POJ_3670 由于遞增和遞減是類似的&#xff0c;下面不妨只討論變成遞增序列的情況。 由于Di只有三個數&#xff0c;所以可以考慮將序列分割成三部分&#xff0c;第一部分全部變成1&#xff0c;第二部分全部變成2&#xff0c;第三部分全部變成3。然后我們枚舉3開始的位置&#xf…

《MySQL——如何解決一主多從的讀寫分離的過期讀問題》

目錄兩種架構兩種架構特點強制走主庫方案Sleep方案判斷主備無延遲方案配合semi-sync等主庫位點方案GTID方案兩種架構 基于一主多從的讀寫分離&#xff0c;如何處理主備延遲導致的讀寫分離問題。 讀寫分離的主要目標&#xff1a;分攤主庫壓力。 有兩種架構&#xff1a; 1、客…

json/ 發送形式_24/7的完整形式是什么?

json/ 發送形式24/7&#xff1a;二十四 (24/7: Twenty-Four Seven) 24/7 or 24-7 service, which generally marked "twenty-four seven" is service that is existing at any time and typically, every day in trade business and industry. Substitute orthograph…

《MySQL tips:并發查詢與并發連接區別》

并發連接與并發查詢&#xff0c;并不是一個概念。 在執行show processlist的結果里&#xff0c;看到了幾千個連接&#xff0c;指的是并發連接。 而"當前正在執行"的語句&#xff0c;才是并發查詢。 并發連接數多影響的是內存。 并發查詢太高對CPU不利。一個機器的…

對上拉下拉電阻的作用作個總結(想了解的過來看看)(轉載)

轉自&#xff1a;http://www.amobbs.com/thread-5475279-1-3.html 一、定義&#xff1a;上拉就是將不確定的信號通過一個電阻嵌位在高電平&#xff01;電阻同時起限流作用&#xff01;下拉同理&#xff01;上拉是對器件注入電流&#xff0c;下拉是輸出電流&#xff1b;弱強只是…

給用戶傳入的變量進行轉義操作

先看代碼實現&#xff1a; /* 對用戶傳入的變量進行轉義操作。*/ if (!get_magic_quotes_gpc()) {if (!empty($_GET)){$_GET addslashes_deep($_GET);}if (!empty($_POST)){$_POST addslashes_deep($_POST);}$_COOKIE addslashes_deep($_COOKIE);$_REQUEST addslashes_…

《MySQL——外部檢測與內部統計 判斷 主庫是否出現問題》

目錄select1判斷查表判斷更新判斷外部檢測弊端內部統計一主一備的雙M架構里&#xff0c;主備切換只需要把客戶端流量切換到備庫。 在一主多從的架構里&#xff0c;主備切換要把客戶端流量切換到備庫&#xff0c;也需要把從庫接到新主庫上。 切換有兩種場景&#xff1a;1、主動…

NIM的完整形式是什么?

NIM&#xff1a;無內部消息 (NIM: No Internal Message) NIM is an abbreviation of "No Internal Message". NIM是“無內部消息”的縮寫。 It is an expression, which is commonly used in the Gmail platform. It is written in the subject of the mail, if the…

[Json] C#ConvertJson|List轉成Json|對象|集合|DataSet|DataTable|DataReader轉成Json (轉載)...

點擊下載 ConvertJson.rar 本類實現了 C#ConvertJson|List轉成Json|對象|集合|DataSet|DataTable|DataReader轉成Json|等功能大家先預覽一下 請看代碼 /// <summary> /// 類說明&#xff1a;Assistant /// 編 碼 人&#xff1a;蘇飛 /// 聯系方式&#xff1a;361983679 …

let 只能在嚴格模式下嗎_LET的完整形式是什么?

let 只能在嚴格模式下嗎LET&#xff1a;今天早早離開 (LET: Leaving Early Today) LET is an abbreviation of "Leaving Early Today". LET是“ Leaveing Today Today”的縮寫 。 It is an expression, which is commonly used in the Gmail platform. It is writt…

js 遮罩層 loading 效果

//調用方法 //關閉事件<button οnclickLayerHide()>關閉</button>&#xff0c;在loadDiv(text)中&#xff0c;剔除出來 //調用LayerShow(text)&#xff0c;text為參數&#xff0c;可以寫入想要寫入的提示語 //本方法在調用時會自動生成一個添加到body的div&#x…

centos6.5安裝配置LDAP服務[轉]

centos6.5安裝配置LDAP服務[轉] 安裝之前查一下 1find / -name openldap*centos6.4默認安裝了LDAP&#xff0c;但沒有裝ldap-server和ldap-client 于是yum安裝 1su root2yum install -y openldap openldap-servers openldap-clients不建議編譯源碼包&#xff0c;有依賴比較麻煩…

《MySQL——恢復數據-誤刪行、表、庫》

目錄誤刪行事前預防誤刪行數據方法誤刪表/庫延遲復制備庫事前預防誤刪庫/表方法傳統的架構不能預防誤刪數據&#xff0c;因為主庫的一個drop table命令&#xff0c;會通過binlog傳給所有從庫和級聯從庫&#xff0c;進而導致整個集群的實例都會執行這個命令。 MySQL相關的誤刪除…

python圖例位置_Python | 圖例位置

python圖例位置Legends are one of the key components of data visualization and plotting. Matplotlib can automatically define a position for a legend in addition to this, it allows us to locate it in our required positions. Following is the list of locations…

Freemarker中遍歷List實例

Freemarker中如何遍歷List摘要&#xff1a;在Freemarker應用中經常會遍歷List獲取需要的數據&#xff0c;并對需要的數據進行排序加工后呈現給用戶。那么在Freemarker中如何遍歷List&#xff0c;并對List中數據進行適當的排序呢&#xff1f;通過下文的介紹&#xff0c;相信您一…