Question: this code is easier then appears use python Apply knowledge of Pythons collection data types and conditional statements. Suppose you have graduated from UC and

this code is easier then appears use python

Apply knowledge of Pythons collection data types and conditional statements.

Suppose you have graduated from UC and are an engineer for Really Expensive Optics, Inc. You have been given the task of modeling a system of optical media to determine how light entering a lens system will behave. You have decided to code a proof-of-concept model for a ray-tracing program using your extensive knowledge of Python (with its corresponding flow diagram of course). Since it is only a proofofconcept, for now you only have to deal with one ray of light and two optical media that are not air. In order to simplify your calculations, you have decided to use only the most basic concepts of Snells Law.

Looking back to your PHYS 2002 notes, you recall that Snells Law states that the behavior of a ray of light as it passes from one optical medium to another is determined from the medias indices of refraction (n1 and n2) and the angles with which the light enters or leaves each medium. The relationship is given by the following equation from Snells Law:

[X] (Equation 1)

Since you are working with a ray of light that starts in medium 1 and passes through two optical media, you decide to draw a new diagram, similar to the one in your notes but more representative of your current problem. You come up with something like this:

Relating this to Snells Law, you see that each angle exiting an optical interface (the point where one medium meets another) can be found from Equation 1, as long as you know the incoming angle and the two indices of refraction. Additionally, you notice immediately a situation in which an error (hint: Arithmetic error) could occur in finding the angle leaving the interface. This situation appears when light leaving a medium with higher refractive index into a medium with lower refractive index, which might be reflected back instead of refracting through the second medium when the incoming angle reaches a certain value (The largest incoming angle before this error occurs is called the critical angle), this situation is defined as total internal reflection.

For your application, you need to be able to handle one optical interface with two media. Additionally, you need to be able to determine the ending distance (shown as d3 in Figure 1) where the light ray will fall.

For inputs, you will prompt the user to enter (in this order):

Indices of refraction for the two media. Input them as lists or tuples (i.e one line input).

Incoming angle 1 in degrees (1 value).

Vertical distances through the media from the point where the light ray starts (d1, d2, in Figure 1). Again, these will be input as lists or tuples.

After entering the values, you need to check them for obvious errors. Next, calculate and output the final horizontal distance (d3 in Figure 1). If the ray will not pass between media (i.e., it gets reflected), your program should display an error and terminate. Your file should be named Homework_11_2_Task1_UCusername.py. Two example outputs and test cases are given below to help you.

example below:

Enter indices of refraction for bottom two media:

1.26 1.33

Enter angle of incidence (in degrees):

48

Enter d1 and d2 (units):

1 1

Ending distance is:

2.102 units

Enter indices of refraction for bottom two media:

2 1

Enter angle of incidence (in degrees):

40

Enter d1, d2 (units):

1.25 2.3

Error, no refraction in the second media

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!