问题描述
我正在尝试实现本文中解释的算法,用于沿直线遍历网格单元,这对于光线追踪很有用:
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/research/grid.pdf
论文将算法描述为两部分:初始化和迭代遍历.我可以理解迭代遍历部分,但我无法理解初始化部分中的一些变量是如何计算的.
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:
接下来,我们确定光线穿过第一个垂直体素边界并将其存储在变量 tMaxX 中.我们执行一个在 y 中进行类似的计算并将结果存储在 tMaxY 中.最小的这两个值将指示我们可以沿着射线行进多少并且仍然保留在当前体素中.
最后,我们计算 tDeltaX 和 tDeltaY.TDeltaX 表示多远我们必须沿着射线移动(以 t 为单位)这种运动的分量等于体素的宽度.相似地,在 tDeltaY 中存储沿具有 a 的射线的移动量垂直分量等于体素的高度.
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.
我无法从上面给出的英文描述中推断出我需要的代码.有人可以帮我把它翻译成数学/伪代码表达式吗?
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, Frac(-1.7)=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
这篇关于如何在“A Fast Voxel Traversal Algorithm for Ray Tracing"中初始化 t 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!