日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

线描算法

發布時間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 线描算法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

線描算法 (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:

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

  • If an angle is greater than 45 degree then it means the slope is greater than 1 which also mean that dy/dx>1.
  • 如果角度大于45度,則意味著斜率大于1,這也意味著dy / dx> 1 。
  • If an angle is less than 45 degree then it means the slope is less than 1 which also mean that dy/dx<1.
  • 如果角度小于45度,則意味著斜率小于1,這也意味著dy / dx <1 。
  • If an angle is equal to 45 degrees then it means the slope is 1 which also means that dy/dx=1.
  • 如果角度等于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)elsestep=abs(dy)x increment= dx/stepy increment= dy/stepfor(i=1;i<=step;i++){putpixel (x1,y1);x1=x1+increment;y1=y1+increment;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

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坐標都可以增加。 在此基礎上,生成了以下三種情況:

  • 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 。

  • 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 。

  • 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-y13. x=x1, y=y14. e=2dy-dx where, e is a decision parameter.5. While(e>=0){y=y+1e=e-2dx}X=x+1e=e+2dy6. i<=dx , here i is only dependent upon the value of x.

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

    總結

    以上是生活随笔為你收集整理的线描算法的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。