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字扫描和光栅扫描的转换

z字扫描和光栅扫描的转换_扫描转换计算机图形中的直线相关推荐

  1. dxf geojson 转换_将Geopandas中geojson文件的linestring转换为polygon

    我有dxf格式的以下CAD文件,它以autocad显示,如下所示: 我用gdalorg2org将它转换成geojson格式的文件,名为test.geojson,但都是type: LineString{ ...

  2. access查询出生日期格式转换_从身份证中提取出生日期的3个方法和计算年龄和星座的方法...

    在我们日常的工作当中,经常会遇到通过身份证来获取出生年月日的需求,今天就给大家介绍三种可以从身份证中提取出生年月日的方法. 我们都知道身份证不同的区域是有不同的含义的,代表出生年月日的数字是第7位到第 ...

  3. java中为什么不能强制转换_为什么Java中的强制转换异常致命?

    根据this文章: In contrast to static type checking, dynamic type checking may cause a program to fail at ...

  4. python汇率转换_利用Python中的Xpath实现一个在线汇率转换器

    前言 在之前的语法里面,我们记得有一个初识Python之汇率转换篇,在那个程序里面我们发现可以运用一些基础的语法写一个汇率计算,但是学到后面的小伙伴就会发现这个小程序有一定的弊端. 首先,它不可以实时 ...

  5. AcWing3208. Z字形扫描

    题目 在图像编码的算法中,需要将一个给定的方形矩阵进行 Z 字形扫描(Zigzag Scan). 给定一个 n×n 的矩阵,Z 字形扫描的过程如下图所示: 对于下面的 4×4 的矩阵, 1 5 3 9 ...

  6. XDOJ.70 C语言 Z字形扫描

    题目 标题 : Z字形扫描 类别 : 数组: 时间限制: 1S 内存限制: 256Kb 问题描述: 在图像编码的算法中,需要将一个给定的方形矩阵进行Z字形扫描(Zigzag Scan).给定一个m×n ...

  7. r中如何求变量的对数转换_对数转换以求阳性。

    r中如何求变量的对数转换 In Simple terms, log transform squashes or compresses range of large numbers and expand ...

  8. mysql 数据库字符集转换_字符集介绍及mysql数据库编码转换

    一.字符集介绍: 1.ASCII ASCII是英文American Standard Code for Information Interchange的缩写,美国标准信息交换代码是由美国国家标准学会( ...

  9. mysql 查询编码转换_字符集介绍及mysql数据库编码转换

    一.字符集介绍: 1.ASCII ASCII是英文American Standard Code for Information Interchange的缩写,美国标准信息交换代码是由美国国家标准学会( ...

最新文章

  1. win七系统如何卸载MySQL_win7系统卸载SQL2008R2数据库的详细教程
  2. android获取软件大小,android获取屏幕大小包括状态栏和软件导航栏的大小
  3. Java 打印菱形星块
  4. 手持gps坐标转换参数求解方法及在excel中的实现_分享∣Arcgis中62个常用技巧系列二(21-40技巧)...
  5. 洲际的merlin怎么用_洲际merlin登陆
  6. c++ 调用system 不显示黑框_Java回调的四种写法:反射+直接调用+接口调用+Lambda表达式...
  7. 【机器学习】SVM基本线性可分与多分类
  8. 单片机8×8点阵显示简单汉字的程序_LED显示屏的显示原理原来是这样,科技实现梦想...
  9. Office Word界面和页面字体模糊不清的解决方案
  10. Mysql调优你不知道这几点,就太可惜了
  11. Silverlight4.0教程之WebBrowser控件(Silverlight内置HTML浏览器控件)
  12. 北斗导航 | 基于最小二乘残差法与奇偶矢量法的RAIM算法(附代码)
  13. 英文打字测试C语言课程设计,语言设计打字练习题库.doc
  14. coreldraw梯形校正_有哪些比较好的CDR教程?
  15. 假币问题python
  16. 图解电影的网站有那些?
  17. python怎么使用库里的pi_python怎么调用pi
  18. conda安装 tensorflow-gpu出现错误
  19. Teradata SQL 日期
  20. 将N个整数按从小到大排序的冒泡排序法是这样工作的:从头到尾比较相邻两个元素,如果前面的元素大于其紧随的后面元素,则交换它们。通过一遍扫描,则最后一个元素必定是最大的元素。然后用同样的方法对前N−1个元

热门文章

  1. Qt图形界面编程入门(Qt的历史、Qt安装资源链接、Qt Creator简介)
  2. 你用计算机做过什么事情,他偷偷干了什么?(电脑)
  3. Iptables防火墙原理
  4. 公司台湾主站的url重写
  5. javascript编译压缩
  6. C++类型萃取之type_traits和type_info
  7. ubuntu安装proxychains及自动补全
  8. 性能测试总结(一)---基础理论篇(转载)
  9. PHP $_SERVER['HTTP_REFERER'] 获取前一页面的 URL 地址
  10. jhipster项目迁移websocket