问题描述
我想实现的算法在这张纸上,用下面的一条直线,这对于光线跟踪有用的遍历网格单元,以便解释:
I am trying to implement the algorithm explained on this paper, used to traverse grid cells in order following a straight line, which is useful for ray tracing:
http://www.cse.yorku.ca/~amana/研究/ grid.pdf
本文介绍了算法两部分:初始化和迭代遍历。我可以undersand迭代遍历的一部分,但我无法理解为什么一些在初始化部分的变量进行计算。
The paper describes the algorithm as two parts: initialisation and iterative traversal. I can undersand the iterative traversal part, but I'm having trouble understanding how some of the variables in the initialisation part are calculated.
我需要帮助初始化 tMaxX
, tMaxY
, tDeltaX
&安培; tDeltaY
。其初始化过程解释如下:
I need help initialising tMaxX
, tMaxY
, tDeltaX
& tDeltaY
. Their initialisation procedure is explained as follows:
接下来,我们确定的t处的光线穿过第一个值 垂直像素边界并将其存储在变量tMaxX。我们执行 y中类似的计算和结果存储在tMaxY。的最小 这两个值将表明我们有多少可以沿着射线走 ,但仍保持在当前体素
最后,我们计算tDeltaX和tDeltaY。 TDeltaX表明多远 沿射线,我们必须移动(在T为单位)的水平 这种运动的分量等于一个体素的宽度。同样, 在tDeltaY存储移动量沿其具有的射线 垂直分量等于一个体素的高度
Finally, we compute tDeltaX and tDeltaY. TDeltaX indicates how far along the ray we must move (in units of t) for the horizontal component of such a movement to equal the width of a voxel. Similarly, store in tDeltaY the amount of movement along the ray which has a vertical component equal to the height of a voxel.
我不能推导出code,我需要形成上面给出的英文说明。谁能把它给一个数学/伪code EX pression我?
I'm not able to deduce the code I need form the English description given above. Can someone translate it to a math/pseudocode expression for me?
推荐答案
初始化为X坐标变量(相同的Y)
Initialization for X-coordinate variables (the same for Y)
DX = X2 - X1
tDeltaX = GridCellWidth / DX
tMaxX = tDeltaX * (1.0 - Frac(X1 / GridCellWidth))
//Frac if fractional part of float, for example, Frac(1.3) = 0.3
例如:
GridCellWidth, Height = 20
X1 = 5, X2 = 105
Y1 = 5, Y2 = 55
DX = 100, DY = 50
tDeltaX = 0.2, tDeltaY = 0.4
tMaxX = 0.2 * (1.0 - 0.25) = 0.15 //ray will meet first vertical line at this param
tMaxY = 0.4 * (1.0 - 0.25) = 0.3 //ray will meet first horizontal line at this param
我们可以看到,第一个单元格边框将在参数t满足= 0.15
We can see that first cell border will be met at parameter t = 0.15
这篇关于我如何初始化T-变量"一种快速的体素遍历算法光线跟踪和QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!