( Python) : . , , /:
1) - ( ), , , . .
:
intersection_points(ray) - , .intersection_objects(ray) - , .containing_object(ray) - , .objects() - .
. : Scene_Boundary. ( ), , .
2) . (, ).
:
contains(ray) - - , False, False,ray_is_on_surface(ray) - True - , False.intersection_points(ray) - () ,surface_normal(ray) - , ( )
.
:
, : (n1) (n2) ? :
1) :
sphere
ray
scene.add_object(sphere)
ipoints = scene.intersection_points(ray)
iobjects = scene.intersection_objects(ray)
, . ipoints iobjects - , . !
2) n1 , :
obj1 = scene.containing_object(ray)
n1 = obj1.refractive_index()
3) n2 iobject, . :
index = iobjects.index_of_object(obj1)
obj2 = iobjects[index+1]
n2 = obj2.refractive_index()
4) :
normal = obj1.surface_normal(ray)
. , , , , !
, . Python numpy ,
def reflect_vector(normal, vector):
d = numpy.dot(normal, vector)
return vector - 2 * d * normal
( ) n1 n2:
def fresnel_refraction(normal, vector, n1, n2):
n = n1/n2
dot = np.dot(norm(vector), norm(normal))
c = np.sqrt(1 - n**2 * (1 - dot**2))
sign = 1
if dot < 0.0:
sign = -1
refraction = n * vector + sign*(c - sign*n*dot) * normal
return norm(refraction)
, , - ( , "" ). 0 1, , .
def fresnel_reflection(angle, n1, n2):
assert 0.0 <= angle <= 0.5*np.pi, "The incident angle must be between 0 and 90 degrees to calculate Fresnel reflection."
if n2 < n1:
if angle > np.arcsin(n2/n1):
return 1.0
Rs1 = n1 * np.cos(angle) - n2 * np.sqrt(1 - (n1/n2 * np.sin(angle))**2)
Rs2 = n1 * np.cos(angle) + n2 * np.sqrt(1 - (n1/n2 * np.sin(angle))**2)
Rs = (Rs1/Rs2)**2
Rp1 = n1 * np.sqrt(1 - (n1/n2 * np.sin(angle))**2) - n2 * np.cos(angle)
Rp2 = n1 * np.sqrt(1 - (n1/n2 * np.sin(angle))**2) + n2 * np.cos(angle)
Rp = (Rp1/Rp2)**2
return 0.5 * (Rs + Rp)
Python, (!), : http://daniel.farrell.name/freebies/pvtrace. Python! Python, http://groups.google.com/group/python-ray-tracing-community/web/list-of-python-statistical-ray-tracers. , , .
, , http://github.com/danieljfarrell/pvtrace
