def test_normal_reflection(self):
     node = Node(name="node")
     ctx = Context(n1=1.0, n2=1.5, normal_node=node, normal=(0.0, 0.0, 1.0), kind=Kind.SURFACE, end_path=(10, 10, 10), container=None)
     ray = Ray(position=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0), wavelength=None)
     interaction = FresnelReflection(ctx)
     p = interaction.probability(ray)
     assert np.isclose(p, 0.04)
 def test_antinormal_reflection(self):
     """ FresnelReflection takes the smallest angle between the ray direction and 
     the normal. Thus the flipped normal will also work.
     """
     node = Node(name="node")
     ctx = Context(n1=1.0, n2=1.5, normal_node=node, normal=(0.0, 0.0, -1.0), kind=Kind.SURFACE, end_path=(10, 10, 10), container=None)
     ray = Ray(position=(0.0, 0.0, 0.0), direction=(0.0, 0.0, 1.0), wavelength=None)
     interaction = FresnelReflection(ctx)
     p = interaction.probability(ray)
     assert np.isclose(p, 0.04)
예제 #3
0
    def generate_interaction_sequence(self, ray, context):
        """ Decision tree for crossing a dielectric interface:

            - Test for reflection.
                - If reflected
                    - reflect and exit
                - If not reflected
                    - refract and exit.
        """
        # Test for reflection.
        mech = FresnelReflection(context)
        p = mech.probability(ray)
        gamma = np.random.uniform()
        if gamma < p:
            yield mech
        else:
            yield FresnelRefraction(context)