z字扫描和光栅扫描的转换_扫描转换计算机图形中的直线
z字掃描和光柵掃描的轉換
掃描轉換直線 (Scan Converting a Straight Line)
For the scan conversion of a straight line, we need the two endpoints. In normal life, if we want to draw a line we simply draw it by using a scale or ruler. But we can't draw a line on the computer by using a ruler. We have to do some programming for it. The computer draws a line by finding the intermediate points between the two endpoints of a line. The line is drawn on the screen when the computer has endpoints and then the computer fills the pixel of the intermediate point's value.
為了進行直線的掃描轉換 ,我們需要兩個端點。 在正常生活中,如果要繪制線條,我們只需使用刻度尺或標尺就可以繪制線條。 但是我們不能使用標尺在計算機上畫一條線。 我們必須為此做一些編程。 計算機通過找到一條線的兩個端點之間的中間點來繪制一條線。 當計算機具有端點時,將在屏幕上繪制該線,然后計算機填充中間點值的像素。
The computer can't take the intermediate points in fraction value. For example, after using any of the algorithms if the intermediate point was found (5.1, 7.8) then the computer will round off the point values which are (5,8). The computer takes the nearest integer from that fraction value. This happens because the computer fills the pixels in the screen and pixels are present at the integer values. Either the pixel will be filled or it will not be filled. A pixel can't be partially filled. That is why the line is drawn in the computer is not always a straight line.
計算機無法獲取分數值的中間點。 例如,使用任何算法后,如果找到中間點(5.1,7.8),則計算機將舍入為(5,8)的點值。 計算機從該分數值中獲取最接近的整數。 發生這種情況是因為計算機填充了屏幕上的像素,并且像素以整數值存在。 像素將被填充或不被填充。 像素無法部分填充。 這就是為什么在計算機中繪制的線并不總是一條直線的原因。
There are several algorithms available which are used for this process:
有幾種算法可用于此過程:
Direct Method
直接法
Bresenham's Algorithm
布雷森納姆算法
DDA (Digital Differential Analyzer)
DDA(數字差分分析儀)
1)直接法 (1) Direct Method)
It is the simplest method of this. In this algorithm, we have two endpoints. We find the slope of the line by using both the points and we put the slope in the line equation Y = MX + C. Then we find the value of C by putting X and Y is equal to 0. After this, we have a relation between X and Y. Now we increase the value of X and find the corresponding value of Y. These values will be the intermediate points of the line. After finding the intermediate points we'll plot those points and draw the line.
這是最簡單的方法。 在此算法中,我們有兩個端點。 我們通過同時使用這兩個點來找到直線的斜率,并將該斜率放在線方程Y = MX + C中 。 然后,通過將X和Y等于0來找到C的值。此后,我們在X和Y之間具有關系。 現在我們增加X的值并找到Y的對應值。 這些值將是線的中間點。 找到中間點后,我們將繪制這些點并繪制線。
2)布雷森納姆算法 (2) Bresenham's Algorithm)
This method of line drawing is very effective because it includes integer addition, subtraction, and multiplication. The calculation is very fast in this method that's why the line is drawn very quickly in this. We'll need the two endpoints in this and then we have to find the decision parameters. Let assume that (x1,y1) and (x2,y2) are the two points. So, dx = x2-x1 and dy = y2-y1.
這種線描方法非常有效,因為它包括整數加法,減法和乘法。 這種方法的計算速度非常快,這就是在這種方法中繪制直線非常快的原因。 我們將需要兩個端點,然后必須找到決策參數。 假設(x1,y1)和(x2,y2)是兩點。 因此, dx = x2-x1和dy = y2-y1 。
The formula for the decision parameter is: di = 2dy - dx
決策參數的公式為: di = 2dy-dx
If di > 0 (Above true line)
如果di> 0(在實線以上)
di +1 = di + 2dy - 2dx Plotted points are, xN = x1 + 1yN = y1 + 1If di < 0: (Below True Line)
如果di <0:(在真線下方)
di + 1 = di + 2dy Plotted points are, xN = x1 + 1yN = y1 This is the way we can find the intermediate point and after finding these points we can plot all the points on the screen using programming.優點 (Advantages)
This algorithm involves integer arithmetic operations.
該算法涉及整數算術運算。
Duplicate points can’t be generated in this.
不能在其中生成重復點。
This algorithm can be implemented using the software as well as the hardware.
可以使用軟件以及硬件來實現該算法。
缺點 (Disadvantages)
This algorithm is for basic line drawing.
此算法用于基本線條繪制。
You have to prefer some other algorithm for drawing smooth lines
您必須喜歡其他一些算法來繪制平滑線
DDA(數字差分分析儀) (DDA (Digital Differential Analyzer))
This algorithm works on the incremental approach. It means that by taking the help of previous coordinates, we find the next coordinates. In this method, the difference of pixel point is analyzed and according to the analysis, the line can be drawn. We'll start with the starting point and we'll try to find the intermediate points between the starting point and the ending point. The slope of the line will be the ratio of difference of y-coordinates and the difference of x-coordinates.
該算法適用于增量方法。 這意味著借助前一個坐標,我們可以找到下一個坐標。 在這種方法中,分析像素點的差異,并根據該分析可以繪制線條。 我們將從起點開始,然后嘗試找到起點和終點之間的中間點。 線的斜率將是y坐標差與x坐標差之比。
Δy = ( y2 - y1 )Δx = ( x2 - x1 )Where, (x1, y1) and (x2, y2) are the endpoints.
其中(x1,y1)和(x2,y2)是端點。
The Digital Differential Analyzer algorithm is based on the values of Δx and Δy.
數字差分分析器算法基于Δx和Δy的值。
Δy = m * Δx Δx = Δy / mThe value of the slope will be either positive or negative. If the value of the slope is positive then the values of Δx and Δy are increased otherwise their values are decreased.
斜率的值可以為正或為負。 如果斜率的值為正,則增加Δx和Δy的值,否則減小它們的值。
1) If (m < 1):xN = x1 + 1yN = y1 + m2) If (m > 1):xN = x1 + 1 / myN = y1 +13) If (m = 1):xN = x1 + 1yN = y1 + 1翻譯自: https://www.includehelp.com/computer-graphics/scan-converting-a-straight-line.aspx
z字掃描和光柵掃描的轉換
總結
以上是生活随笔為你收集整理的z字扫描和光栅扫描的转换_扫描转换计算机图形中的直线的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java类类getGenericSupe
- 下一篇: 不错!SpringBoot发布Jar包优