Ejemplo n.º 1
0
def refract_ray_sphere(ray, sphere):
    #TODO: docstring
    #decide if the ray is starting inside or outside the sphere, and set the
    #indices correctly:
    if sphere.is_inside(ray.point):
        ni, nt = sphere.n_sphere, sphere.n_outside
    else:
        ni, nt = sphere.n_outside, sphere.n_sphere
    #move the ray forward to where it hits the sphere
    dist = sphere.ray_intersect_dist(ray)
    ray.propagate(dist)
    #find the surface normal at the intersection and its angle
    s_norm = umath.norm_vec(ray.point - sphere.center) #outwards-facing surface normal
    trans_ray, refl_ray = refract_ray(ray, s_norm, ni, nt) #TODO: check the sign of the normal! should point towards the ray.
    return trans_ray, refl_ray
Ejemplo n.º 2
0
 def direction(self, value):
     self._direction = umath.norm_vec(umath.nparray(value))
 def __init__(self, point, normal):
     self.point = umath.nparray(point)
     self.normal = umath.norm_vec(umath.nparray(normal))