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:

有几种算法可用于此过程:

  1. Direct Method

    直接法

  2. Bresenham's Algorithm

    布雷森纳姆算法

  3. 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中 。 然后,通过将XY等于0来找到C的值。此后,我们在XY之间具有关系。 现在我们增加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-x1dy = y2-y1

The formula for the decision parameter is: di = 2dy - dx

决策参数的公式为: di = 2dy-dx

  1. If di > 0 (Above true line)

    如果di> 0(在实线以上)

        di +1 = di + 2dy - 2dx
    
    Plotted points are,
    
        xN = x1 + 1
        yN = y1 + 1
    
    
  2. If di < 0: (Below True Line)

    如果di <0:(在真线下方)

        di + 1 = di + 2dy
    
    Plotted points are,
    
        xN = x1 + 1
        yN = 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 / m

The 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 + 1
        yN = y1 + m

    2)	If (m > 1):
        xN = x1 + 1 / m
        yN = y1 +1

    3)	If (m = 1):
        xN = x1 + 1
        yN = y1 + 1


翻译自: https://www.includehelp.com/computer-graphics/scan-converting-a-straight-line.aspx

z字扫描和光栅扫描的转换

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值