2D 光线追踪
我正在开发一个程序来演示各种镜头的工作原理以及我所需要的 2D 光线追踪库或算法。
我搜索了光线追踪,主要找到了用于创建 3D 场景的东西,而我的要求是简单的交互式镜头模拟。
因此,任何有关 2D 光线追踪算法或库的观点都是受欢迎的。我正在使用Python。
I am working on program that demonstrate how various lens works and for that I needed
a 2D ray tracing library or algorithm.
I searched for ray tracing and mostly found things that uses to create a scene in 3D, while my requirement is a simple interactive lens simulation.
So any point towards 2D ray tracing algorithm or library is welcome. I am using Python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我创建这个小组是因为我对这种事情感兴趣,
http://groups.google.com/group/python-ray-tracing-community/web/list-of-python-statistical-ray-tracers 。
在这里,您将找到一个(非详尽的)Python 光线追踪器列表,它应该为您指明正确的方向。我还有一个用 Python 编写的光线追踪器,可以满足您的需求,但尚未发布!
I started this group because I'm interested in this kind of thing,
http://groups.google.com/group/python-ray-tracing-community/web/list-of-python-statistical-ray-tracers .
Here you will find a (non-exhaustive) list of python ray tracers that should point you in the right direction. I also have a ray tracer written in Python that does what you need but it has not yet been released!
这个问题有两个部分:
为了找出光线击中的物体,我将离散透镜的形状。所以你只需要针对直线进行测试。
找到第一个命中的伪代码:
在命中时,将矢量版本 snellius-law 应用于射线方向,并将新的起点设置为事件点。然后从该点再次开始光线追踪。
您还需要注意光线不要立即再次击中同一个线段。通过将该一条线段列入黑名单或仅将位置设置为线段之外一点(位置+=ε*方向)来实现这一点,
重复直到不再有命中,即光线离开框。
This problem has two parts:
For finding out what the ray hits I'd discretize the form of the lens. So you just need to test against straight lines.
Pseudo-code to find the first hit:
On the hit apply the vector version snellius-law to the ray-direction and set the new starting point to the point of incident. Then start raytracing again from that point.
You also need to take care that the ray doesn't hit the same line-piece immediately again. Do that by either blacklisting that one line-piece or just setting the position as a bit beyond the line-piece (position+=epsilon*direction)
Repeat until there are no more hits i.e. the ray leaves the box.
不确定这是否能解决您的问题,但至少对于“找出光线击中的内容”,您始终可以通过将每条线 (x0,y0)-(x1,y0) 制作为四边形 (x0,y0,z=0)-(x1,y1,z=1),然后将所有光线 (ex,ey)+r*(dx,dy) 更改为“3D”光线 (ex,ey, z=0.5)+r*(dx,dy,0.f)。然后,您可以使用任何 3D 光线追踪库(如 embree 或 optix)来追踪这些光线并找到被击中的“四边形”。
Not sure that solves your problem, but at least for the "find out what the ray hits" you can always "embed" a 2D scene into a 3D scene by making each line (x0,y0)-(x1,y0) into a quad (x0,y0,z=0)-(x1,y1,z=1), then change all yours rays (ex,ey)+r*(dx,dy) into a "3D" ray (ex,ey,z=0.5)+r*(dx,dy,0.f). Then you can use any 3D ray tracing library like embree or optix to trace those rays and find the "quads" that were hit.