DDA算法的困惑......! [英] DDA algorithm confusion......!

查看:206
本文介绍了DDA算法的困惑......!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一本书解释的DDA算法和卡住在一个点。根据该规则的点应四舍五入所以这里在这种情况下,它应该是(4,6)处的位置(4,5)是不是。检查下面的图片我包围,我觉得不正确书中的点,所以我是不是把它错了或这本书有一个错字吗?

I was studying a book explaining DDA algorithm and got stuck at a point .According to the rule the points should be rounded up so here in this case It should be (4,6) at the place of (4,5) isn't it .Check the picture below I've encircled the points I feel incorrect in the book ,so Am I taking it wrong or the book got a misprint here ?

推荐答案

为了吸取一个不显眼的计划络绎不绝(X,Y),X,Y的整数,即算法的基础上,直线的斜率,使任一的 X 的或的的载体(总是递增1),另一坐标被内插。原因是:

In order to draw a continuous line on a discreet plan (x,y), x, y integer, that algorithm, based on the slope of the line, makes either x or y the "carrier" (always incremented by one) and the other coordinate is interpolated. Reason are:

  • 图纸应尽可能接近的直线方程
  • 应该有画线
  • 没有洞
  • 在没有必要计算超过必要的值(例如,具有的 X 的载体, X + 0.1 X + 0.2 等)
  • the drawing should be as close as possible to the line equation
  • there should be no "hole" in the drawn line
  • there is no need to calculate more values than necessary (eg, having x "carrier", x+0.1, x+0.2 etc...)

该文件似乎是这个PDF ,在这里你可以看到不断线,不总是在它穿过像素的中心。由于这一算法,一个点都会有一个近邻,无论是在 X + 1 Y + 1 视斜率(插值坐标可能是两次(或更多)在一排相同的舍入的值。例如,如果的的内插,你可以有(10,20),(11,20),( 12,21),具有两倍Y = 20)。

The document seems to be this PDF, where you can see that the continuous line, is not always in the center of the pixels it crosses. Thanks to that algorithm, a dot will have an immediate neighbor, either at x+1 or y+1 depending on the slope (the interpolated coordinate could be twice (or more) in a row the same rounded value. Eg if y is interpolated, you could have (10,20), (11, 20), (12, 21) having twice y=20).

仅考虑季度[0,90]度,从坐标线开始(0,0)。如果线斜率低于45度,最好是具有的 X 的作为载体(加1),而的插入。示例

Considering only the quarter [0, 90] degrees, the line start from coordinates (0,0). If the line slope is below 45 degrees, it is better to have x as "carrier" (incremented by 1), and y interpolated. Example

      +++
   +++
+++

下面的 X 的总是递增一,但的需要有时相同的值作为用于previous的 X 的(例如,对于x = 0,X = 1,X = 2,我们有相同的的)

here x is always incremented by one, but y takes sometimes the same value as for the previous x (eg, for x=0, x=1, x=2 we have the same y)

返回四舍五入

在同一文件中,据说47页

In the same document, it is said page 47

为了绘制的像素的屏幕上,我们需要的坐标四舍五入至最近的整数

in order to plot a pixel on the screen, we need to round off the coordinates to a nearest integer

这是通常的情况下做的一个插值时。这是更好地把最接近的整数。这意味着,通常,

which is usually the case when doing an interpolation. It is better to take the nearest integer. That means, usually,

  • 在采取整数部分+ 1,如果小数点后是> = 0.5 (如 4.71 => 5
  • 只需要整数部分,如果第一个小数点是< 0.5 (如 5.42 => 5
  • take integer part + 1 if first decimal is >= .5 (eg. 4.71 => 5)
  • take only integer part if 1st decimal is < .5 (eg 5.42 => 5)

这样:

  • 整数像素的坐标接近方程式值与小数
  • 舍入值的总和(例如,对于 X 的)更可能接近从等式计算值的总和。
  • the integer pixel coordinates are closer to the equation value with decimals
  • the sum of the rounded value (eg for x) is more likely to be close to the sum of the calculated value from the equation.

在这种特殊情况下,(4,第38/7号)〜= (4,5.43) 5.43 四舍五入到最接近的整数,即 5 ,而不是 6

In this particular case, (4, 38/7) ~= (4, 5.43), 5.43 is rounded to the nearest integer, ie 5 and not 6.

这篇关于DDA算法的困惑......!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆