<p>这很可能是以前问过的问题,但我不确定我看到的问题有完全相同的情况</p>
<p>我有一个追踪光线的程序。每条光线都是一个物体,每个镜头都是一个物体。如果,当用户尝试使用该方法通过透镜传播光线时,光线实际上没有通过透镜,我希望程序告诉用户这个事实</p>
<p>伪代码:</p>
<pre><code>class OpticalElement:
...
def propagate_ray(self):
if intersect:
calculate new direction etc
else:
print "Ray %s did not intersect optical element" % (ray)
</code></pre>
<p>所以</p>
<pre><code>>> A = Ray(args) # won't intersect lens1
>> B = Ray(different args)
>> lens1 = OpticalElement(args)
>> lens1.propagate_rays(A, B)
'Ray <Ray instance at 0x7688> did not intersect optical element'
</code></pre>
<p>当有50条射线被传播时,谁知道是哪条射线呢?我希望它输出什么:</p>
<pre><code>'Ray A did not intersect optical element'
</code></pre>